Repository navigation
JIT: Fold SequenceEqual self-comparisons with constant length - #135307
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The codegen fix needs a targeted disassembly regression test.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Moves the existing equal-value-number check so constant-length SequenceEqual self-comparisons fold to true.
Changes:
- Applies self-comparison folding before constant-length handling.
- Preserves argument side effects while eliminating redundant comparisons.
| File | Description |
|---|---|
src/coreclr/jit/assertionprop.cpp |
Hoists the equal-VN optimization. |
|
@EgorBo I agree with your concern, if I understood it correctly. With I think we should avoid this optimization when either argument is known to be if (vnStore->IsVNNull(arg1VN) || vnStore->IsVNNull(arg2VN))
{
return nullptr;
}I'll verify this when I have some time. |
|
Just a small personal note: this was my first contribution to the JIT, so seeing it merged means a lot to me. Thanks for the review! |
I'd just wrap 0/1 with explicit nullchecks for addresses - I'll file a PR later.
Haha, well, thanks for not trying to land a lot of changes at once like other first-time contributors try to do sometimes 🙂 |

The existing equal-VN optimization for
SequenceEqualis only reached when the length is not a constant. As a result, self-comparisons with a constant length are not folded totrue.Move the equal-VN check before the constant-length check so the existing optimization applies regardless of whether the length is constant.
Closes #134431