Skip to content

JIT: bail from optOptimizeBoolsCondBlock on GTF_UNSIGNED inputs#128928

Open
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:Fix128895
Open

JIT: bail from optOptimizeBoolsCondBlock on GTF_UNSIGNED inputs#128928
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:Fix128895

Conversation

@AndyAyersMS
Copy link
Copy Markdown
Member

optOptimizeBoolsCondBlock folds pairs of BBJ_COND blocks of the form "(x == 0) || (x relop 0)" into a single directional comparison.

Mirror the existing check at the (LT,LT)/(LT,GE) folds and bail out if either input is unsigned.

Possible fix for #128895.

optOptimizeBoolsCondBlock folds pairs of BBJ_COND blocks of the form
"(x == 0) || (x relop 0)" into a single directional comparison.

Mirror the existing check at the (LT,LT)/(LT,GE) folds and bail out
if either input is unsigned.

Possible a fix for dotnet#128895.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 01:38
@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 3, 2026
@AndyAyersMS
Copy link
Copy Markdown
Member Author

@EgorBo PTAL
fyi @dotnet/jit-contrib

This is a bug. Whether it is the same bug as #128895 is not yet known (but it seems likely).

@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.

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 tightens OptBoolsDsc::optOptimizeBoolsCondBlock to avoid folding specific two-block boolean patterns into a signed directional compare when either original condition node is flagged GTF_UNSIGNED, preventing SetOper from accidentally making an originally-irrelevant unsigned flag become semantically meaningful after the fold.

Changes:

  • Add early bail-outs in optOptimizeBoolsCondBlock for the “same local” fold cases when either input comparison node is marked unsigned.
  • Add a JitBlue regression test that enables Tiered Compilation + Tiered PGO and checks the runtime behavior of an OR-chain that previously could miscompile.
  • Add a dedicated test .csproj enabling process isolation and setting the required DOTNET_* environment variables for the repro scenario.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/optimizebools.cpp Adds unsigned-flag bail-outs before performing signed directional folding that uses SetOper (which preserves flags).
src/tests/JIT/Regression/JitBlue/Runtime_128895/Runtime_128895.cs New regression test that drives Tier0→Tier1+PGO and validates correct boolean results for the OR-chain scenario.
src/tests/JIT/Regression/JitBlue/Runtime_128895/Runtime_128895.csproj Enables process isolation and sets DOTNET_TieredCompilation/DOTNET_TieredPGO to exercise the intended JIT pipeline in test runs.

Copy link
Copy Markdown
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

I feel like the entire function can be rewritten to be some sort of a table with rules like the one in RBO

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.

3 participants