Repository navigation
Conversation
ParseArrayAddress accumulates the address offset with wrapping arithmetic, so a[x + C] with a 3-byte element can end up as x * 3 + 2, whose constant part is not a multiple of the element size. The assert fired, and without it the truncated division would produce a wrong index VN. Bail out (unknown array address) instead. Fixes dotnet#134192 Co-authored-by: Copilot <[email protected]> Copilot-Session: 88502efb-96e2-4483-b698-59f5003a2e2c
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
🟢 Approval recommended
The narrow guard follows the existing fallback contract, and the regression test targets the reported failure.
0 open findings
What changed in this PR
Prevents incorrect JIT array-index value numbering when a wrapped constant offset is not divisible by the element size, addressing #134192.
Changes:
- Replaces the divisibility assertion with a conservative unknown-address fallback.
- Adds a regression test using a three-byte array element and a large index constant.
Builds and tests were not run during this review.
| File | Description |
|---|---|
| src/tests/JIT/Regression_ro_2/Runtime_134192.cs | Adds the reported regression scenario. |
| src/coreclr/jit/gentree.cpp | Rejects non-divisible offsets before computing the constant index. |
🧠 Review effort: Balanced
|
PTAL @dotnet/jit-contrib, trivial change, no diffs |
| // This should be divisible by the element size... | ||
| assert((constIndexOffset % elemSize) == 0); | ||
| // The offset was accumulated with wrapping arithmetic, e.g. (x + C) * 3 becomes x * 3 + 3C where 3C may wrap | ||
| // to a value that isn't a multiple of the element size. We can't recover the constant index then, give up. |
There was a problem hiding this comment.
If the value is a multiple of the element size, we won't be able to recover the exact original index either. What makes it work in that case?
There was a problem hiding this comment.
@jkotas This is only used for VN phase. If the function fails to extract the components, we conservatively assign a fresh, unique VN to the array address, so we only lose optimization.
There was a problem hiding this comment.
"We can't recover the constant index then, give up." part of the comment looks confusing to me. If there is a wrap around, you cannot recover the original constant index, irrespective of what the element size is,
What happens if there is wraparound, the bogus value happens to be a multiple of element size, and we extract a bogus constant index here?
There was a problem hiding this comment.
Yeah, I do think we need to account for the case where there is wraparound that is a multiple of the elem size. Could we try and detect if overflow occurred in ParseArrayAddressWork?
ParseArrayAddress accumulates the address offset with wrapping arithmetic, so a[x + C] with a 3-byte element can end up as x * 3 + 2, whose constant part is not a multiple of the element size. The assert fired, and without it the truncated division would produce a wrong index VN. Bail out (unknown array address) instead.
Fixes #134192
No diffs