Skip to content

JIT: remove unsound NOT(relop) VN simplification#129097

Merged
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-129076-not-relop-vn
Jun 8, 2026
Merged

JIT: remove unsound NOT(relop) VN simplification#129097
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-129076-not-relop-vn

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

Note

This PR was authored by GitHub Copilot CLI on @AndyAyersMS's machine.

VNForFunc was rewriting NOT(relop(x,y)) to Reverse(relop)(x,y). GT_NOT is bitwise complement, not logical negation: for a 0/1 relop result, ~v produces -1 or -2, while Reverse(relop) produces 0 or 1, so downstream arithmetic uses of the complemented value (here ~v3 >= -1 in the repro) folded the wrong way.

Removes the case; keeps NOT(NOT(x)) ==> x which is correct.

SuperPMI asmdiffs across all 10 osx-arm64 Checked collections (2,302,269 contexts, 871K MinOpts + 1.4M FullOpts): 0 diffs. The peephole never fires on real-world code.

Fixes #129076.

VNForFunc was rewriting NOT(relop(x,y)) to Reverse(relop)(x,y). GT_NOT
is bitwise complement, not logical negation: for a 0/1 relop result,
`~v` produces -1 or -2, not the 1 or 0 that the reversed relop would,
so downstream arithmetic uses of the complemented value folded the
wrong way.

Fixes dotnet#129076.
Copilot AI review requested due to automatic review settings June 7, 2026 15:54
@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 Jun 7, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@AndyAyersMS
Copy link
Copy Markdown
Member Author

@dotnet/jit-contrib PTAL

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a value-numbering (VN) simplification in CoreCLR JIT where NOT(relop(x,y)) could be rewritten to the reversed relational operator, and adds a JIT regression test intended to cover the resulting miscompile scenario.

Changes:

  • Remove the VNF_NOT + VNFuncIsComparison rewrite in ValueNumStore::VNForFunc.
  • Add a new JitBlue regression test (Runtime_129076) exercising ~(relop) used in downstream arithmetic comparisons.
  • Add a minimal test .csproj to build the new regression.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/valuenum.cpp Removes the NOT(relop) -> Reverse(relop) VN fold while keeping NOT(NOT(x)) -> x.
src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.csproj New test project for the regression.
src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.cs New regression test reproducer validating correct behavior.

Comment thread src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.csproj Outdated
Comment thread src/tests/JIT/Regression/JitBlue/Runtime_129076/Runtime_129076.csproj Outdated
Drop the standalone .csproj and add the .cs to Regression_ro_2.csproj
following the pattern of recent JitBlue tests (Runtime_128631,
Runtime_128801). Standalone csprojs are only needed when the test
requires its own process via CLRTestEnvironmentVariable; ours doesn't.

Verified: bash Regression_ro_2.sh invokes Runtime_129076.TestEntryPoint
(passes on the fixed JIT, fails on the regressed JIT).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Is this a recent regression? Surprised Fuzzlyn hasn't found this.

@AndyAyersMS
Copy link
Copy Markdown
Member Author

LGTM. Is this a recent regression? Surprised Fuzzlyn hasn't found this.

Yes, it was from #127181 (so ~6 weeks old)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

JIT: regression in compare simplification rewriting ~x op k without inverting the comparison

3 participants