Skip to content

Fix side effect handling for certain TernaryLogic cases #114848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025

Conversation

BruceForstall
Copy link
Member

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
@dotnet-issue-labeler dotnet-issue-labeler bot 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
Member 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
Member Author

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

@@ -4529,8 +4588,7 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic,
(control == static_cast<uint8_t>(~0xAA & 0xF0)) || // ~C & A
(control == static_cast<uint8_t>(~0xAA & 0xCC))) // ~C & B
{
// 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
Member 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
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: Likely incorrect side effect ordering with Avx512F.VL.TernaryLogic
2 participants