-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[X86] Improve variable 8-bit shifts on AVX512BW #164136
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
+109
−104
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30968,6 +30968,76 @@ static SDValue LowerShift(SDValue Op, const X86Subtarget &Subtarget, | |
| return DAG.getNode(X86ISD::PACKUS, dl, VT, LoR, HiR); | ||
| } | ||
|
|
||
| if (VT == MVT::v64i8 && Subtarget.canExtendTo512BW()) { | ||
| // On AVX512BW, we can use variable 16-bit shifts to implement variable | ||
| // 8-bit shifts. For this, we split the input into two vectors, RLo and RHi. | ||
| // The i-th lane of RLo contains the (2*i)-th lane of R, and the i-th lane | ||
| // of RHi contains the (2*i+1)-th lane of R. After shifting, these vectors | ||
| // can efficiently be merged together using a masked move. | ||
| MVT ExtVT = MVT::v32i16; | ||
|
|
||
| // When used in a vectorshuffle, selects even-index lanes from the first | ||
| // vector and odd index lanes from the second vector. | ||
| SmallVector<int, 64> InterleaveIndices; | ||
| for (unsigned i = 0; i < 64; ++i) { | ||
| unsigned offset = (i % 2 == 0) ? 0 : 64; | ||
| InterleaveIndices.push_back(i + offset); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| SDValue zero = DAG.getConstant(0, dl, VT); | ||
| SDValue eight = DAG.getTargetConstant(8, dl, MVT::i8); | ||
| SDValue RLo, RHi; | ||
|
|
||
| // Isolate lower and upper lanes of Amt by shuffling zeros into AmtLo and | ||
| // right shifting AmtHi. | ||
| SDValue AmtLo = DAG.getBitcast( | ||
| ExtVT, DAG.getVectorShuffle(VT, dl, Amt, zero, InterleaveIndices)); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SDValue AmtHi = DAG.getNode(X86ISD::VSRLI, dl, ExtVT, | ||
| DAG.getBitcast(ExtVT, Amt), eight); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
RKSimon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unsigned int ShiftOp; | ||
| switch (Opc) { | ||
| case ISD::SHL: | ||
| // Because we shift left, no bits from the high half can influence the low | ||
| // half, so we don't need to mask RLo. We do however need to mask RHi, to | ||
| // prevent high bits of an even lane overflowing into low bits of an odd | ||
| // lane. | ||
| RLo = DAG.getBitcast(ExtVT, R); | ||
| RHi = DAG.getBitcast( | ||
| ExtVT, DAG.getVectorShuffle(VT, dl, zero, R, InterleaveIndices)); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ShiftOp = X86ISD::VSHLV; | ||
| break; | ||
| case ISD::SRL: | ||
| // Same idea as above, but this time we need to make sure no low bits of | ||
| // an odd lane can overflow into high bits of an even lane. | ||
| RLo = DAG.getBitcast( | ||
| ExtVT, DAG.getVectorShuffle(VT, dl, R, zero, InterleaveIndices)); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| RHi = DAG.getBitcast(ExtVT, R); | ||
| ShiftOp = X86ISD::VSRLV; | ||
| break; | ||
| case ISD::SRA: | ||
| // For arithmetic right shifts, we want to sign extend each even lane of R | ||
|
||
| // such that the upper half of the corresponding lane of RLo is 0 or -1 | ||
| // depending on the sign bit of the original lane. We do this using 2 | ||
| // immediate shifts. | ||
| RHi = DAG.getBitcast(ExtVT, R); | ||
| RLo = DAG.getNode(X86ISD::VSHLI, dl, ExtVT, RHi, eight); | ||
| RLo = DAG.getNode(X86ISD::VSRAI, dl, ExtVT, RLo, eight); | ||
Sp00ph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ShiftOp = X86ISD::VSRAV; | ||
| break; | ||
| default: | ||
| llvm_unreachable("Unexpected Shift Op"); | ||
| return SDValue(); | ||
| } | ||
|
|
||
| SDValue ShiftedLo = | ||
| DAG.getBitcast(VT, DAG.getNode(ShiftOp, dl, ExtVT, RLo, AmtLo)); | ||
| SDValue ShiftedHi = | ||
| DAG.getBitcast(VT, DAG.getNode(ShiftOp, dl, ExtVT, RHi, AmtHi)); | ||
|
|
||
| return DAG.getVectorShuffle(VT, dl, ShiftedLo, ShiftedHi, | ||
| InterleaveIndices); | ||
| } | ||
|
|
||
| if (VT == MVT::v16i8 || | ||
| (VT == MVT::v32i8 && Subtarget.hasInt256() && !Subtarget.hasXOP()) || | ||
| (VT == MVT::v64i8 && Subtarget.hasBWI())) { | ||
|
|
||
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.