perf(codegen): a loop region whose body calls out takes no array it only reads element values from - #11860
Merged
Conversation
added 2 commits
October 3, 2026 23:54
…nly reads element values from
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (3)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the #10594
userplainand #10510date_getTimeregressions that #11790 introduced.Cause
#11790 (#10741) makes an array a loop-region candidate when it is read at a static index (
x & c) in any context.const d = ds[i & 63]; a += d.valueOf()therefore became a region loop overds. The region was versioned, and the body triplicated (425 to 1,882 IR lines), to save one guarded element load per iteration. The method call in the body sets the region's dirty flag, so every iteration re-checks the guard. Both rows went from 151/158 to 167/176 instructions per op.Fix
In a body that calls out (a call,
new, a native method call), an array becomes a candidate only when the region serves it there: the body stores into it, or a Number consumer takes one of its reads (the dense raw-f64 facts). A call-free body keeps every proven-index read as before. There the facts hold across iterations, and the matrix'svaryingcells (const o = objs[k & 7]; o.d = k; h += o.a) depend on it. Static-index value reads still ride along once some other access makes the array a candidate.Results (instructions per op)
Real workloads (n=5, median instructions:u; main = 5b06d69)
Outputs are identical to main's in every run.
Verification
an_array_only_read_for_element_values_is_not_a_region_array. Its controls show that a Number-consumed masked read, and a value read in a call-free body, still make the array a region array. Allregion_array_loop_testsandregion_loop_testspass.varyingcells are unchanged.