[SelectionDAG] Add isZero/isAllOnes methods to ConstantSDNode.

Soft deprecrate isNullValue/isAllOnesValue and update in tree
callers. This matches the changes to the APInt interface from
D109483.

Reviewed By: lattner

Differential Revision: https://reviews.llvm.org/D109535
This commit is contained in:
Craig Topper 2021-09-09 13:10:55 -07:00
parent f53fafbacb
commit 9af8f1b18e
27 changed files with 179 additions and 172 deletions

View File

@ -1577,8 +1577,12 @@ public:
Align getAlignValue() const { return Value->getAlignValue(); } Align getAlignValue() const { return Value->getAlignValue(); }
bool isOne() const { return Value->isOne(); } bool isOne() const { return Value->isOne(); }
bool isNullValue() const { return Value->isZero(); } bool isZero() const { return Value->isZero(); }
bool isAllOnesValue() const { return Value->isMinusOne(); } // NOTE: This is soft-deprecated. Please use `isZero()` instead.
bool isNullValue() const { return isZero(); }
bool isAllOnes() const { return Value->isMinusOne(); }
// NOTE: This is soft-deprecated. Please use `isAllOnes()` instead.
bool isAllOnesValue() const { return isAllOnes(); }
bool isMaxSignedValue() const { return Value->isMaxValue(true); } bool isMaxSignedValue() const { return Value->isMaxValue(true); }
bool isMinSignedValue() const { return Value->isMinValue(true); } bool isMinSignedValue() const { return Value->isMinValue(true); }

View File

@ -2781,7 +2781,7 @@ static SDValue extractBooleanFlip(SDValue V, SelectionDAG &DAG,
IsFlip = Const->isOne(); IsFlip = Const->isOne();
break; break;
case TargetLowering::ZeroOrNegativeOneBooleanContent: case TargetLowering::ZeroOrNegativeOneBooleanContent:
IsFlip = Const->isAllOnesValue(); IsFlip = Const->isAllOnes();
break; break;
case TargetLowering::UndefinedBooleanContent: case TargetLowering::UndefinedBooleanContent:
IsFlip = (Const->getAPIntValue() & 0x01) == 1; IsFlip = (Const->getAPIntValue() & 0x01) == 1;
@ -3808,18 +3808,18 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
return DAG.getNode(ISD::MUL, SDLoc(N), VT, N1, N0); return DAG.getNode(ISD::MUL, SDLoc(N), VT, N1, N0);
// fold (mul x, 0) -> 0 // fold (mul x, 0) -> 0
if (N1IsConst && ConstValue1.isNullValue()) if (N1IsConst && ConstValue1.isZero())
return N1; return N1;
// fold (mul x, 1) -> x // fold (mul x, 1) -> x
if (N1IsConst && ConstValue1.isOneValue()) if (N1IsConst && ConstValue1.isOne())
return N0; return N0;
if (SDValue NewSel = foldBinOpIntoSelect(N)) if (SDValue NewSel = foldBinOpIntoSelect(N))
return NewSel; return NewSel;
// fold (mul x, -1) -> 0-x // fold (mul x, -1) -> 0-x
if (N1IsConst && ConstValue1.isAllOnesValue()) { if (N1IsConst && ConstValue1.isAllOnes()) {
SDLoc DL(N); SDLoc DL(N);
return DAG.getNode(ISD::SUB, DL, VT, return DAG.getNode(ISD::SUB, DL, VT,
DAG.getConstant(0, DL, VT), N0); DAG.getConstant(0, DL, VT), N0);
@ -3966,7 +3966,7 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
SmallBitVector ClearMask; SmallBitVector ClearMask;
ClearMask.reserve(NumElts); ClearMask.reserve(NumElts);
auto IsClearMask = [&ClearMask](ConstantSDNode *V) { auto IsClearMask = [&ClearMask](ConstantSDNode *V) {
if (!V || V->isNullValue()) { if (!V || V->isZero()) {
ClearMask.push_back(true); ClearMask.push_back(true);
return true; return true;
} }
@ -4111,7 +4111,7 @@ static SDValue simplifyDivRem(SDNode *N, SelectionDAG &DAG) {
// 0 / X -> 0 // 0 / X -> 0
// 0 % X -> 0 // 0 % X -> 0
ConstantSDNode *N0C = isConstOrConstSplat(N0); ConstantSDNode *N0C = isConstOrConstSplat(N0);
if (N0C && N0C->isNullValue()) if (N0C && N0C->isZero())
return N0; return N0;
// X / X -> 1 // X / X -> 1
@ -4150,7 +4150,7 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
return C; return C;
// fold (sdiv X, -1) -> 0-X // fold (sdiv X, -1) -> 0-X
if (N1C && N1C->isAllOnesValue()) if (N1C && N1C->isAllOnes())
return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), N0); return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), N0);
// fold (sdiv X, MIN_SIGNED) -> select(X == MIN_SIGNED, 1, 0) // fold (sdiv X, MIN_SIGNED) -> select(X == MIN_SIGNED, 1, 0)
@ -4204,7 +4204,7 @@ SDValue DAGCombiner::visitSDIVLike(SDValue N0, SDValue N1, SDNode *N) {
// Helper for determining whether a value is a power-2 constant scalar or a // Helper for determining whether a value is a power-2 constant scalar or a
// vector of such elements. // vector of such elements.
auto IsPowerOfTwo = [](ConstantSDNode *C) { auto IsPowerOfTwo = [](ConstantSDNode *C) {
if (C->isNullValue() || C->isOpaque()) if (C->isZero() || C->isOpaque())
return false; return false;
if (C->getAPIntValue().isPowerOf2()) if (C->getAPIntValue().isPowerOf2())
return true; return true;
@ -4295,7 +4295,7 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) {
return C; return C;
// fold (udiv X, -1) -> select(X == -1, 1, 0) // fold (udiv X, -1) -> select(X == -1, 1, 0)
if (N1C && N1C->getAPIntValue().isAllOnesValue()) if (N1C && N1C->isAllOnes())
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ), return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
DAG.getConstant(1, DL, VT), DAG.getConstant(1, DL, VT),
DAG.getConstant(0, DL, VT)); DAG.getConstant(0, DL, VT));
@ -4391,7 +4391,7 @@ SDValue DAGCombiner::visitREM(SDNode *N) {
return C; return C;
// fold (urem X, -1) -> select(X == -1, 0, x) // fold (urem X, -1) -> select(X == -1, 0, x)
if (!isSigned && N1C && N1C->getAPIntValue().isAllOnesValue()) if (!isSigned && N1C && N1C->isAllOnes())
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ), return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
DAG.getConstant(0, DL, VT), N0); DAG.getConstant(0, DL, VT), N0);
@ -5815,7 +5815,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
case ISD::NON_EXTLOAD: B = true; break; case ISD::NON_EXTLOAD: B = true; break;
} }
if (B && Constant.isAllOnesValue()) { if (B && Constant.isAllOnes()) {
// If the load type was an EXTLOAD, convert to ZEXTLOAD in order to // If the load type was an EXTLOAD, convert to ZEXTLOAD in order to
// preserve semantics once we get rid of the AND. // preserve semantics once we get rid of the AND.
SDValue NewLoad(Load, 0); SDValue NewLoad(Load, 0);
@ -9371,27 +9371,27 @@ SDValue DAGCombiner::foldSelectOfConstants(SDNode *N) {
// is also a target-independent combine here in DAGCombiner in the other // is also a target-independent combine here in DAGCombiner in the other
// direction for (select Cond, -1, 0) when the condition is not i1. // direction for (select Cond, -1, 0) when the condition is not i1.
if (CondVT == MVT::i1 && !LegalOperations) { if (CondVT == MVT::i1 && !LegalOperations) {
if (C1->isNullValue() && C2->isOne()) { if (C1->isZero() && C2->isOne()) {
// select Cond, 0, 1 --> zext (!Cond) // select Cond, 0, 1 --> zext (!Cond)
SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1); SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1);
if (VT != MVT::i1) if (VT != MVT::i1)
NotCond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, NotCond); NotCond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, NotCond);
return NotCond; return NotCond;
} }
if (C1->isNullValue() && C2->isAllOnesValue()) { if (C1->isZero() && C2->isAllOnes()) {
// select Cond, 0, -1 --> sext (!Cond) // select Cond, 0, -1 --> sext (!Cond)
SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1); SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1);
if (VT != MVT::i1) if (VT != MVT::i1)
NotCond = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, NotCond); NotCond = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, NotCond);
return NotCond; return NotCond;
} }
if (C1->isOne() && C2->isNullValue()) { if (C1->isOne() && C2->isZero()) {
// select Cond, 1, 0 --> zext (Cond) // select Cond, 1, 0 --> zext (Cond)
if (VT != MVT::i1) if (VT != MVT::i1)
Cond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Cond); Cond = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Cond);
return Cond; return Cond;
} }
if (C1->isAllOnesValue() && C2->isNullValue()) { if (C1->isAllOnes() && C2->isZero()) {
// select Cond, -1, 0 --> sext (Cond) // select Cond, -1, 0 --> sext (Cond)
if (VT != MVT::i1) if (VT != MVT::i1)
Cond = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, Cond); Cond = DAG.getNode(ISD::SIGN_EXTEND, DL, VT, Cond);
@ -9447,7 +9447,7 @@ SDValue DAGCombiner::foldSelectOfConstants(SDNode *N) {
TargetLowering::ZeroOrOneBooleanContent && TargetLowering::ZeroOrOneBooleanContent &&
TLI.getBooleanContents(/*isVec*/false, /*isFloat*/false) == TLI.getBooleanContents(/*isVec*/false, /*isFloat*/false) ==
TargetLowering::ZeroOrOneBooleanContent && TargetLowering::ZeroOrOneBooleanContent &&
C1->isNullValue() && C2->isOne()) { C1->isZero() && C2->isOne()) {
SDValue NotCond = SDValue NotCond =
DAG.getNode(ISD::XOR, DL, CondVT, Cond, DAG.getConstant(1, DL, CondVT)); DAG.getNode(ISD::XOR, DL, CondVT, Cond, DAG.getConstant(1, DL, CondVT));
if (VT.bitsEq(CondVT)) if (VT.bitsEq(CondVT))
@ -9716,8 +9716,8 @@ static SDValue ConvertSelectToConcatVector(SDNode *N, SelectionDAG &DAG) {
"same value. This should have been addressed before this function."); "same value. This should have been addressed before this function.");
return DAG.getNode( return DAG.getNode(
ISD::CONCAT_VECTORS, DL, VT, ISD::CONCAT_VECTORS, DL, VT,
BottomHalf->isNullValue() ? RHS->getOperand(0) : LHS->getOperand(0), BottomHalf->isZero() ? RHS->getOperand(0) : LHS->getOperand(0),
TopHalf->isNullValue() ? RHS->getOperand(1) : LHS->getOperand(1)); TopHalf->isZero() ? RHS->getOperand(1) : LHS->getOperand(1));
} }
bool refineUniformBase(SDValue &BasePtr, SDValue &Index, SelectionDAG &DAG) { bool refineUniformBase(SDValue &BasePtr, SDValue &Index, SelectionDAG &DAG) {
@ -10203,7 +10203,7 @@ SDValue DAGCombiner::visitSELECT_CC(SDNode *N) {
AddToWorklist(SCC.getNode()); AddToWorklist(SCC.getNode());
if (ConstantSDNode *SCCC = dyn_cast<ConstantSDNode>(SCC.getNode())) { if (ConstantSDNode *SCCC = dyn_cast<ConstantSDNode>(SCC.getNode())) {
if (!SCCC->isNullValue()) if (!SCCC->isZero())
return N2; // cond always true -> true val return N2; // cond always true -> true val
else else
return N3; // cond always false -> false val return N3; // cond always false -> false val
@ -10261,13 +10261,13 @@ SDValue DAGCombiner::visitSETCC(SDNode *N) {
// Is 'X Cond C' always true or false? // Is 'X Cond C' always true or false?
auto IsAlwaysTrueOrFalse = [](ISD::CondCode Cond, ConstantSDNode *C) { auto IsAlwaysTrueOrFalse = [](ISD::CondCode Cond, ConstantSDNode *C) {
bool False = (Cond == ISD::SETULT && C->isNullValue()) || bool False = (Cond == ISD::SETULT && C->isZero()) ||
(Cond == ISD::SETLT && C->isMinSignedValue()) || (Cond == ISD::SETLT && C->isMinSignedValue()) ||
(Cond == ISD::SETUGT && C->isAllOnesValue()) || (Cond == ISD::SETUGT && C->isAllOnes()) ||
(Cond == ISD::SETGT && C->isMaxSignedValue()); (Cond == ISD::SETGT && C->isMaxSignedValue());
bool True = (Cond == ISD::SETULE && C->isAllOnesValue()) || bool True = (Cond == ISD::SETULE && C->isAllOnes()) ||
(Cond == ISD::SETLE && C->isMaxSignedValue()) || (Cond == ISD::SETLE && C->isMaxSignedValue()) ||
(Cond == ISD::SETUGE && C->isNullValue()) || (Cond == ISD::SETUGE && C->isZero()) ||
(Cond == ISD::SETGE && C->isMinSignedValue()); (Cond == ISD::SETGE && C->isMinSignedValue());
return True || False; return True || False;
}; };
@ -17395,7 +17395,7 @@ bool DAGCombiner::tryStoreMergeOfConstants(
SDValue StoredVal = ST->getValue(); SDValue StoredVal = ST->getValue();
bool IsElementZero = false; bool IsElementZero = false;
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(StoredVal)) if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(StoredVal))
IsElementZero = C->isNullValue(); IsElementZero = C->isZero();
else if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(StoredVal)) else if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(StoredVal))
IsElementZero = C->getConstantFPValue()->isNullValue(); IsElementZero = C->getConstantFPValue()->isNullValue();
if (IsElementZero) { if (IsElementZero) {
@ -22748,7 +22748,7 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
if (auto *SCCC = dyn_cast<ConstantSDNode>(SCC)) { if (auto *SCCC = dyn_cast<ConstantSDNode>(SCC)) {
// fold select_cc true, x, y -> x // fold select_cc true, x, y -> x
// fold select_cc false, x, y -> y // fold select_cc false, x, y -> y
return !(SCCC->isNullValue()) ? N2 : N3; return !(SCCC->isZero()) ? N2 : N3;
} }
} }
@ -22847,7 +22847,7 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
// select_cc setne X, 0, ctlz_zero_undef(X), sizeof(X) -> ctlz(X) // select_cc setne X, 0, ctlz_zero_undef(X), sizeof(X) -> ctlz(X)
// select_cc setne X, 0, cttz(X), sizeof(X) -> cttz(X) // select_cc setne X, 0, cttz(X), sizeof(X) -> cttz(X)
// select_cc setne X, 0, cttz_zero_undef(X), sizeof(X) -> cttz(X) // select_cc setne X, 0, cttz_zero_undef(X), sizeof(X) -> cttz(X)
if (N1C && N1C->isNullValue() && (CC == ISD::SETEQ || CC == ISD::SETNE)) { if (N1C && N1C->isZero() && (CC == ISD::SETEQ || CC == ISD::SETNE)) {
SDValue ValueOnZero = N2; SDValue ValueOnZero = N2;
SDValue Count = N3; SDValue Count = N3;
// If the condition is NE instead of E, swap the operands. // If the condition is NE instead of E, swap the operands.
@ -22878,8 +22878,8 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
// Fold select_cc setlt X, 0, C, ~C -> xor (ashr X, BW-1), ~C // Fold select_cc setlt X, 0, C, ~C -> xor (ashr X, BW-1), ~C
if (!NotExtCompare && N1C && N2C && N3C && if (!NotExtCompare && N1C && N2C && N3C &&
N2C->getAPIntValue() == ~N3C->getAPIntValue() && N2C->getAPIntValue() == ~N3C->getAPIntValue() &&
((N1C->isAllOnesValue() && CC == ISD::SETGT) || ((N1C->isAllOnes() && CC == ISD::SETGT) ||
(N1C->isNullValue() && CC == ISD::SETLT)) && (N1C->isZero() && CC == ISD::SETLT)) &&
!TLI.shouldAvoidTransformToShift(VT, CmpOpVT.getScalarSizeInBits() - 1)) { !TLI.shouldAvoidTransformToShift(VT, CmpOpVT.getScalarSizeInBits() - 1)) {
SDValue ASR = DAG.getNode( SDValue ASR = DAG.getNode(
ISD::SRA, DL, CmpOpVT, N0, ISD::SRA, DL, CmpOpVT, N0,
@ -22928,7 +22928,7 @@ SDValue DAGCombiner::BuildSDIVPow2(SDNode *N) {
return SDValue(); return SDValue();
// Avoid division by zero. // Avoid division by zero.
if (C->isNullValue()) if (C->isZero())
return SDValue(); return SDValue();
SmallVector<SDNode *, 8> Built; SmallVector<SDNode *, 8> Built;

View File

@ -4251,8 +4251,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
SDValue Op = Node->getOperand(IsStrict ? 1 : 0); SDValue Op = Node->getOperand(IsStrict ? 1 : 0);
SDValue Chain = IsStrict ? Node->getOperand(0) : SDValue(); SDValue Chain = IsStrict ? Node->getOperand(0) : SDValue();
EVT VT = Node->getValueType(0); EVT VT = Node->getValueType(0);
assert(cast<ConstantSDNode>(Node->getOperand(IsStrict ? 2 : 1)) assert(cast<ConstantSDNode>(Node->getOperand(IsStrict ? 2 : 1))->isZero() &&
->isNullValue() &&
"Unable to expand as libcall if it is not normal rounding"); "Unable to expand as libcall if it is not normal rounding");
RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), VT); RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), VT);

View File

@ -4375,7 +4375,7 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
if (CCCode == ISD::SETEQ || CCCode == ISD::SETNE) { if (CCCode == ISD::SETEQ || CCCode == ISD::SETNE) {
if (RHSLo == RHSHi) { if (RHSLo == RHSHi) {
if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) { if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) {
if (RHSCST->isAllOnesValue()) { if (RHSCST->isAllOnes()) {
// Equality comparison to -1. // Equality comparison to -1.
NewLHS = DAG.getNode(ISD::AND, dl, NewLHS = DAG.getNode(ISD::AND, dl,
LHSLo.getValueType(), LHSLo, LHSHi); LHSLo.getValueType(), LHSLo, LHSHi);
@ -4395,8 +4395,8 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
// If this is a comparison of the sign bit, just look at the top part. // If this is a comparison of the sign bit, just look at the top part.
// X > -1, x < 0 // X > -1, x < 0
if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(NewRHS)) if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(NewRHS))
if ((CCCode == ISD::SETLT && CST->isNullValue()) || // X < 0 if ((CCCode == ISD::SETLT && CST->isZero()) || // X < 0
(CCCode == ISD::SETGT && CST->isAllOnesValue())) { // X > -1 (CCCode == ISD::SETGT && CST->isAllOnes())) { // X > -1
NewLHS = LHSHi; NewLHS = LHSHi;
NewRHS = RHSHi; NewRHS = RHSHi;
return; return;
@ -4447,9 +4447,11 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
bool EqAllowed = (CCCode == ISD::SETLE || CCCode == ISD::SETGE || bool EqAllowed = (CCCode == ISD::SETLE || CCCode == ISD::SETGE ||
CCCode == ISD::SETUGE || CCCode == ISD::SETULE); CCCode == ISD::SETUGE || CCCode == ISD::SETULE);
if ((EqAllowed && (HiCmpC && HiCmpC->isNullValue())) || // FIXME: Is the HiCmpC->isOne() here correct for
(!EqAllowed && ((HiCmpC && (HiCmpC->getAPIntValue() == 1)) || // ZeroOrNegativeOneBooleanContent.
(LoCmpC && LoCmpC->isNullValue())))) { if ((EqAllowed && (HiCmpC && HiCmpC->isZero())) ||
(!EqAllowed &&
((HiCmpC && HiCmpC->isOne()) || (LoCmpC && LoCmpC->isZero())))) {
// For LE / GE, if high part is known false, ignore the low part. // For LE / GE, if high part is known false, ignore the low part.
// For LT / GT: if low part is known false, return the high part. // For LT / GT: if low part is known false, return the high part.
// if high part is known true, ignore the low part. // if high part is known true, ignore the low part.

View File

@ -529,7 +529,7 @@ SDValue DAGTypeLegalizer::ScalarizeVecRes_VECTOR_SHUFFLE(SDNode *N) {
SDValue Arg = N->getOperand(2).getOperand(0); SDValue Arg = N->getOperand(2).getOperand(0);
if (Arg.isUndef()) if (Arg.isUndef())
return DAG.getUNDEF(N->getValueType(0).getVectorElementType()); return DAG.getUNDEF(N->getValueType(0).getVectorElementType());
unsigned Op = !cast<ConstantSDNode>(Arg)->isNullValue(); unsigned Op = !cast<ConstantSDNode>(Arg)->isZero();
return GetScalarizedVector(N->getOperand(Op)); return GetScalarizedVector(N->getOperand(Op));
} }

View File

@ -1926,7 +1926,7 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
if (SameNumElts) if (SameNumElts)
return N1; return N1;
if (auto *C = dyn_cast<ConstantSDNode>(Splat)) if (auto *C = dyn_cast<ConstantSDNode>(Splat))
if (C->isNullValue()) if (C->isZero())
return N1; return N1;
} }
@ -3977,13 +3977,13 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
// Special case decrementing a value (ADD X, -1): // Special case decrementing a value (ADD X, -1):
if (ConstantSDNode *CRHS = if (ConstantSDNode *CRHS =
isConstOrConstSplat(Op.getOperand(1), DemandedElts)) isConstOrConstSplat(Op.getOperand(1), DemandedElts))
if (CRHS->isAllOnesValue()) { if (CRHS->isAllOnes()) {
KnownBits Known = KnownBits Known =
computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1); computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
// If the input is known to be 0 or 1, the output is 0/-1, which is all // If the input is known to be 0 or 1, the output is 0/-1, which is all
// sign bits set. // sign bits set.
if ((Known.Zero | 1).isAllOnesValue()) if ((Known.Zero | 1).isAllOnes())
return VTBits; return VTBits;
// If we are subtracting one from a positive number, there is no carry // If we are subtracting one from a positive number, there is no carry
@ -4002,12 +4002,12 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
// Handle NEG. // Handle NEG.
if (ConstantSDNode *CLHS = if (ConstantSDNode *CLHS =
isConstOrConstSplat(Op.getOperand(0), DemandedElts)) isConstOrConstSplat(Op.getOperand(0), DemandedElts))
if (CLHS->isNullValue()) { if (CLHS->isZero()) {
KnownBits Known = KnownBits Known =
computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1); computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
// If the input is known to be 0 or 1, the output is 0/-1, which is all // If the input is known to be 0 or 1, the output is 0/-1, which is all
// sign bits set. // sign bits set.
if ((Known.Zero | 1).isAllOnesValue()) if ((Known.Zero | 1).isAllOnes())
return VTBits; return VTBits;
// If the input is known to be positive (the sign bit is known clear), // If the input is known to be positive (the sign bit is known clear),
@ -4490,8 +4490,8 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op) const {
"Floating point types unsupported - use isKnownNeverZeroFloat"); "Floating point types unsupported - use isKnownNeverZeroFloat");
// If the value is a constant, we can obviously see if it is a zero or not. // If the value is a constant, we can obviously see if it is a zero or not.
if (ISD::matchUnaryPredicate( if (ISD::matchUnaryPredicate(Op,
Op, [](ConstantSDNode *C) { return !C->isNullValue(); })) [](ConstantSDNode *C) { return !C->isZero(); }))
return true; return true;
// TODO: Recognize more cases here. // TODO: Recognize more cases here.
@ -4531,7 +4531,7 @@ bool SelectionDAG::haveNoCommonBitsSet(SDValue A, SDValue B) const {
static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step, static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step,
SelectionDAG &DAG) { SelectionDAG &DAG) {
if (cast<ConstantSDNode>(Step)->isNullValue()) if (cast<ConstantSDNode>(Step)->isZero())
return DAG.getConstant(0, DL, VT); return DAG.getConstant(0, DL, VT);
return SDValue(); return SDValue();
@ -5632,9 +5632,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
N1.getValueType() == VT && "Binary operator types must match!"); N1.getValueType() == VT && "Binary operator types must match!");
// (X & 0) -> 0. This commonly occurs when legalizing i64 values, so it's // (X & 0) -> 0. This commonly occurs when legalizing i64 values, so it's
// worth handling here. // worth handling here.
if (N2C && N2C->isNullValue()) if (N2C && N2C->isZero())
return N2; return N2;
if (N2C && N2C->isAllOnesValue()) // X & -1 -> X if (N2C && N2C->isAllOnes()) // X & -1 -> X
return N1; return N1;
break; break;
case ISD::OR: case ISD::OR:
@ -5646,7 +5646,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
N1.getValueType() == VT && "Binary operator types must match!"); N1.getValueType() == VT && "Binary operator types must match!");
// (X ^|+- 0) -> X. This commonly occurs when legalizing i64 values, so // (X ^|+- 0) -> X. This commonly occurs when legalizing i64 values, so
// it's worth handling here. // it's worth handling here.
if (N2C && N2C->isNullValue()) if (N2C && N2C->isZero())
return N1; return N1;
if ((Opcode == ISD::ADD || Opcode == ISD::SUB) && VT.isVector() && if ((Opcode == ISD::ADD || Opcode == ISD::SUB) && VT.isVector() &&
VT.getVectorElementType() == MVT::i1) VT.getVectorElementType() == MVT::i1)
@ -5752,7 +5752,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
// size of the value, the shift/rotate count is guaranteed to be zero. // size of the value, the shift/rotate count is guaranteed to be zero.
if (VT == MVT::i1) if (VT == MVT::i1)
return N1; return N1;
if (N2C && N2C->isNullValue()) if (N2C && N2C->isZero())
return N1; return N1;
break; break;
case ISD::FP_ROUND: case ISD::FP_ROUND:
@ -6761,7 +6761,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl,
if (FI && !MFI.isFixedObjectIndex(FI->getIndex())) if (FI && !MFI.isFixedObjectIndex(FI->getIndex()))
DstAlignCanChange = true; DstAlignCanChange = true;
bool IsZeroVal = bool IsZeroVal =
isa<ConstantSDNode>(Src) && cast<ConstantSDNode>(Src)->isNullValue(); isa<ConstantSDNode>(Src) && cast<ConstantSDNode>(Src)->isZero();
if (!TLI.findOptimalMemOpLowering( if (!TLI.findOptimalMemOpLowering(
MemOps, TLI.getMaxStoresPerMemset(OptSize), MemOps, TLI.getMaxStoresPerMemset(OptSize),
MemOp::Set(Size, DstAlignCanChange, Alignment, IsZeroVal, isVol), MemOp::Set(Size, DstAlignCanChange, Alignment, IsZeroVal, isVol),
@ -6850,7 +6850,7 @@ SDValue SelectionDAG::getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst,
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
if (ConstantSize) { if (ConstantSize) {
// Memcpy with size zero? Just return the original chain. // Memcpy with size zero? Just return the original chain.
if (ConstantSize->isNullValue()) if (ConstantSize->isZero())
return Chain; return Chain;
SDValue Result = getMemcpyLoadsAndStores( SDValue Result = getMemcpyLoadsAndStores(
@ -6965,7 +6965,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
if (ConstantSize) { if (ConstantSize) {
// Memmove with size zero? Just return the original chain. // Memmove with size zero? Just return the original chain.
if (ConstantSize->isNullValue()) if (ConstantSize->isZero())
return Chain; return Chain;
SDValue Result = getMemmoveLoadsAndStores( SDValue Result = getMemmoveLoadsAndStores(
@ -7067,7 +7067,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
if (ConstantSize) { if (ConstantSize) {
// Memset with size zero? Just return the original chain. // Memset with size zero? Just return the original chain.
if (ConstantSize->isNullValue()) if (ConstantSize->isZero())
return Chain; return Chain;
SDValue Result = getMemsetStores(*this, dl, Chain, Dst, Src, SDValue Result = getMemsetStores(*this, dl, Chain, Dst, Src,
@ -8227,7 +8227,7 @@ SDValue SelectionDAG::simplifySelect(SDValue Cond, SDValue T, SDValue F) {
// select true, T, F --> T // select true, T, F --> T
// select false, T, F --> F // select false, T, F --> F
if (auto *CondC = dyn_cast<ConstantSDNode>(Cond)) if (auto *CondC = dyn_cast<ConstantSDNode>(Cond))
return CondC->isNullValue() ? F : T; return CondC->isZero() ? F : T;
// TODO: This should simplify VSELECT with constant condition using something // TODO: This should simplify VSELECT with constant condition using something
// like this (but check boolean contents to be complete?): // like this (but check boolean contents to be complete?):
@ -9935,7 +9935,7 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op,
bool llvm::isNullConstant(SDValue V) { bool llvm::isNullConstant(SDValue V) {
ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V); ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
return Const != nullptr && Const->isNullValue(); return Const != nullptr && Const->isZero();
} }
bool llvm::isNullFPConstant(SDValue V) { bool llvm::isNullFPConstant(SDValue V) {
@ -9945,7 +9945,7 @@ bool llvm::isNullFPConstant(SDValue V) {
bool llvm::isAllOnesConstant(SDValue V) { bool llvm::isAllOnesConstant(SDValue V) {
ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V); ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
return Const != nullptr && Const->isAllOnesValue(); return Const != nullptr && Const->isAllOnes();
} }
bool llvm::isOneConstant(SDValue V) { bool llvm::isOneConstant(SDValue V) {
@ -10079,7 +10079,7 @@ bool llvm::isNullOrNullSplat(SDValue N, bool AllowUndefs) {
// TODO: may want to use peekThroughBitcast() here. // TODO: may want to use peekThroughBitcast() here.
ConstantSDNode *C = ConstantSDNode *C =
isConstOrConstSplat(N, AllowUndefs, /*AllowTruncation=*/true); isConstOrConstSplat(N, AllowUndefs, /*AllowTruncation=*/true);
return C && C->isNullValue(); return C && C->isZero();
} }
bool llvm::isOneOrOneSplat(SDValue N, bool AllowUndefs) { bool llvm::isOneOrOneSplat(SDValue N, bool AllowUndefs) {
@ -10093,7 +10093,7 @@ bool llvm::isAllOnesOrAllOnesSplat(SDValue N, bool AllowUndefs) {
N = peekThroughBitcasts(N); N = peekThroughBitcasts(N);
unsigned BitWidth = N.getScalarValueSizeInBits(); unsigned BitWidth = N.getScalarValueSizeInBits();
ConstantSDNode *C = isConstOrConstSplat(N, AllowUndefs); ConstantSDNode *C = isConstOrConstSplat(N, AllowUndefs);
return C && C->isAllOnesValue() && C->getValueSizeInBits(0) == BitWidth; return C && C->isAllOnes() && C->getValueSizeInBits(0) == BitWidth;
} }
HandleSDNode::~HandleSDNode() { HandleSDNode::~HandleSDNode() {

View File

@ -1359,8 +1359,7 @@ bool TargetLowering::SimplifyDemandedBits(
// If the RHS is a constant, see if we can change it. Don't alter a -1 // If the RHS is a constant, see if we can change it. Don't alter a -1
// constant because that's a 'not' op, and that is better for combining // constant because that's a 'not' op, and that is better for combining
// and codegen. // and codegen.
if (!C->isAllOnesValue() && if (!C->isAllOnes() && DemandedBits.isSubsetOf(C->getAPIntValue())) {
DemandedBits.isSubsetOf(C->getAPIntValue())) {
// We're flipping all demanded bits. Flip the undemanded bits too. // We're flipping all demanded bits. Flip the undemanded bits too.
SDValue New = TLO.DAG.getNOT(dl, Op0, VT); SDValue New = TLO.DAG.getNOT(dl, Op0, VT);
return TLO.CombineTo(Op, New); return TLO.CombineTo(Op, New);
@ -1368,7 +1367,7 @@ bool TargetLowering::SimplifyDemandedBits(
} }
// If we can't turn this into a 'not', try to shrink the constant. // If we can't turn this into a 'not', try to shrink the constant.
if (!C || !C->isAllOnesValue()) if (!C || !C->isAllOnes())
if (ShrinkDemandedConstant(Op, DemandedBits, DemandedElts, TLO)) if (ShrinkDemandedConstant(Op, DemandedBits, DemandedElts, TLO))
return true; return true;
@ -2252,7 +2251,7 @@ bool TargetLowering::SimplifyDemandedBits(
// is probably not useful (and could be detrimental). // is probably not useful (and could be detrimental).
ConstantSDNode *C = isConstOrConstSplat(Op1); ConstantSDNode *C = isConstOrConstSplat(Op1);
APInt HighMask = APInt::getHighBitsSet(BitWidth, DemandedBitsLZ); APInt HighMask = APInt::getHighBitsSet(BitWidth, DemandedBitsLZ);
if (C && !C->isAllOnesValue() && !C->isOne() && if (C && !C->isAllOnes() && !C->isOne() &&
(C->getAPIntValue() | HighMask).isAllOnes()) { (C->getAPIntValue() | HighMask).isAllOnes()) {
SDValue Neg1 = TLO.DAG.getAllOnesConstant(dl, VT); SDValue Neg1 = TLO.DAG.getAllOnesConstant(dl, VT);
// Disable the nsw and nuw flags. We can no longer guarantee that we // Disable the nsw and nuw flags. We can no longer guarantee that we
@ -3146,7 +3145,7 @@ bool TargetLowering::isConstFalseVal(const SDNode *N) const {
if (getBooleanContents(N->getValueType(0)) == UndefinedBooleanContent) if (getBooleanContents(N->getValueType(0)) == UndefinedBooleanContent)
return !CN->getAPIntValue()[0]; return !CN->getAPIntValue()[0];
return CN->isNullValue(); return CN->isZero();
} }
bool TargetLowering::isExtendedTrueVal(const ConstantSDNode *N, EVT VT, bool TargetLowering::isExtendedTrueVal(const ConstantSDNode *N, EVT VT,
@ -3162,7 +3161,7 @@ bool TargetLowering::isExtendedTrueVal(const ConstantSDNode *N, EVT VT,
return (N->isOne() && !SExt) || (SExt && (N->getValueType(0) != MVT::i1)); return (N->isOne() && !SExt) || (SExt && (N->getValueType(0) != MVT::i1));
case TargetLowering::UndefinedBooleanContent: case TargetLowering::UndefinedBooleanContent:
case TargetLowering::ZeroOrNegativeOneBooleanContent: case TargetLowering::ZeroOrNegativeOneBooleanContent:
return N->isAllOnesValue() && SExt; return N->isAllOnes() && SExt;
} }
llvm_unreachable("Unexpected enumeration."); llvm_unreachable("Unexpected enumeration.");
} }
@ -3216,7 +3215,7 @@ SDValue TargetLowering::foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1,
// Bail out if the compare operand that we want to turn into a zero is // Bail out if the compare operand that we want to turn into a zero is
// already a zero (otherwise, infinite loop). // already a zero (otherwise, infinite loop).
auto *YConst = dyn_cast<ConstantSDNode>(Y); auto *YConst = dyn_cast<ConstantSDNode>(Y);
if (YConst && YConst->isNullValue()) if (YConst && YConst->isZero())
return SDValue(); return SDValue();
// Transform this into: ~X & Y == 0. // Transform this into: ~X & Y == 0.
@ -3654,8 +3653,8 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
(isConstFalseVal(N1C) || (isConstFalseVal(N1C) ||
isExtendedTrueVal(N1C, N0->getValueType(0), SExt))) { isExtendedTrueVal(N1C, N0->getValueType(0), SExt))) {
bool Inverse = (N1C->isNullValue() && Cond == ISD::SETEQ) || bool Inverse = (N1C->isZero() && Cond == ISD::SETEQ) ||
(!N1C->isNullValue() && Cond == ISD::SETNE); (!N1C->isZero() && Cond == ISD::SETNE);
if (!Inverse) if (!Inverse)
return TopSetCC; return TopSetCC;
@ -3806,7 +3805,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
// Otherwise, make this a use of a zext. // Otherwise, make this a use of a zext.
return DAG.getSetCC(dl, VT, ZextOp, return DAG.getSetCC(dl, VT, ZextOp,
DAG.getConstant(C1 & Imm, dl, ExtDstTy), Cond); DAG.getConstant(C1 & Imm, dl, ExtDstTy), Cond);
} else if ((N1C->isNullValue() || N1C->isOne()) && } else if ((N1C->isZero() || N1C->isOne()) &&
(Cond == ISD::SETEQ || Cond == ISD::SETNE)) { (Cond == ISD::SETEQ || Cond == ISD::SETNE)) {
// SETCC (SETCC), [0|1], [EQ|NE] -> SETCC // SETCC (SETCC), [0|1], [EQ|NE] -> SETCC
if (N0.getOpcode() == ISD::SETCC && if (N0.getOpcode() == ISD::SETCC &&
@ -3900,7 +3899,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
// icmp eq/ne (urem %x, %y), 0 // icmp eq/ne (urem %x, %y), 0
// Iff %x has 0 or 1 bits set, and %y has at least 2 bits set, omit 'urem': // Iff %x has 0 or 1 bits set, and %y has at least 2 bits set, omit 'urem':
// icmp eq/ne %x, 0 // icmp eq/ne %x, 0
if (N0.getOpcode() == ISD::UREM && N1C->isNullValue() && if (N0.getOpcode() == ISD::UREM && N1C->isZero() &&
(Cond == ISD::SETEQ || Cond == ISD::SETNE)) { (Cond == ISD::SETEQ || Cond == ISD::SETNE)) {
KnownBits XKnown = DAG.computeKnownBits(N0.getOperand(0)); KnownBits XKnown = DAG.computeKnownBits(N0.getOperand(0));
KnownBits YKnown = DAG.computeKnownBits(N0.getOperand(1)); KnownBits YKnown = DAG.computeKnownBits(N0.getOperand(1));
@ -3913,7 +3912,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
N0.getOpcode() == ISD::SRA && isa<ConstantSDNode>(N0.getOperand(1)) && N0.getOpcode() == ISD::SRA && isa<ConstantSDNode>(N0.getOperand(1)) &&
N0.getConstantOperandAPInt(1) == OpVT.getScalarSizeInBits() - 1 && N0.getConstantOperandAPInt(1) == OpVT.getScalarSizeInBits() - 1 &&
N1C && N1C->isAllOnesValue()) { N1C && N1C->isAllOnes()) {
return DAG.getSetCC(dl, VT, N0.getOperand(0), return DAG.getSetCC(dl, VT, N0.getOperand(0),
DAG.getConstant(0, dl, OpVT), DAG.getConstant(0, dl, OpVT),
Cond == ISD::SETEQ ? ISD::SETLT : ISD::SETGE); Cond == ISD::SETEQ ? ISD::SETLT : ISD::SETGE);
@ -5067,7 +5066,7 @@ static SDValue BuildExactSDIV(const TargetLowering &TLI, SDNode *N,
SmallVector<SDValue, 16> Shifts, Factors; SmallVector<SDValue, 16> Shifts, Factors;
auto BuildSDIVPattern = [&](ConstantSDNode *C) { auto BuildSDIVPattern = [&](ConstantSDNode *C) {
if (C->isNullValue()) if (C->isZero())
return false; return false;
APInt Divisor = C->getAPIntValue(); APInt Divisor = C->getAPIntValue();
unsigned Shift = Divisor.countTrailingZeros(); unsigned Shift = Divisor.countTrailingZeros();
@ -5275,7 +5274,7 @@ SDValue TargetLowering::BuildSDIV(SDNode *N, SelectionDAG &DAG,
SmallVector<SDValue, 16> MagicFactors, Factors, Shifts, ShiftMasks; SmallVector<SDValue, 16> MagicFactors, Factors, Shifts, ShiftMasks;
auto BuildSDIVPattern = [&](ConstantSDNode *C) { auto BuildSDIVPattern = [&](ConstantSDNode *C) {
if (C->isNullValue()) if (C->isZero())
return false; return false;
const APInt &Divisor = C->getAPIntValue(); const APInt &Divisor = C->getAPIntValue();
@ -5420,7 +5419,7 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
SmallVector<SDValue, 16> PreShifts, PostShifts, MagicFactors, NPQFactors; SmallVector<SDValue, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
auto BuildUDIVPattern = [&](ConstantSDNode *C) { auto BuildUDIVPattern = [&](ConstantSDNode *C) {
if (C->isNullValue()) if (C->isZero())
return false; return false;
// FIXME: We should use a narrower constant when the upper // FIXME: We should use a narrower constant when the upper
// bits are known to be zero. // bits are known to be zero.
@ -5634,7 +5633,7 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
auto BuildUREMPattern = [&](ConstantSDNode *CDiv, ConstantSDNode *CCmp) { auto BuildUREMPattern = [&](ConstantSDNode *CDiv, ConstantSDNode *CCmp) {
// Division by 0 is UB. Leave it to be constant-folded elsewhere. // Division by 0 is UB. Leave it to be constant-folded elsewhere.
if (CDiv->isNullValue()) if (CDiv->isZero())
return false; return false;
const APInt &D = CDiv->getAPIntValue(); const APInt &D = CDiv->getAPIntValue();
@ -5875,7 +5874,7 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
// TODO: Could support comparing with non-zero too. // TODO: Could support comparing with non-zero too.
ConstantSDNode *CompTarget = isConstOrConstSplat(CompTargetNode); ConstantSDNode *CompTarget = isConstOrConstSplat(CompTargetNode);
if (!CompTarget || !CompTarget->isNullValue()) if (!CompTarget || !CompTarget->isZero())
return SDValue(); return SDValue();
bool HadIntMinDivisor = false; bool HadIntMinDivisor = false;
@ -5888,7 +5887,7 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
auto BuildSREMPattern = [&](ConstantSDNode *C) { auto BuildSREMPattern = [&](ConstantSDNode *C) {
// Division by 0 is UB. Leave it to be constant-folded elsewhere. // Division by 0 is UB. Leave it to be constant-folded elsewhere.
if (C->isNullValue()) if (C->isZero())
return false; return false;
// FIXME: we don't fold `rem %X, -C` to `rem %X, C` in DAGCombine. // FIXME: we don't fold `rem %X, -C` to `rem %X, C` in DAGCombine.
@ -8041,7 +8040,7 @@ SDValue TargetLowering::lowerCmpEqZeroToCtlzSrl(SDValue Op,
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
SDLoc dl(Op); SDLoc dl(Op);
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
if (C->isNullValue() && CC == ISD::SETEQ) { if (C->isZero() && CC == ISD::SETEQ) {
EVT VT = Op.getOperand(0).getValueType(); EVT VT = Op.getOperand(0).getValueType();
SDValue Zext = Op.getOperand(0); SDValue Zext = Op.getOperand(0);
if (VT.bitsLT(MVT::i32)) { if (VT.bitsLT(MVT::i32)) {

View File

@ -167,7 +167,7 @@ public:
case ISD::SPLAT_VECTOR: { case ISD::SPLAT_VECTOR: {
auto Opnd0 = N->getOperand(0); auto Opnd0 = N->getOperand(0);
if (auto CN = dyn_cast<ConstantSDNode>(Opnd0)) if (auto CN = dyn_cast<ConstantSDNode>(Opnd0))
if (CN->isNullValue()) if (CN->isZero())
return true; return true;
if (auto CN = dyn_cast<ConstantFPSDNode>(Opnd0)) if (auto CN = dyn_cast<ConstantFPSDNode>(Opnd0))
if (CN->isZero()) if (CN->isZero())
@ -187,7 +187,7 @@ public:
case ISD::SPLAT_VECTOR: { case ISD::SPLAT_VECTOR: {
auto Opnd0 = N->getOperand(0); auto Opnd0 = N->getOperand(0);
if (auto CN = dyn_cast<ConstantSDNode>(Opnd0)) if (auto CN = dyn_cast<ConstantSDNode>(Opnd0))
if (CN->isNullValue()) if (CN->isZero())
return true; return true;
if (auto CN = dyn_cast<ConstantFPSDNode>(Opnd0)) if (auto CN = dyn_cast<ConstantFPSDNode>(Opnd0))
if (CN->isZero()) if (CN->isZero())
@ -3520,7 +3520,7 @@ void AArch64DAGToDAGISel::Select(SDNode *Node) {
// Materialize zero constants as copies from WZR/XZR. This allows // Materialize zero constants as copies from WZR/XZR. This allows
// the coalescer to propagate these into other instructions. // the coalescer to propagate these into other instructions.
ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node); ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
if (ConstNode->isNullValue()) { if (ConstNode->isZero()) {
if (VT == MVT::i32) { if (VT == MVT::i32) {
SDValue New = CurDAG->getCopyFromReg( SDValue New = CurDAG->getCopyFromReg(
CurDAG->getEntryNode(), SDLoc(Node), AArch64::WZR, MVT::i32); CurDAG->getEntryNode(), SDLoc(Node), AArch64::WZR, MVT::i32);

View File

@ -2308,7 +2308,7 @@ static bool isZerosVector(const SDNode *N) {
auto Opnd0 = N->getOperand(0); auto Opnd0 = N->getOperand(0);
auto *CINT = dyn_cast<ConstantSDNode>(Opnd0); auto *CINT = dyn_cast<ConstantSDNode>(Opnd0);
auto *CFP = dyn_cast<ConstantFPSDNode>(Opnd0); auto *CFP = dyn_cast<ConstantFPSDNode>(Opnd0);
return (CINT && CINT->isNullValue()) || (CFP && CFP->isZero()); return (CINT && CINT->isZero()) || (CFP && CFP->isZero());
} }
/// changeIntCCToAArch64CC - Convert a DAG integer condition code to an AArch64 /// changeIntCCToAArch64CC - Convert a DAG integer condition code to an AArch64
@ -2990,9 +2990,9 @@ static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
} }
} }
if (!Cmp && (RHSC->isNullValue() || RHSC->isOne())) { if (!Cmp && (RHSC->isZero() || RHSC->isOne())) {
if ((Cmp = emitConjunction(DAG, LHS, AArch64CC))) { if ((Cmp = emitConjunction(DAG, LHS, AArch64CC))) {
if ((CC == ISD::SETNE) ^ RHSC->isNullValue()) if ((CC == ISD::SETNE) ^ RHSC->isZero())
AArch64CC = AArch64CC::getInvertedCondCode(AArch64CC); AArch64CC = AArch64CC::getInvertedCondCode(AArch64CC);
} }
} }
@ -3157,14 +3157,14 @@ SDValue AArch64TargetLowering::LowerXOR(SDValue Op, SelectionDAG &DAG) const {
// We can commute the SELECT_CC by inverting the condition. This // We can commute the SELECT_CC by inverting the condition. This
// might be needed to make this fit into a CSINV pattern. // might be needed to make this fit into a CSINV pattern.
if (CTVal->isAllOnesValue() && CFVal->isNullValue()) { if (CTVal->isAllOnes() && CFVal->isZero()) {
std::swap(TVal, FVal); std::swap(TVal, FVal);
std::swap(CTVal, CFVal); std::swap(CTVal, CFVal);
CC = ISD::getSetCCInverse(CC, LHS.getValueType()); CC = ISD::getSetCCInverse(CC, LHS.getValueType());
} }
// If the constants line up, perform the transform! // If the constants line up, perform the transform!
if (CTVal->isNullValue() && CFVal->isAllOnesValue()) { if (CTVal->isZero() && CFVal->isAllOnes()) {
SDValue CCVal; SDValue CCVal;
SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl); SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl);
@ -7433,8 +7433,8 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
// Check for sign pattern (SELECT_CC setgt, iN lhs, -1, 1, -1) and transform // Check for sign pattern (SELECT_CC setgt, iN lhs, -1, 1, -1) and transform
// into (OR (ASR lhs, N-1), 1), which requires less instructions for the // into (OR (ASR lhs, N-1), 1), which requires less instructions for the
// supported types. // supported types.
if (CC == ISD::SETGT && RHSC && RHSC->isAllOnesValue() && CTVal && CFVal && if (CC == ISD::SETGT && RHSC && RHSC->isAllOnes() && CTVal && CFVal &&
CTVal->isOne() && CFVal->isAllOnesValue() && CTVal->isOne() && CFVal->isAllOnes() &&
LHS.getValueType() == TVal.getValueType()) { LHS.getValueType() == TVal.getValueType()) {
EVT VT = LHS.getValueType(); EVT VT = LHS.getValueType();
SDValue Shift = SDValue Shift =
@ -7447,11 +7447,11 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
// If both the TVal and the FVal are constants, see if we can swap them in // If both the TVal and the FVal are constants, see if we can swap them in
// order to for a CSINV or CSINC out of them. // order to for a CSINV or CSINC out of them.
if (CTVal && CFVal && CTVal->isAllOnesValue() && CFVal->isNullValue()) { if (CTVal && CFVal && CTVal->isAllOnes() && CFVal->isZero()) {
std::swap(TVal, FVal); std::swap(TVal, FVal);
std::swap(CTVal, CFVal); std::swap(CTVal, CFVal);
CC = ISD::getSetCCInverse(CC, LHS.getValueType()); CC = ISD::getSetCCInverse(CC, LHS.getValueType());
} else if (CTVal && CFVal && CTVal->isOne() && CFVal->isNullValue()) { } else if (CTVal && CFVal && CTVal->isOne() && CFVal->isZero()) {
std::swap(TVal, FVal); std::swap(TVal, FVal);
std::swap(CTVal, CFVal); std::swap(CTVal, CFVal);
CC = ISD::getSetCCInverse(CC, LHS.getValueType()); CC = ISD::getSetCCInverse(CC, LHS.getValueType());
@ -7530,7 +7530,7 @@ SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
// FVal, respectively. // FVal, respectively.
ConstantSDNode *RHSVal = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSVal = dyn_cast<ConstantSDNode>(RHS);
if (Opcode == AArch64ISD::CSEL && RHSVal && !RHSVal->isOne() && if (Opcode == AArch64ISD::CSEL && RHSVal && !RHSVal->isOne() &&
!RHSVal->isNullValue() && !RHSVal->isAllOnesValue()) { !RHSVal->isZero() && !RHSVal->isAllOnes()) {
AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC); AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC);
// Transform "a == C ? C : x" to "a == C ? a : x" and "a != C ? x : C" to // Transform "a == C ? C : x" to "a == C ? a : x" and "a != C ? x : C" to
// "a != C ? x : a" to avoid materializing C. // "a != C ? x : a" to avoid materializing C.
@ -9643,7 +9643,7 @@ SDValue AArch64TargetLowering::LowerSPLAT_VECTOR(SDValue Op,
// The only legal i1 vectors are SVE vectors, so we can use SVE-specific // The only legal i1 vectors are SVE vectors, so we can use SVE-specific
// lowering code. // lowering code.
if (auto *ConstVal = dyn_cast<ConstantSDNode>(SplatVal)) { if (auto *ConstVal = dyn_cast<ConstantSDNode>(SplatVal)) {
if (ConstVal->isNullValue()) if (ConstVal->isZero())
return SDValue(DAG.getMachineNode(AArch64::PFALSE, dl, VT), 0); return SDValue(DAG.getMachineNode(AArch64::PFALSE, dl, VT), 0);
if (ConstVal->isOne()) if (ConstVal->isOne())
return getPTrue(DAG, dl, VT, AArch64SVEPredPattern::all); return getPTrue(DAG, dl, VT, AArch64SVEPredPattern::all);
@ -13967,7 +13967,7 @@ static bool isSetCC(SDValue Op, SetCCInfoAndKind &SetCCInfo) {
SetCCInfo.Info.AArch64.CC = SetCCInfo.Info.AArch64.CC =
AArch64CC::getInvertedCondCode(SetCCInfo.Info.AArch64.CC); AArch64CC::getInvertedCondCode(SetCCInfo.Info.AArch64.CC);
} }
return TValue->isOne() && FValue->isNullValue(); return TValue->isOne() && FValue->isZero();
} }
// Returns true if Op is setcc or zext of setcc. // Returns true if Op is setcc or zext of setcc.
@ -14045,7 +14045,7 @@ static SDValue performUADDVCombine(SDNode *N, SelectionDAG &DAG) {
auto *LHSN1 = dyn_cast<ConstantSDNode>(LHS->getOperand(1)); auto *LHSN1 = dyn_cast<ConstantSDNode>(LHS->getOperand(1));
auto *RHSN1 = dyn_cast<ConstantSDNode>(RHS->getOperand(1)); auto *RHSN1 = dyn_cast<ConstantSDNode>(RHS->getOperand(1));
if (!LHSN1 || LHSN1 != RHSN1 || !RHSN1->isNullValue()) if (!LHSN1 || LHSN1 != RHSN1 || !RHSN1->isZero())
return SDValue(); return SDValue();
SDValue Op1 = LHS->getOperand(0); SDValue Op1 = LHS->getOperand(0);

View File

@ -24,8 +24,10 @@ SDValue AArch64SelectionDAGInfo::EmitTargetCodeForMemset(
ConstantSDNode *SizeValue = dyn_cast<ConstantSDNode>(Size); ConstantSDNode *SizeValue = dyn_cast<ConstantSDNode>(Size);
const AArch64Subtarget &STI = const AArch64Subtarget &STI =
DAG.getMachineFunction().getSubtarget<AArch64Subtarget>(); DAG.getMachineFunction().getSubtarget<AArch64Subtarget>();
const char *bzeroName = (V && V->isNullValue()) const char *bzeroName =
? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO) : nullptr; (V && V->isZero())
? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO)
: nullptr;
// For small size (< 256), it is not beneficial to use bzero // For small size (< 256), it is not beneficial to use bzero
// instead of memset. // instead of memset.
if (bzeroName && (!SizeValue || SizeValue->getZExtValue() > 256)) { if (bzeroName && (!SizeValue || SizeValue->getZExtValue() > 256)) {

View File

@ -52,7 +52,7 @@ static bool isNullConstantOrUndef(SDValue V) {
return true; return true;
ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V); ConstantSDNode *Const = dyn_cast<ConstantSDNode>(V);
return Const != nullptr && Const->isNullValue(); return Const != nullptr && Const->isZero();
} }
static bool getConstantValue(SDValue N, uint32_t &Out) { static bool getConstantValue(SDValue N, uint32_t &Out) {
@ -354,7 +354,7 @@ static bool isExtractHiElt(SDValue In, SDValue &Out) {
static SDValue stripExtractLoElt(SDValue In) { static SDValue stripExtractLoElt(SDValue In) {
if (In.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { if (In.getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(In.getOperand(1))) { if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(In.getOperand(1))) {
if (Idx->isNullValue() && In.getValueSizeInBits() <= 32) if (Idx->isZero() && In.getValueSizeInBits() <= 32)
return In.getOperand(0); return In.getOperand(0);
} }
} }

View File

@ -3532,7 +3532,7 @@ SDValue AMDGPUTargetLowering::performMulhuCombine(SDNode *N,
static bool isNegativeOne(SDValue Val) { static bool isNegativeOne(SDValue Val) {
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val)) if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val))
return C->isAllOnesValue(); return C->isAllOnes();
return false; return false;
} }
@ -3567,7 +3567,7 @@ SDValue AMDGPUTargetLowering::performCtlz_CttzCombine(const SDLoc &SL, SDValue C
SDValue LHS, SDValue RHS, SDValue LHS, SDValue RHS,
DAGCombinerInfo &DCI) const { DAGCombinerInfo &DCI) const {
ConstantSDNode *CmpRhs = dyn_cast<ConstantSDNode>(Cond.getOperand(1)); ConstantSDNode *CmpRhs = dyn_cast<ConstantSDNode>(Cond.getOperand(1));
if (!CmpRhs || !CmpRhs->isNullValue()) if (!CmpRhs || !CmpRhs->isZero())
return SDValue(); return SDValue();
SelectionDAG &DAG = DCI.DAG; SelectionDAG &DAG = DCI.DAG;

View File

@ -828,7 +828,7 @@ SDValue R600TargetLowering::LowerImplicitParameter(SelectionDAG &DAG, EVT VT,
bool R600TargetLowering::isZero(SDValue Op) const { bool R600TargetLowering::isZero(SDValue Op) const {
if(ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Op)) { if(ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Op)) {
return Cst->isNullValue(); return Cst->isZero();
} else if(ConstantFPSDNode *CstFP = dyn_cast<ConstantFPSDNode>(Op)){ } else if(ConstantFPSDNode *CstFP = dyn_cast<ConstantFPSDNode>(Op)){
return CstFP->isZero(); return CstFP->isZero();
} else { } else {

View File

@ -4844,7 +4844,7 @@ static SDValue lowerBALLOTIntrinsic(const SITargetLowering &TLI, SDNode *N,
} }
if (const ConstantSDNode *Arg = dyn_cast<ConstantSDNode>(Src)) { if (const ConstantSDNode *Arg = dyn_cast<ConstantSDNode>(Src)) {
// (ballot 0) -> 0 // (ballot 0) -> 0
if (Arg->isNullValue()) if (Arg->isZero())
return DAG.getConstant(0, SL, VT); return DAG.getConstant(0, SL, VT);
// (ballot 1) -> EXEC/EXEC_LO // (ballot 1) -> EXEC/EXEC_LO
@ -6153,7 +6153,7 @@ SDValue SITargetLowering::lowerImage(SDValue Op,
if (MIPMappingInfo) { if (MIPMappingInfo) {
if (auto *ConstantLod = dyn_cast<ConstantSDNode>( if (auto *ConstantLod = dyn_cast<ConstantSDNode>(
Op.getOperand(ArgOffset + Intr->MipIndex))) { Op.getOperand(ArgOffset + Intr->MipIndex))) {
if (ConstantLod->isNullValue()) { if (ConstantLod->isZero()) {
IntrOpcode = MIPMappingInfo->NONMIP; // set new opcode to variant without _mip IntrOpcode = MIPMappingInfo->NONMIP; // set new opcode to variant without _mip
VAddrEnd--; // remove 'mip' VAddrEnd--; // remove 'mip'
} }
@ -6688,7 +6688,7 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
// intrinsic has the numerator as the first operand to match a normal // intrinsic has the numerator as the first operand to match a normal
// division operation. // division operation.
SDValue Src0 = Param->isAllOnesValue() ? Numerator : Denominator; SDValue Src0 = Param->isAllOnes() ? Numerator : Denominator;
return DAG.getNode(AMDGPUISD::DIV_SCALE, DL, Op->getVTList(), Src0, return DAG.getNode(AMDGPUISD::DIV_SCALE, DL, Op->getVTList(), Src0,
Denominator, Numerator); Denominator, Numerator);
@ -6822,7 +6822,7 @@ static void updateBufferMMO(MachineMemOperand *MMO, SDValue VOffset,
} }
if (VIndex && (!isa<ConstantSDNode>(VIndex) || if (VIndex && (!isa<ConstantSDNode>(VIndex) ||
!cast<ConstantSDNode>(VIndex)->isNullValue())) { !cast<ConstantSDNode>(VIndex)->isZero())) {
// The strided index component of the address is not known to be zero, so we // The strided index component of the address is not known to be zero, so we
// cannot represent it in the MMO. Give up. // cannot represent it in the MMO. Give up.
MMO->setValue((Value *)nullptr); MMO->setValue((Value *)nullptr);
@ -7667,7 +7667,7 @@ SDValue SITargetLowering::LowerINTRINSIC_VOID(SDValue Op,
Op.getOperand(0) // Chain Op.getOperand(0) // Chain
}; };
unsigned Opc = Done->isNullValue() ? AMDGPU::EXP : AMDGPU::EXP_DONE; unsigned Opc = Done->isZero() ? AMDGPU::EXP : AMDGPU::EXP_DONE;
return SDValue(DAG.getMachineNode(Opc, DL, Op->getVTList(), Ops), 0); return SDValue(DAG.getMachineNode(Opc, DL, Op->getVTList(), Ops), 0);
} }
case Intrinsic::amdgcn_s_barrier: { case Intrinsic::amdgcn_s_barrier: {
@ -9512,7 +9512,7 @@ SDValue SITargetLowering::performClassCombine(SDNode *N,
// fp_class x, 0 -> false // fp_class x, 0 -> false
if (const ConstantSDNode *CMask = dyn_cast<ConstantSDNode>(Mask)) { if (const ConstantSDNode *CMask = dyn_cast<ConstantSDNode>(Mask)) {
if (CMask->isNullValue()) if (CMask->isZero())
return DAG.getConstant(0, SDLoc(N), MVT::i1); return DAG.getConstant(0, SDLoc(N), MVT::i1);
} }
@ -10501,7 +10501,7 @@ SDValue SITargetLowering::performSubCombine(SDNode *N,
if (LHS.getOpcode() == ISD::SUBCARRY) { if (LHS.getOpcode() == ISD::SUBCARRY) {
// sub (subcarry x, 0, cc), y => subcarry x, y, cc // sub (subcarry x, 0, cc), y => subcarry x, y, cc
auto C = dyn_cast<ConstantSDNode>(LHS.getOperand(1)); auto C = dyn_cast<ConstantSDNode>(LHS.getOperand(1));
if (!C || !C->isNullValue()) if (!C || !C->isZero())
return SDValue(); return SDValue();
SDValue Args[] = { LHS.getOperand(0), RHS, LHS.getOperand(2) }; SDValue Args[] = { LHS.getOperand(0), RHS, LHS.getOperand(2) };
return DAG.getNode(ISD::SUBCARRY, SDLoc(N), LHS->getVTList(), Args); return DAG.getNode(ISD::SUBCARRY, SDLoc(N), LHS->getVTList(), Args);
@ -10724,15 +10724,15 @@ SDValue SITargetLowering::performSetCCCombine(SDNode *N,
// setcc (sext from i1 cc), -1, eq|sle|uge) => cc // setcc (sext from i1 cc), -1, eq|sle|uge) => cc
// setcc (sext from i1 cc), 0, eq|sge|ule) => not cc => xor cc, -1 // setcc (sext from i1 cc), 0, eq|sge|ule) => not cc => xor cc, -1
// setcc (sext from i1 cc), 0, ne|ugt|slt) => cc // setcc (sext from i1 cc), 0, ne|ugt|slt) => cc
if ((CRHS->isAllOnesValue() && if ((CRHS->isAllOnes() &&
(CC == ISD::SETNE || CC == ISD::SETGT || CC == ISD::SETULT)) || (CC == ISD::SETNE || CC == ISD::SETGT || CC == ISD::SETULT)) ||
(CRHS->isNullValue() && (CRHS->isZero() &&
(CC == ISD::SETEQ || CC == ISD::SETGE || CC == ISD::SETULE))) (CC == ISD::SETEQ || CC == ISD::SETGE || CC == ISD::SETULE)))
return DAG.getNode(ISD::XOR, SL, MVT::i1, LHS.getOperand(0), return DAG.getNode(ISD::XOR, SL, MVT::i1, LHS.getOperand(0),
DAG.getConstant(-1, SL, MVT::i1)); DAG.getConstant(-1, SL, MVT::i1));
if ((CRHS->isAllOnesValue() && if ((CRHS->isAllOnes() &&
(CC == ISD::SETEQ || CC == ISD::SETLE || CC == ISD::SETUGE)) || (CC == ISD::SETEQ || CC == ISD::SETLE || CC == ISD::SETUGE)) ||
(CRHS->isNullValue() && (CRHS->isZero() &&
(CC == ISD::SETNE || CC == ISD::SETUGT || CC == ISD::SETLT))) (CC == ISD::SETNE || CC == ISD::SETUGT || CC == ISD::SETLT)))
return LHS.getOperand(0); return LHS.getOperand(0);
} }

View File

@ -1125,7 +1125,7 @@ bool ARMDAGToDAGISel::SelectThumbAddrModeRRSext(SDValue N, SDValue &Base,
SDValue &Offset) { SDValue &Offset) {
if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) { if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N); ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
if (!NC || !NC->isNullValue()) if (!NC || !NC->isZero())
return false; return false;
Base = Offset = N; Base = Offset = N;
@ -3556,7 +3556,7 @@ void ARMDAGToDAGISel::SelectCMPZ(SDNode *N, bool &SwitchEQNEToPLMI) {
return; return;
SDValue Zero = N->getOperand(1); SDValue Zero = N->getOperand(1);
if (!isa<ConstantSDNode>(Zero) || !cast<ConstantSDNode>(Zero)->isNullValue() || if (!isa<ConstantSDNode>(Zero) || !cast<ConstantSDNode>(Zero)->isZero() ||
And->getOpcode() != ISD::AND) And->getOpcode() != ISD::AND)
return; return;
SDValue X = And.getOperand(0); SDValue X = And.getOperand(0);

View File

@ -9139,7 +9139,7 @@ static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG,
Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) Hi1->getSExtValue() == Lo1->getSExtValue() >> 32)
return true; return true;
} else { } else {
if (Hi0->isNullValue() && Hi1->isNullValue()) if (Hi0->isZero() && Hi1->isZero())
return true; return true;
} }
return false; return false;
@ -17261,7 +17261,7 @@ static SDValue SearchLoopIntrinsic(SDValue N, ISD::CondCode &CC, int &Imm,
auto *Const = dyn_cast<ConstantSDNode>(N.getOperand(1)); auto *Const = dyn_cast<ConstantSDNode>(N.getOperand(1));
if (!Const) if (!Const)
return SDValue(); return SDValue();
if (Const->isNullValue()) if (Const->isZero())
Imm = 0; Imm = 0;
else if (Const->isOne()) else if (Const->isOne())
Imm = 1; Imm = 1;
@ -17313,7 +17313,7 @@ static SDValue PerformHWLoopCombine(SDNode *N,
Cond = N->getOperand(2); Cond = N->getOperand(2);
Dest = N->getOperand(4); Dest = N->getOperand(4);
if (auto *Const = dyn_cast<ConstantSDNode>(N->getOperand(3))) { if (auto *Const = dyn_cast<ConstantSDNode>(N->getOperand(3))) {
if (!Const->isOne() && !Const->isNullValue()) if (!Const->isOne() && !Const->isZero())
return SDValue(); return SDValue();
Imm = Const->getZExtValue(); Imm = Const->getZExtValue();
} else } else

View File

@ -990,7 +990,7 @@ void HexagonDAGToDAGISel::ppSimplifyOrSelect0(std::vector<SDNode*> &&Nodes) {
auto IsZero = [] (const SDValue &V) -> bool { auto IsZero = [] (const SDValue &V) -> bool {
if (ConstantSDNode *SC = dyn_cast<ConstantSDNode>(V.getNode())) if (ConstantSDNode *SC = dyn_cast<ConstantSDNode>(V.getNode()))
return SC->isNullValue(); return SC->isZero();
return false; return false;
}; };
auto IsSelect0 = [IsZero] (const SDValue &Op) -> bool { auto IsSelect0 = [IsZero] (const SDValue &Op) -> bool {

View File

@ -2556,7 +2556,7 @@ HexagonTargetLowering::extractVector(SDValue VecV, SDValue IdxV,
// Extracting the lowest bit is a no-op, but it changes the type, // Extracting the lowest bit is a no-op, but it changes the type,
// so it must be kept as an operation to avoid errors related to // so it must be kept as an operation to avoid errors related to
// type mismatches. // type mismatches.
if (IdxN->isNullValue() && ValTy.getSizeInBits() == 1) if (IdxN->isZero() && ValTy.getSizeInBits() == 1)
return DAG.getNode(HexagonISD::TYPECAST, dl, MVT::i1, VecV); return DAG.getNode(HexagonISD::TYPECAST, dl, MVT::i1, VecV);
} }

View File

@ -525,7 +525,7 @@ HexagonTargetLowering::buildHvxVectorReg(ArrayRef<SDValue> Values,
if (IsSplat) { if (IsSplat) {
assert(SplatV.getNode()); assert(SplatV.getNode());
auto *IdxN = dyn_cast<ConstantSDNode>(SplatV.getNode()); auto *IdxN = dyn_cast<ConstantSDNode>(SplatV.getNode());
if (IdxN && IdxN->isNullValue()) if (IdxN && IdxN->isZero())
return getZero(dl, VecTy, DAG); return getZero(dl, VecTy, DAG);
MVT WordTy = MVT::getVectorVT(MVT::i32, HwLen/4); MVT WordTy = MVT::getVectorVT(MVT::i32, HwLen/4);
SDValue S = DAG.getNode(ISD::SPLAT_VECTOR, dl, WordTy, SplatV); SDValue S = DAG.getNode(ISD::SPLAT_VECTOR, dl, WordTy, SplatV);
@ -743,12 +743,12 @@ HexagonTargetLowering::buildHvxVectorPred(ArrayRef<SDValue> Values,
auto IsTrue = [] (SDValue V) { auto IsTrue = [] (SDValue V) {
if (const auto *N = dyn_cast<ConstantSDNode>(V.getNode())) if (const auto *N = dyn_cast<ConstantSDNode>(V.getNode()))
return !N->isNullValue(); return !N->isZero();
return false; return false;
}; };
auto IsFalse = [] (SDValue V) { auto IsFalse = [] (SDValue V) {
if (const auto *N = dyn_cast<ConstantSDNode>(V.getNode())) if (const auto *N = dyn_cast<ConstantSDNode>(V.getNode()))
return N->isNullValue(); return N->isZero();
return false; return false;
}; };
@ -1065,7 +1065,7 @@ HexagonTargetLowering::insertHvxSubvectorReg(SDValue VecV, SDValue SubV,
assert(SubTy.getSizeInBits() == 32 || SubTy.getSizeInBits() == 64); assert(SubTy.getSizeInBits() == 32 || SubTy.getSizeInBits() == 64);
// Convert IdxV to be index in bytes. // Convert IdxV to be index in bytes.
auto *IdxN = dyn_cast<ConstantSDNode>(IdxV.getNode()); auto *IdxN = dyn_cast<ConstantSDNode>(IdxV.getNode());
if (!IdxN || !IdxN->isNullValue()) { if (!IdxN || !IdxN->isZero()) {
IdxV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, IdxV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV,
DAG.getConstant(ElemWidth/8, dl, MVT::i32)); DAG.getConstant(ElemWidth/8, dl, MVT::i32));
SingleV = DAG.getNode(HexagonISD::VROR, dl, SingleTy, SingleV, IdxV); SingleV = DAG.getNode(HexagonISD::VROR, dl, SingleTy, SingleV, IdxV);
@ -1088,7 +1088,7 @@ HexagonTargetLowering::insertHvxSubvectorReg(SDValue VecV, SDValue SubV,
RolBase = HwLen-4; RolBase = HwLen-4;
} }
// If the vector wasn't ror'ed, don't ror it back. // If the vector wasn't ror'ed, don't ror it back.
if (RolBase != 4 || !IdxN || !IdxN->isNullValue()) { if (RolBase != 4 || !IdxN || !IdxN->isZero()) {
SDValue RolV = DAG.getNode(ISD::SUB, dl, MVT::i32, SDValue RolV = DAG.getNode(ISD::SUB, dl, MVT::i32,
DAG.getConstant(RolBase, dl, MVT::i32), IdxV); DAG.getConstant(RolBase, dl, MVT::i32), IdxV);
SingleV = DAG.getNode(HexagonISD::VROR, dl, SingleTy, SingleV, RolV); SingleV = DAG.getNode(HexagonISD::VROR, dl, SingleTy, SingleV, RolV);
@ -1125,7 +1125,7 @@ HexagonTargetLowering::insertHvxSubvectorPred(SDValue VecV, SDValue SubV,
SDValue ByteIdx; SDValue ByteIdx;
auto *IdxN = dyn_cast<ConstantSDNode>(IdxV.getNode()); auto *IdxN = dyn_cast<ConstantSDNode>(IdxV.getNode());
if (!IdxN || !IdxN->isNullValue()) { if (!IdxN || !IdxN->isZero()) {
ByteIdx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, ByteIdx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV,
DAG.getConstant(BitBytes, dl, MVT::i32)); DAG.getConstant(BitBytes, dl, MVT::i32));
ByteVec = DAG.getNode(HexagonISD::VROR, dl, ByteTy, ByteVec, ByteIdx); ByteVec = DAG.getNode(HexagonISD::VROR, dl, ByteTy, ByteVec, ByteIdx);
@ -1140,7 +1140,7 @@ HexagonTargetLowering::insertHvxSubvectorPred(SDValue VecV, SDValue SubV,
{DAG.getConstant(BlockLen, dl, MVT::i32)}, DAG); {DAG.getConstant(BlockLen, dl, MVT::i32)}, DAG);
ByteVec = getInstr(Hexagon::V6_vmux, dl, ByteTy, {Q, ByteSub, ByteVec}, DAG); ByteVec = getInstr(Hexagon::V6_vmux, dl, ByteTy, {Q, ByteSub, ByteVec}, DAG);
// Rotate ByteVec back, and convert to a vector predicate. // Rotate ByteVec back, and convert to a vector predicate.
if (!IdxN || !IdxN->isNullValue()) { if (!IdxN || !IdxN->isZero()) {
SDValue HwLenV = DAG.getConstant(HwLen, dl, MVT::i32); SDValue HwLenV = DAG.getConstant(HwLen, dl, MVT::i32);
SDValue ByteXdi = DAG.getNode(ISD::SUB, dl, MVT::i32, HwLenV, ByteIdx); SDValue ByteXdi = DAG.getNode(ISD::SUB, dl, MVT::i32, HwLenV, ByteIdx);
ByteVec = DAG.getNode(HexagonISD::VROR, dl, ByteTy, ByteVec, ByteXdi); ByteVec = DAG.getNode(HexagonISD::VROR, dl, ByteTy, ByteVec, ByteXdi);
@ -2255,7 +2255,7 @@ HexagonTargetLowering::PerformHvxDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
case HexagonISD::V2Q: case HexagonISD::V2Q:
if (Ops[0].getOpcode() == ISD::SPLAT_VECTOR) { if (Ops[0].getOpcode() == ISD::SPLAT_VECTOR) {
if (const auto *C = dyn_cast<ConstantSDNode>(Ops[0].getOperand(0))) if (const auto *C = dyn_cast<ConstantSDNode>(Ops[0].getOperand(0)))
return C->isNullValue() ? DAG.getNode(HexagonISD::QFALSE, dl, ty(Op)) return C->isZero() ? DAG.getNode(HexagonISD::QFALSE, dl, ty(Op))
: DAG.getNode(HexagonISD::QTRUE, dl, ty(Op)); : DAG.getNode(HexagonISD::QTRUE, dl, ty(Op));
} }
break; break;

View File

@ -287,14 +287,14 @@ void LanaiDAGToDAGISel::Select(SDNode *Node) {
ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node); ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
// Materialize zero constants as copies from R0. This allows the coalescer // Materialize zero constants as copies from R0. This allows the coalescer
// to propagate these into other instructions. // to propagate these into other instructions.
if (ConstNode->isNullValue()) { if (ConstNode->isZero()) {
SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
SDLoc(Node), Lanai::R0, MVT::i32); SDLoc(Node), Lanai::R0, MVT::i32);
return ReplaceNode(Node, New.getNode()); return ReplaceNode(Node, New.getNode());
} }
// Materialize all ones constants as copies from R1. This allows the // Materialize all ones constants as copies from R1. This allows the
// coalescer to propagate these into other instructions. // coalescer to propagate these into other instructions.
if (ConstNode->isAllOnesValue()) { if (ConstNode->isAllOnes()) {
SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
SDLoc(Node), Lanai::R1, MVT::i32); SDLoc(Node), Lanai::R1, MVT::i32);
return ReplaceNode(Node, New.getNode()); return ReplaceNode(Node, New.getNode());

View File

@ -1150,7 +1150,7 @@ SDValue MSP430TargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
// lowering & isel wouldn't diverge. // lowering & isel wouldn't diverge.
bool andCC = false; bool andCC = false;
if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) { if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
if (RHSC->isNullValue() && LHS.hasOneUse() && if (RHSC->isZero() && LHS.hasOneUse() &&
(LHS.getOpcode() == ISD::AND || (LHS.getOpcode() == ISD::AND ||
(LHS.getOpcode() == ISD::TRUNCATE && (LHS.getOpcode() == ISD::TRUNCATE &&
LHS.getOperand(0).getOpcode() == ISD::AND))) { LHS.getOperand(0).getOpcode() == ISD::AND))) {

View File

@ -3186,7 +3186,7 @@ IntegerCompareEliminator::get32BitZExtCompare(SDValue LHS, SDValue RHS,
// by swapping inputs and falling through. // by swapping inputs and falling through.
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
case ISD::SETLE: { case ISD::SETLE: {
@ -3236,7 +3236,7 @@ IntegerCompareEliminator::get32BitZExtCompare(SDValue LHS, SDValue RHS,
// (%b < %a) by swapping inputs and falling through. // (%b < %a) by swapping inputs and falling through.
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1; IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1;
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
@ -3370,7 +3370,7 @@ IntegerCompareEliminator::get32BitSExtCompare(SDValue LHS, SDValue RHS,
// by swapping inputs and falling through. // by swapping inputs and falling through.
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
case ISD::SETLE: { case ISD::SETLE: {
@ -3415,7 +3415,7 @@ IntegerCompareEliminator::get32BitSExtCompare(SDValue LHS, SDValue RHS,
// (%b < %a) by swapping inputs and falling through. // (%b < %a) by swapping inputs and falling through.
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1; IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1;
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
@ -3528,7 +3528,7 @@ IntegerCompareEliminator::get64BitZExtCompare(SDValue LHS, SDValue RHS,
return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt); return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
case ISD::SETLE: { case ISD::SETLE: {
@ -3570,7 +3570,7 @@ IntegerCompareEliminator::get64BitZExtCompare(SDValue LHS, SDValue RHS,
} }
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1; IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1;
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
@ -3687,7 +3687,7 @@ IntegerCompareEliminator::get64BitSExtCompare(SDValue LHS, SDValue RHS,
return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt); return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
case ISD::SETLE: { case ISD::SETLE: {
@ -3730,7 +3730,7 @@ IntegerCompareEliminator::get64BitSExtCompare(SDValue LHS, SDValue RHS,
} }
std::swap(LHS, RHS); std::swap(LHS, RHS);
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS); ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
IsRHSZero = RHSConst && RHSConst->isNullValue(); IsRHSZero = RHSConst && RHSConst->isZero();
IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1; IsRHSOne = RHSConst && RHSConst->getSExtValue() == 1;
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
} }
@ -5423,8 +5423,8 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N->getOperand(1))) if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N->getOperand(1)))
if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N->getOperand(2))) if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N->getOperand(2)))
if (ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N->getOperand(3))) if (ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N->getOperand(3)))
if (N1C->isNullValue() && N3C->isNullValue() && if (N1C->isZero() && N3C->isZero() && N2C->getZExtValue() == 1ULL &&
N2C->getZExtValue() == 1ULL && CC == ISD::SETNE && CC == ISD::SETNE &&
// FIXME: Implement this optzn for PPC64. // FIXME: Implement this optzn for PPC64.
N->getValueType(0) == MVT::i32) { N->getValueType(0) == MVT::i32) {
SDNode *Tmp = SDNode *Tmp =
@ -6180,7 +6180,7 @@ bool PPCDAGToDAGISel::AllUsersSelectZero(SDNode *N) {
if (!C) if (!C)
return false; return false;
if (!C->isNullValue()) if (!C->isZero())
return false; return false;
} }

View File

@ -3509,7 +3509,7 @@ SDValue PPCTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
// Leave comparisons against 0 and -1 alone for now, since they're usually // Leave comparisons against 0 and -1 alone for now, since they're usually
// optimized. FIXME: revisit this when we can custom lower all setcc // optimized. FIXME: revisit this when we can custom lower all setcc
// optimizations. // optimizations.
if (C->isAllOnesValue() || C->isNullValue()) if (C->isAllOnes() || C->isZero())
return SDValue(); return SDValue();
} }
@ -14853,8 +14853,8 @@ SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N,
break; break;
case PPCISD::SRA: case PPCISD::SRA:
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(0))) { if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(0))) {
if (C->isNullValue() || // 0 >>s V -> 0. if (C->isZero() || // 0 >>s V -> 0.
C->isAllOnesValue()) // -1 >>s V -> -1. C->isAllOnes()) // -1 >>s V -> -1.
return N->getOperand(0); return N->getOperand(0);
} }
break; break;

View File

@ -467,7 +467,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
switch (Opcode) { switch (Opcode) {
case ISD::Constant: { case ISD::Constant: {
auto *ConstNode = cast<ConstantSDNode>(Node); auto *ConstNode = cast<ConstantSDNode>(Node);
if (VT == XLenVT && ConstNode->isNullValue()) { if (VT == XLenVT && ConstNode->isZero()) {
SDValue New = SDValue New =
CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, RISCV::X0, XLenVT); CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, RISCV::X0, XLenVT);
ReplaceNode(Node, New.getNode()); ReplaceNode(Node, New.getNode());

View File

@ -5239,16 +5239,16 @@ static X86::CondCode TranslateX86CC(ISD::CondCode SetCCOpcode, const SDLoc &DL,
SelectionDAG &DAG) { SelectionDAG &DAG) {
if (!isFP) { if (!isFP) {
if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) { if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
if (SetCCOpcode == ISD::SETGT && RHSC->isAllOnesValue()) { if (SetCCOpcode == ISD::SETGT && RHSC->isAllOnes()) {
// X > -1 -> X == 0, jump !sign. // X > -1 -> X == 0, jump !sign.
RHS = DAG.getConstant(0, DL, RHS.getValueType()); RHS = DAG.getConstant(0, DL, RHS.getValueType());
return X86::COND_NS; return X86::COND_NS;
} }
if (SetCCOpcode == ISD::SETLT && RHSC->isNullValue()) { if (SetCCOpcode == ISD::SETLT && RHSC->isZero()) {
// X < 0 -> X == 0, jump on sign. // X < 0 -> X == 0, jump on sign.
return X86::COND_S; return X86::COND_S;
} }
if (SetCCOpcode == ISD::SETGE && RHSC->isNullValue()) { if (SetCCOpcode == ISD::SETGE && RHSC->isZero()) {
// X >= 0 -> X == 0, jump on !sign. // X >= 0 -> X == 0, jump on !sign.
return X86::COND_NS; return X86::COND_NS;
} }
@ -41038,9 +41038,9 @@ static SDValue combineBitcast(SDNode *N, SelectionDAG &DAG,
VT.isVector() && VT.getVectorElementType() == MVT::i1 && VT.isVector() && VT.getVectorElementType() == MVT::i1 &&
isa<ConstantSDNode>(N0)) { isa<ConstantSDNode>(N0)) {
auto *C = cast<ConstantSDNode>(N0); auto *C = cast<ConstantSDNode>(N0);
if (C->isAllOnesValue()) if (C->isAllOnes())
return DAG.getConstant(1, SDLoc(N0), VT); return DAG.getConstant(1, SDLoc(N0), VT);
if (C->isNullValue()) if (C->isZero())
return DAG.getConstant(0, SDLoc(N0), VT); return DAG.getConstant(0, SDLoc(N0), VT);
} }
@ -42267,7 +42267,7 @@ static SDValue combineSelectOfTwoConstants(SDNode *N, SelectionDAG &DAG) {
R = DAG.getNode(ISD::MUL, DL, VT, R, DAG.getConstant(AbsDiff, DL, VT)); R = DAG.getNode(ISD::MUL, DL, VT, R, DAG.getConstant(AbsDiff, DL, VT));
// Add the base if non-zero. // Add the base if non-zero.
if (!FalseC->isNullValue()) if (!FalseC->isZero())
R = DAG.getNode(ISD::ADD, DL, VT, R, SDValue(FalseC, 0)); R = DAG.getNode(ISD::ADD, DL, VT, R, SDValue(FalseC, 0));
return R; return R;
@ -50409,8 +50409,8 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
// the general case below. // the general case below.
auto *ConstantX = dyn_cast<ConstantSDNode>(X); auto *ConstantX = dyn_cast<ConstantSDNode>(X);
if (ConstantX) { if (ConstantX) {
if ((!IsSub && CC == X86::COND_AE && ConstantX->isAllOnesValue()) || if ((!IsSub && CC == X86::COND_AE && ConstantX->isAllOnes()) ||
(IsSub && CC == X86::COND_B && ConstantX->isNullValue())) { (IsSub && CC == X86::COND_B && ConstantX->isZero())) {
// This is a complicated way to get -1 or 0 from the carry flag: // This is a complicated way to get -1 or 0 from the carry flag:
// -1 + SETAE --> -1 + (!CF) --> CF ? -1 : 0 --> SBB %eax, %eax // -1 + SETAE --> -1 + (!CF) --> CF ? -1 : 0 --> SBB %eax, %eax
// 0 - SETB --> 0 - (CF) --> CF ? -1 : 0 --> SBB %eax, %eax // 0 - SETB --> 0 - (CF) --> CF ? -1 : 0 --> SBB %eax, %eax
@ -50419,8 +50419,8 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
Y.getOperand(1)); Y.getOperand(1));
} }
if ((!IsSub && CC == X86::COND_BE && ConstantX->isAllOnesValue()) || if ((!IsSub && CC == X86::COND_BE && ConstantX->isAllOnes()) ||
(IsSub && CC == X86::COND_A && ConstantX->isNullValue())) { (IsSub && CC == X86::COND_A && ConstantX->isZero())) {
SDValue EFLAGS = Y->getOperand(1); SDValue EFLAGS = Y->getOperand(1);
if (EFLAGS.getOpcode() == X86ISD::SUB && EFLAGS.hasOneUse() && if (EFLAGS.getOpcode() == X86ISD::SUB && EFLAGS.hasOneUse() &&
EFLAGS.getValueType().isInteger() && EFLAGS.getValueType().isInteger() &&
@ -50518,8 +50518,8 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
// fake operands: // fake operands:
// 0 - (Z != 0) --> sbb %eax, %eax, (neg Z) // 0 - (Z != 0) --> sbb %eax, %eax, (neg Z)
// -1 + (Z == 0) --> sbb %eax, %eax, (neg Z) // -1 + (Z == 0) --> sbb %eax, %eax, (neg Z)
if ((IsSub && CC == X86::COND_NE && ConstantX->isNullValue()) || if ((IsSub && CC == X86::COND_NE && ConstantX->isZero()) ||
(!IsSub && CC == X86::COND_E && ConstantX->isAllOnesValue())) { (!IsSub && CC == X86::COND_E && ConstantX->isAllOnes())) {
SDValue Zero = DAG.getConstant(0, DL, ZVT); SDValue Zero = DAG.getConstant(0, DL, ZVT);
SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32); SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32);
SDValue Neg = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Zero, Z); SDValue Neg = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Zero, Z);
@ -50532,8 +50532,8 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
// with fake operands: // with fake operands:
// 0 - (Z == 0) --> sbb %eax, %eax, (cmp Z, 1) // 0 - (Z == 0) --> sbb %eax, %eax, (cmp Z, 1)
// -1 + (Z != 0) --> sbb %eax, %eax, (cmp Z, 1) // -1 + (Z != 0) --> sbb %eax, %eax, (cmp Z, 1)
if ((IsSub && CC == X86::COND_E && ConstantX->isNullValue()) || if ((IsSub && CC == X86::COND_E && ConstantX->isZero()) ||
(!IsSub && CC == X86::COND_NE && ConstantX->isAllOnesValue())) { (!IsSub && CC == X86::COND_NE && ConstantX->isAllOnes())) {
SDValue One = DAG.getConstant(1, DL, ZVT); SDValue One = DAG.getConstant(1, DL, ZVT);
SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32); SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32);
SDValue Cmp1 = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Z, One); SDValue Cmp1 = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Z, One);
@ -51681,7 +51681,7 @@ static SDValue combineScalarToVector(SDNode *N, SelectionDAG &DAG) {
Src.hasOneUse() && Src.getOperand(0).getValueType().isVector() && Src.hasOneUse() && Src.getOperand(0).getValueType().isVector() &&
Src.getOperand(0).getValueType().getVectorElementType() == MVT::i1) Src.getOperand(0).getValueType().getVectorElementType() == MVT::i1)
if (auto *C = dyn_cast<ConstantSDNode>(Src.getOperand(1))) if (auto *C = dyn_cast<ConstantSDNode>(Src.getOperand(1)))
if (C->isNullValue()) if (C->isZero())
return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src.getOperand(0), return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Src.getOperand(0),
Src.getOperand(1)); Src.getOperand(1));

View File

@ -71,7 +71,8 @@ SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset(
// Check to see if there is a specialized entry-point for memory zeroing. // Check to see if there is a specialized entry-point for memory zeroing.
ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val); ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val);
if (const char *bzeroName = (ValC && ValC->isNullValue()) if (const char *bzeroName =
(ValC && ValC->isZero())
? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO) ? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO)
: nullptr) { : nullptr) {
const TargetLowering &TLI = DAG.getTargetLoweringInfo(); const TargetLowering &TLI = DAG.getTargetLoweringInfo();

View File

@ -1643,7 +1643,7 @@ SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
return DAG.getNode(XCoreISD::LADD, dl, DAG.getVTList(VT, VT), N1, N0, N2); return DAG.getNode(XCoreISD::LADD, dl, DAG.getVTList(VT, VT), N1, N0, N2);
// fold (ladd 0, 0, x) -> 0, x & 1 // fold (ladd 0, 0, x) -> 0, x & 1
if (N0C && N0C->isNullValue() && N1C && N1C->isNullValue()) { if (N0C && N0C->isZero() && N1C && N1C->isZero()) {
SDValue Carry = DAG.getConstant(0, dl, VT); SDValue Carry = DAG.getConstant(0, dl, VT);
SDValue Result = DAG.getNode(ISD::AND, dl, VT, N2, SDValue Result = DAG.getNode(ISD::AND, dl, VT, N2,
DAG.getConstant(1, dl, VT)); DAG.getConstant(1, dl, VT));
@ -1653,7 +1653,7 @@ SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
// fold (ladd x, 0, y) -> 0, add x, y iff carry is unused and y has only the // fold (ladd x, 0, y) -> 0, add x, y iff carry is unused and y has only the
// low bit set // low bit set
if (N1C && N1C->isNullValue() && N->hasNUsesOfValue(0, 1)) { if (N1C && N1C->isZero() && N->hasNUsesOfValue(0, 1)) {
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(), APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
VT.getSizeInBits() - 1); VT.getSizeInBits() - 1);
KnownBits Known = DAG.computeKnownBits(N2); KnownBits Known = DAG.computeKnownBits(N2);
@ -1675,7 +1675,7 @@ SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
EVT VT = N0.getValueType(); EVT VT = N0.getValueType();
// fold (lsub 0, 0, x) -> x, -x iff x has only the low bit set // fold (lsub 0, 0, x) -> x, -x iff x has only the low bit set
if (N0C && N0C->isNullValue() && N1C && N1C->isNullValue()) { if (N0C && N0C->isZero() && N1C && N1C->isZero()) {
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(), APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
VT.getSizeInBits() - 1); VT.getSizeInBits() - 1);
KnownBits Known = DAG.computeKnownBits(N2); KnownBits Known = DAG.computeKnownBits(N2);
@ -1690,7 +1690,7 @@ SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
// fold (lsub x, 0, y) -> 0, sub x, y iff borrow is unused and y has only the // fold (lsub x, 0, y) -> 0, sub x, y iff borrow is unused and y has only the
// low bit set // low bit set
if (N1C && N1C->isNullValue() && N->hasNUsesOfValue(0, 1)) { if (N1C && N1C->isZero() && N->hasNUsesOfValue(0, 1)) {
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(), APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
VT.getSizeInBits() - 1); VT.getSizeInBits() - 1);
KnownBits Known = DAG.computeKnownBits(N2); KnownBits Known = DAG.computeKnownBits(N2);
@ -1719,7 +1719,7 @@ SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
N1, N0, N2, N3); N1, N0, N2, N3);
// lmul(x, 0, a, b) // lmul(x, 0, a, b)
if (N1C && N1C->isNullValue()) { if (N1C && N1C->isZero()) {
// If the high result is unused fold to add(a, b) // If the high result is unused fold to add(a, b)
if (N->hasNUsesOfValue(0, 0)) { if (N->hasNUsesOfValue(0, 0)) {
SDValue Lo = DAG.getNode(ISD::ADD, dl, VT, N2, N3); SDValue Lo = DAG.getNode(ISD::ADD, dl, VT, N2, N3);