return DAG.getSetCC(dl, VT, Op0, Op1, SetCCOpcode);
}
-/// Try to turn a VSETULT into a VSETULE by modifying its second
-/// operand \p Op1. If non-trivial (for example because it's not constant)
-/// return an empty value.
-static SDValue ChangeVSETULTtoVSETULE(const SDLoc &dl, SDValue Op1,
- SelectionDAG &DAG) {
- BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(Op1.getNode());
+/// Given a simple buildvector constant, return a new vector constant with each
+/// element decremented. If decrementing would result in underflow or this
+/// is not a simple vector constant, return an empty value.
+static SDValue decrementVectorConstant(SDValue V, SelectionDAG &DAG) {
+ auto *BV = dyn_cast<BuildVectorSDNode>(V.getNode());
if (!BV)
return SDValue();
- MVT VT = Op1.getSimpleValueType();
- MVT EVT = VT.getVectorElementType();
- unsigned n = VT.getVectorNumElements();
- SmallVector<SDValue, 8> ULTOp1;
-
- for (unsigned i = 0; i < n; ++i) {
- ConstantSDNode *Elt = dyn_cast<ConstantSDNode>(BV->getOperand(i));
- if (!Elt || Elt->isOpaque() || Elt->getSimpleValueType(0) != EVT)
+ MVT VT = V.getSimpleValueType();
+ MVT EltVT = VT.getVectorElementType();
+ unsigned NumElts = VT.getVectorNumElements();
+ SmallVector<SDValue, 8> NewVecC;
+ SDLoc DL(V);
+ for (unsigned i = 0; i < NumElts; ++i) {
+ auto *Elt = dyn_cast<ConstantSDNode>(BV->getOperand(i));
+ if (!Elt || Elt->isOpaque() || Elt->getSimpleValueType(0) != EltVT)
return SDValue();
// Avoid underflow.
- APInt Val = Elt->getAPIntValue();
- if (Val == 0)
+ if (Elt->getAPIntValue().isNullValue())
return SDValue();
- ULTOp1.push_back(DAG.getConstant(Val - 1, dl, EVT));
+ NewVecC.push_back(DAG.getConstant(Elt->getAPIntValue() - 1, DL, EltVT));
}
- return DAG.getBuildVector(VT, dl, ULTOp1);
+ return DAG.getBuildVector(VT, DL, NewVecC);
}
/// As another special case, use PSUBUS[BW] when it's profitable. E.g. for
// Only do this pre-AVX since vpcmp* is no longer destructive.
if (Subtarget.hasAVX())
return SDValue();
- SDValue ULEOp1 = ChangeVSETULTtoVSETULE(dl, Op1, DAG);
+ SDValue ULEOp1 = decrementVectorConstant(Op1, DAG);
if (!ULEOp1)
return SDValue();
Op1 = ULEOp1;