-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: Generalize pattern-based IV analysis #119537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: Generalize pattern-based IV analysis #119537
Conversation
- Follow unique preds when locating the init statement for the iterator variable - Generalize zero-trip detection by similarly following unique preds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR generalizes pattern-based induction variable (IV) analysis in the JIT compiler to improve loop optimization capabilities. The changes focus on following unique predecessors when locating initialization statements and generalizing zero-trip detection.
Key changes:
- Remove init extraction from
optExtractInitTestIncr
and create a new focused methodoptExtractTestIncr
- Add new methods
FindConstInit
andHasZeroTripTest
that follow unique predecessors to locate initialization and zero-trip tests - Add
gtTreeHasLocalStore
utility to check for stores affecting specified locals
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/coreclr/jit/optimizer.cpp | Refactored to remove init extraction logic from optExtractInitTestIncr , renamed to optExtractTestIncr |
src/coreclr/jit/gentree.cpp | Added new gtTreeHasLocalStore method to detect stores affecting a local variable |
src/coreclr/jit/flowgraph.cpp | Added FindConstInit and HasZeroTripTest methods, removed old init matching logic |
src/coreclr/jit/compiler.h | Updated method signatures and added new method declarations |
cc @dotnet/jit-contrib PTAL @AndyAyersMS Diffs. This mostly results in more loops we can unroll. Comparing on benchmarks.run_pgo, we go from 1443 cloned, 260 unrolled to 1445 cloned, 342 unrolled with this change. |
This at least allows us to analyze the loop iteration here: #119277 (comment)
However, we still do not unroll because we bail out on this condition in unrolling:
runtime/src/coreclr/jit/optimizer.cpp
Lines 1347 to 1358 in dcf8680
I think we truly do need to improve heuristics for inversion to fix the case.