Skip to content

Conversation

@tannergooding
Copy link
Member

A reddit post (https://www.reddit.com/r/csharp/comments/1equjfd/low_level_things_that_make_me_sad_volume_1/) was made that indicated Bmi2.MultiplyNoFlags may not be commutative, so I took a look.

The issue the reddit post raises was not due to a missing flag to indicate the intrinsic could be commutative. Rather, its due to LSRA not understanding commutativity itself and therefore there being no way for us to say that "either op1 or op2 must be RDX, but which specifically it is doesn't matter". We have a few similar cases where LSRA cannot be accurately told about various preferencing details, such as it being possible for either operand to be contained or reg-optional (just not both simultaneously). So the actual issue comes down to https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/lsraxarch.cpp#L2346-L2347 where we say op1 must be SRBM_EDX, which we do because op2 is the "containable" operand (as that best fits in with the existing general support for op2 being the operand we want to contain).

However, as part of looking at this I audited the flags and found a couple places that were invalid and this PR fixes them. It also normalizes the NI_BMI2_MultiplyNoFlags containment support to actually use the main commutative path to ensure other JIT lightup does work as expected for it.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 13, 2024
@dotnet-policy-service
Copy link
Contributor

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

@tannergooding tannergooding merged commit 6086fe1 into dotnet:main Aug 14, 2024
@tannergooding tannergooding deleted the commutative-hwintrin branch August 14, 2024 09:28
@github-actions github-actions bot locked and limited conversation to collaborators Sep 14, 2024
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.

2 participants