Repository navigation
[X86] combineShiftRightLogical - fold srl(vecreduce_umax(x),bw-1) as MOVMSK signbit reduction #210281
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
[X86] combineShiftRightLogical - fold srl(vecreduce_umax(x),bw-1) as MOVMSK signbit reduction #210281
Changes from 2 commits
271b338
a3c7966
9d94d0b
a7cd7ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50910,6 +50910,33 @@ static SDValue combineShiftRightLogical(SDNode *N, SelectionDAG &DAG, | |
| } | ||
| } | ||
|
|
||
| // VectorCombine may have folded: | ||
| // icmp_eq(vecreduce_or(splatsign(x)),0) --> icmp_sgt(vecreduce_umax(x),-1) | ||
| // which DAG folds to: srl(vecreduce_umax(x),bw-1). | ||
| // This attempts to reconstruct the signbit reduction. | ||
| if (sd_match(N1, m_SpecificInt(EltSizeInBits - 1))) { | ||
| SDValue X = N0; | ||
| ISD::CondCode CC = ISD::SETNE; | ||
| if (sd_match(N0, m_Not(m_Value(X)))) | ||
| CC = ISD::SETEQ; | ||
| if (X.getOpcode() == ISD::VECREDUCE_UMAX) { | ||
| SDValue V = X.getOperand(0); | ||
| EVT VecVT = V.getValueType(); | ||
| if (DAG.getTargetLoweringInfo().isTypeLegal(VecVT) && | ||
| (VecVT.is128BitVector() || VecVT.is256BitVector())) { | ||
| if (VecVT == MVT::v16i16) { | ||
| auto [Lo, Hi] = DAG.SplitVector(V, DL); | ||
| V = DAG.getNode(X86ISD::PACKSS, DL, MVT::v16i8, Lo, Hi); | ||
| } else if (VecVT == MVT::v8i16) { | ||
| V = DAG.getNode(X86ISD::PACKSS, DL, MVT::v16i8, V, V); | ||
| } | ||
| V = getPMOVMSKB(DL, V, DAG, Subtarget); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, getPMOVMSKB only handles vXi8 type, how vXi32/vXi64 get lowered by this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a badly named function - it was originally added to handle v32i8/v64i8 splitting, but has been used for more general MOVMSK lowering for some time. If you want I can rename it (and add some much needed asserts), but was trying to minimise churn for a release patch.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I agree it's good to do it in a follow up. |
||
| V = DAG.getSetCC(DL, MVT::i8, V, DAG.getConstant(0, DL, MVT::i32), CC); | ||
| return DAG.getZExtOrTrunc(V, DL, VT); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Only do this on the last DAG combine as it can interfere with other | ||
| // combines. | ||
| if (!DCI.isAfterLegalizeDAG()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why exclude 512-bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add test coverage to check how bad 512-bit cases look like