Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jul 17, 2025

Fixes #116159

@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 17, 2025
@EgorBo EgorBo marked this pull request as ready for review July 17, 2025 11:29
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 11:29
Copy link
Contributor

@Copilot 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 fixes a bug in the JIT compiler's redundant branch optimization where the optimizer incorrectly handled always-true relational operations in optRelopTryInferWithOneEqualOperand. The fix prevents the optimizer from making incorrect inferences when both branches of a dominating relop result in always-true conditions.

  • Adds a check to bail out when both branches result in AlwaysTrue status
  • Includes a regression test case that reproduces the original issue
  • Improves debug output with additional JITDUMP messages

Reviewed Changes

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

File Description
src/coreclr/jit/redundantbranchopts.cpp Adds logic to handle always-true relops in both branches and improves debug messaging
src/tests/JIT/Regression/JitBlue/Runtime_116159/Runtime_116159.cs Regression test that reproduces the bug with specific array and relational operations
src/tests/JIT/Regression/JitBlue/Runtime_116159/Runtime_116159.csproj Test project configuration with optimization enabled

@EgorBo
Copy link
Member Author

EgorBo commented Jul 17, 2025

PTAL @AndyAyersMS @dotnet/jit-contrib

No diffs. Apparently, the logic didn't expect both canInferFromTrue and canInferFromFalse to be true. In this case the dominated relop was myLong >= long.MinValue which always true no matter what dominating relop is.

@EgorBo EgorBo requested a review from AndyAyersMS July 17, 2025 11:32
@EgorBo
Copy link
Member Author

EgorBo commented Jul 17, 2025

/ba-g "NetCore-Public 40 timeout"

@EgorBo EgorBo merged commit bd15721 into dotnet:main Jul 17, 2025
114 of 116 checks passed
@EgorBo EgorBo deleted the fix-redundant-branch-bug branch July 17, 2025 22:32
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 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.

JIT: Invalid handling of comparison with long.MinValue

2 participants