Skip to content

Conversation

BruceForstall
Copy link
Contributor

There were a few cases of TernaryLogic with NOT/AND and NOT/OR that swapped operands without considering side effects. Add some new logic to hoist those side effects if necessary.

Fixes #114324

There were a few cases of TernaryLogic with NOT/AND and NOT/OR that
swapped operands without considering side effects. Add some new logic to
hoist those side effects if necessary.

Fixes dotnet#114324
@Copilot Copilot AI review requested due to automatic review settings April 20, 2025 20:50
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 20, 2025
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 handling of TernaryLogic cases where side effects were not properly preserved when swapping operands in NOT/AND and NOT/OR operations.

  • Added a regression test (Runtime_114324.cs) to capture the issue.
  • Updated hwintrinsicxarch.cpp to ensure that side effects are correctly hoisted during operand normalization.

Reviewed Changes

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

File Description
src/tests/JIT/Regression/JitBlue/Runtime_114324/Runtime_114324.cs Added regression test for TernaryLogic side effect handling
src/coreclr/jit/hwintrinsicxarch.cpp Updated operand swapping logic to correctly hoist side effects
Files not reviewed (1)
  • src/tests/JIT/Regression/JitBlue/Runtime_114324/Runtime_114324.csproj: Language not supported

@BruceForstall
Copy link
Contributor Author

/azp run runtime-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

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

@BruceForstall
Copy link
Contributor Author

@tannergooding @dotnet/intel PTAL
cc @dotnet/jit-contrib

{
// We're normalizing to ~B & C, so we need another swap
std::swap(*val2, *val3);
// We already normalized to ~B & C above.
Copy link
Member

Choose a reason for hiding this comment

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

nit: This first if could be merged with the assert below. We may not even need the assert at all since it's the only possible 6 permutations of NOT AND and NOT OR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept the logic here stylized to be the same as the hoisted logic, for better or worse...

@BruceForstall BruceForstall merged commit 472a33b into dotnet:main Apr 23, 2025
167 checks passed
@BruceForstall BruceForstall deleted the Fix114324 branch April 23, 2025 16:32
@github-actions github-actions bot locked and limited conversation to collaborators May 24, 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: Likely incorrect side effect ordering with Avx512F.VL.TernaryLogic
2 participants