Skip to content

Commit 365cb80

Browse files
committed
[X86] Fold (add X, (srl Y, 7)) -> (sub X, (icmp_sgt 0, Y)) on vXi8 vectors
Undo the vectorcombine canonicalisation as SSE has awful vXi8 shift support, but can easily splat the MSB using the PCMPGTB(0,x) trick. Alternative to llvm#143106 which could cause infinite loops between srl/sra conversions Fixes llvm#130549
1 parent c738308 commit 365cb80

File tree

4 files changed

+557
-582
lines changed

4 files changed

+557
-582
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58117,21 +58117,31 @@ static SDValue combineAdd(SDNode *N, SelectionDAG &DAG,
5811758117
}
5811858118
}
5811958119

58120-
// If vectors of i1 are legal, turn (add (zext (vXi1 X)), Y) into
58121-
// (sub Y, (sext (vXi1 X))).
58122-
// FIXME: We have the (sub Y, (zext (vXi1 X))) -> (add (sext (vXi1 X)), Y) in
58123-
// generic DAG combine without a legal type check, but adding this there
58124-
// caused regressions.
5812558120
if (VT.isVector()) {
5812658121
SDValue X, Y;
5812758122
EVT BoolVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1,
5812858123
VT.getVectorElementCount());
58124+
58125+
// If vectors of i1 are legal, turn (add (zext (vXi1 X)), Y) into
58126+
// (sub Y, (sext (vXi1 X))).
58127+
// FIXME: We have the (sub Y, (zext (vXi1 X))) -> (add (sext (vXi1 X)), Y)
58128+
// in generic DAG combine without a legal type check, but adding this there
58129+
// caused regressions.
5812958130
if (DAG.getTargetLoweringInfo().isTypeLegal(BoolVT) &&
5813058131
sd_match(N, m_Add(m_ZExt(m_AllOf(m_SpecificVT(BoolVT), m_Value(X))),
5813158132
m_Value(Y)))) {
5813258133
SDValue SExt = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, X);
5813358134
return DAG.getNode(ISD::SUB, DL, VT, Y, SExt);
5813458135
}
58136+
58137+
// Fold (add X, (srl Y, 7)) -> (sub X, (icmp_sgt 0, Y)) to undo instcombine
58138+
// canonicalisation as we don't have good vXi8 shifts.
58139+
if (VT.getScalarType() == MVT::i8 &&
58140+
sd_match(N, m_Add(m_Value(X), m_Srl(m_Value(Y), m_SpecificInt(7))))) {
58141+
SDValue Cmp =
58142+
DAG.getSetCC(DL, BoolVT, DAG.getConstant(0, DL, VT), Y, ISD::SETGT);
58143+
return DAG.getNode(ISD::SUB, DL, VT, X, DAG.getSExtOrTrunc(Cmp, DL, VT));
58144+
}
5813558145
}
5813658146

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

0 commit comments

Comments
 (0)