Repository navigation
JIT: fix loop cloning condition merging - #137776
Merged
AndyAyersMS merged 1 commit intoNov 18, 2026
Merged
Conversation
Loop cloning could drop a signed non-negativity guard when it matched an unsigned zero-trip guard, allowing out-of-bounds array accesses. Only combine ordered conditions with matching signedness and use SwapRelop when swapping operands. Fixes dotnet#137676 Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
@EgorBo ptal |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the loop-cloning condition-merging fix.
No open issues 🎉
What changed in this PR
This PR fixes condition merging in JIT loop cloning so required bounds guards are not discarded, preventing out-of-bounds array access in optimized loops.
Changes:
- Require matching signedness when merging ordered comparisons.
- Use
SwapRelopfor swapped operands, preserving strict versus inclusive comparisons. - Add a regression test that expects
IndexOutOfRangeExceptionfor a large unsigned loop bound.
| File | Description |
|---|---|
src/tests/JIT/Regression_ro_2/Runtime_137676.cs |
Adds regression coverage for an unsigned loop bound of 0x80000000u. |
src/coreclr/jit/loopcloning.cpp |
Corrects signedness checks and swapped-comparison equivalence during condition merging. |
Review effort: Balanced
EgorBo
approved these changes
Nov 18, 2026
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.
Loop cloning could drop a signed non-negativity guard when it matched an
unsigned zero-trip guard, allowing the fast loop to access past the end
of an array.
Only combine ordered conditions with matching signedness, and use
SwapRelopwhen swapping operands so strict and inclusive comparisonsare not treated as equivalent.
Validation
.\build.cmd clr+libs+host -c Checked: passed..\build.cmd clr.jit -c Checked: passed..\src\tests\build.cmd -GenerateLayoutOnly x64 Checked: passed..\src\tests\build.cmd -Test JIT/Regression_ro_2/Regression_ro_2.csproj x64 Checked: passed.Regression_ro_2.cmd: 506 passed, 7 skipped. The new regression crasheswithout the fix and passes with it.
clang-format --dry-run --Werror -style=file src\coreclr\jit\loopcloning.cpp:passed.
Resolves #137676
Note
This PR description was generated with GitHub Copilot.