Add peephole optimization to reduce MaskToVec and VecToMask conversions#130895
Open
abhishekdahad-1 wants to merge 1 commit into
Open
Add peephole optimization to reduce MaskToVec and VecToMask conversions#130895abhishekdahad-1 wants to merge 1 commit into
abhishekdahad-1 wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Author
@dotnet-policy-service agree company="AMD" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On x64, specifically when supporting AVX512 there is an issue in the code gen which leads to extraneous MaskToVec and VecToMask conversions. This can be observed specifically on the System.Numerics.Tensors.IndexOfMax<Int32> benchmark.
The generated assembly will look like this:

This can be fixed by examining every VecToMask conversion and seeing if it fits this form:
MASK_2 = VecToMask(NOT(LCL_VAR))
and LCL_VAR is defined earlier in the program as the following:
LCL_VAR = MaskToVec(MASK_1)
Then we can reduce this expression to become:
MASK_2 = NOT(MASK_1)
The fixed assembly looks like this:

This fix causes a ~47 reduction for 128 BufferLength and ~55% reduction in runtime for 3079 BufferLength. The runtime on System.Numerics.Tensors.IndexOfMax<Int32> is compared below.
Before changes:

After changes:
