Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jul 14, 2025

VN-based constant propagation used to incorrectly handle side-effects - it used to pass "ignoreTrue = true" to gtWrapWithSideEffects. This could led to replacing IND(node) with a constant while ignoring the GTF_EXCEPT on the IND node itself (it's precisely what I've hit in #117583). Looks like most regressions from this change were caused by GT_ARR_LENGTH node so I made a small optimization in gtExtractSideEffList to fold unused GT_ARR_LENGTH into GT_NULLCHECK to mitigate some regressions.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 14, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo EgorBo marked this pull request as ready for review July 14, 2025 08:51
@EgorBo
Copy link
Member Author

EgorBo commented Jul 14, 2025

PTAL @dotnet/jit-contrib @jakobbotsch correctness change, I've hit it with IND(obj) that was recognized as a method-table access and replaced with a constant type handle while obj was actually null, hence, no NRE were thrown.

Diffs, some improvements from the GT_ARR_LENGTH -> GT_NULLCHECK folding

@EgorBo EgorBo requested a review from jakobbotsch July 14, 2025 08:56
@filipnavara
Copy link
Member

Are the extra null checks in win-x86 diffs expected?

@EgorBo
Copy link
Member Author

EgorBo commented Jul 15, 2025

Are the extra null checks in win-x86 diffs expected?

I've realized that yeah, there are too many nullchecks in the diffs. The problem that in VN phase we have a bunch of optimizations that look through static readonly fields, RVA, etc - in some of those cases we actually know that the indirect is never faulty, but since we don't mutate the IR in the VN phase, we don't have a way to tell that to the assertprop phase. I'll put on hold this change

Even just

ROS<char> x = "hello";
var val = x[1];

now produces a nullcheck.

@EgorBo EgorBo closed this Jul 15, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants