Skip to content

Add flags checks to BMI1 intrinsic lowering - #66736

Merged
jakobbotsch merged 3 commits into
dotnet:mainfrom
Wraith2:fix-bmi1-decomposition
Mar 20, 2022
Merged

jakobbotsch merged 3 commits into
dotnet:mainfrom
Wraith2:fix-bmi1-decomposition

Conversation

@Wraith2

@Wraith2 Wraith2 commented Mar 16, 2022

Copy link
Copy Markdown
Contributor

Fixes #66709

On x86 longs are decomposed into two integer nodes. This bug was caused by one of those integer nodes being recognised as part of the blsi pattern, x & -x and transformed without the second node being included. On x86 the 64 bit version of the intrinsic is not available so the lowering of a 64 bit operation to the intrinsic is not possible.

This PR adds in flags checks on all nodes being removed to see if they have side effect and if they have the lowering is not attempted.

I have added the same checks to blsr and andn even though I have confirmed that they do not suffer from the same bug. This seemed prudent to me in case future jit changes expose a situation where it does become possible for those lowering to be affected.

/cc @dotnet/jit-contrib

@ghost ghost added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member labels Mar 16, 2022
@ghost

ghost commented Mar 16, 2022

Copy link
Copy Markdown

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

Issue Details

Fixes #66709

On x86 longs are decomposed into two integer nodes. This bug was caused by one of those integer nodes being recognised as part of the blsi pattern, x & -x and transformed without the second node being included. On x86 the 64 bit version of the intrinsic is not available so the lowering of a 64 bit operation to the intrinsic is not possible.

This PR adds in flags checks on all nodes being removed to see if they have side effect and if they have the lowering is not attempted.

I have added the same checks to blsr and andn even though I have confirmed that they do not suffer from the same bug. This seemed prudent to me in case future jit changes expose a situation where it does become possible for those lowering to be affected.

/cc @dotnet/jit-contrib

Author: Wraith2
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch

Copy link
Copy Markdown
Member

Can you add the regression test?

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also add the test case that uncovered this?

Feel free to add it to your existing tests, if that works out.

@Wraith2

Wraith2 commented Mar 16, 2022

Copy link
Copy Markdown
Contributor Author

I've updated the bmi1 tests to have 64 bit overloads and verified that they fail on current main as expected.

Comment thread src/coreclr/jit/lowerxarch.cpp Outdated
Comment thread src/coreclr/jit/lowerxarch.cpp Outdated
Comment thread src/coreclr/jit/lowerxarch.cpp Outdated
Comment thread src/coreclr/jit/lowerxarch.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Failure is #66571.

@jakobbotsch
jakobbotsch merged commit fa1f283 into dotnet:main Mar 20, 2022
@Wraith2
Wraith2 deleted the fix-bmi1-decomposition branch March 20, 2022 11:23
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
* add flags checks to BMI1 intrinsic lowering to prevent decomposed longs in x84 from being altered

* update bmji1intrinsics tests
@ghost ghost locked as resolved and limited conversation to collaborators Apr 19, 2022
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Incorrect optimization of x & -x on x86

5 participants