Uh oh!
There was an error while loading. Please reload this page.
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.
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
optExtractInitTestIncrand create a new focused methodoptExtractTestIncr - Add new methods
FindConstInitandHasZeroTripTestthat follow unique predecessors to locate initialization and zero-trip tests - Add
gtTreeHasLocalStoreutility 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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jakobbotsch
commented
Sep 11, 2025
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.