Skip to content

Commit 4e676a1

Browse files
authored
[X86] Fold (add X, (srl Y, 7)) -> (sub X, (ashr Y, 7)) on vXi8 vectors (#143106)
Undo the vectorcombine canonicalisation as SSE has awful vXi8 shift support, but can easily splat the MSB using the PCMPGTB(0,x) trick. Fixes #130549
1 parent 1540ed5 commit 4e676a1

File tree

4 files changed

+421
-448
lines changed

4 files changed

+421
-448
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58113,13 +58113,14 @@ static SDValue combineAdd(SDNode *N, SelectionDAG &DAG,
5811358113
}
5811458114
}
5811558115

58116-
// If vectors of i1 are legal, turn (add (zext (vXi1 X)), Y) into
58117-
// (sub Y, (sext (vXi1 X))).
58118-
// FIXME: We have the (sub Y, (zext (vXi1 X))) -> (add (sext (vXi1 X)), Y) in
58119-
// generic DAG combine without a legal type check, but adding this there
58120-
// caused regressions.
5812158116
if (VT.isVector()) {
5812258117
SDValue X, Y;
58118+
58119+
// If vectors of i1 are legal, turn (add (zext (vXi1 X)), Y) into
58120+
// (sub Y, (sext (vXi1 X))).
58121+
// FIXME: We have the (sub Y, (zext (vXi1 X))) -> (add (sext (vXi1 X)), Y)
58122+
// in generic DAG combine without a legal type check, but adding this there
58123+
// caused regressions.
5812358124
EVT BoolVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1,
5812458125
VT.getVectorElementCount());
5812558126
if (DAG.getTargetLoweringInfo().isTypeLegal(BoolVT) &&
@@ -58128,6 +58129,15 @@ static SDValue combineAdd(SDNode *N, SelectionDAG &DAG,
5812858129
SDValue SExt = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, X);
5812958130
return DAG.getNode(ISD::SUB, DL, VT, Y, SExt);
5813058131
}
58132+
58133+
// Fold (add X, (srl Y, 7)) -> (sub X, (ashr Y, 7)) to undo instcombine
58134+
// canonicalisation as we don't have good vXi8 shifts.
58135+
if (VT.getScalarType() == MVT::i8 &&
58136+
sd_match(N, m_Add(m_Value(X), m_Srl(m_Value(Y), m_SpecificInt(7))))) {
58137+
SDValue AShr = DAG.getNode(ISD::SRA, DL, VT, Y,
58138+
DAG.getShiftAmountConstant(7, VT, DL));
58139+
return DAG.getNode(ISD::SUB, DL, VT, X, AShr);
58140+
}
5813158141
}
5813258142

5813358143
// Peephole for 512-bit VPDPBSSD on non-VLX targets.

0 commit comments

Comments
 (0)