Skip to content

Commit

Permalink
[CodeGen] Use DAG.getAllOnesConstant where possible to simplify code.…
Browse files Browse the repository at this point in the history
… NFC.
  • Loading branch information
lattner committed Sep 9, 2021
1 parent 124bcc1 commit d51da74
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
5 changes: 2 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Expand Up @@ -3240,9 +3240,8 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
assert(TLI.isOperationLegalOrCustom(ISD::ADD, VT) &&
TLI.isOperationLegalOrCustom(ISD::XOR, VT) &&
"Don't know how to expand this subtraction!");
Tmp1 = DAG.getNode(
ISD::XOR, dl, VT, Node->getOperand(1),
DAG.getConstant(APInt::getAllOnes(VT.getSizeInBits()), dl, VT));
Tmp1 = DAG.getNode(ISD::XOR, dl, VT, Node->getOperand(1),
DAG.getAllOnesConstant(dl, VT));
Tmp1 = DAG.getNode(ISD::ADD, dl, VT, Tmp1, DAG.getConstant(1, dl, VT));
Results.push_back(DAG.getNode(ISD::ADD, dl, VT, Node->getOperand(0), Tmp1));
break;
Expand Down
25 changes: 9 additions & 16 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
Expand Up @@ -943,10 +943,8 @@ SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
// What is the size of each element in the vector mask.
EVT BitTy = MaskTy.getScalarType();

Mask = DAG.getSelect(
DL, BitTy, Mask,
DAG.getConstant(APInt::getAllOnes(BitTy.getSizeInBits()), DL, BitTy),
DAG.getConstant(0, DL, BitTy));
Mask = DAG.getSelect(DL, BitTy, Mask, DAG.getAllOnesConstant(DL, BitTy),
DAG.getConstant(0, DL, BitTy));

// Broadcast the mask so that the entire vector is all one or all zero.
if (VT.isFixedLengthVector())
Expand All @@ -960,8 +958,7 @@ SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);

SDValue AllOnes =
DAG.getConstant(APInt::getAllOnes(BitTy.getSizeInBits()), DL, MaskTy);
SDValue AllOnes = DAG.getAllOnesConstant(DL, MaskTy);
SDValue NotMask = DAG.getNode(ISD::XOR, DL, MaskTy, Mask, AllOnes);

Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
Expand Down Expand Up @@ -1207,8 +1204,7 @@ SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);

SDValue AllOnes =
DAG.getConstant(APInt::getAllOnes(VT.getScalarSizeInBits()), DL, VT);
SDValue AllOnes = DAG.getAllOnesConstant(DL, VT);
SDValue NotMask = DAG.getNode(ISD::XOR, DL, VT, Mask, AllOnes);

Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
Expand Down Expand Up @@ -1501,10 +1497,9 @@ void VectorLegalizer::UnrollStrictFPOp(SDNode *Node,

if (Node->getOpcode() == ISD::STRICT_FSETCC ||
Node->getOpcode() == ISD::STRICT_FSETCCS)
ScalarResult = DAG.getSelect(
dl, EltVT, ScalarResult,
DAG.getConstant(APInt::getAllOnes(EltVT.getSizeInBits()), dl, EltVT),
DAG.getConstant(0, dl, EltVT));
ScalarResult = DAG.getSelect(dl, EltVT, ScalarResult,
DAG.getAllOnesConstant(dl, EltVT),
DAG.getConstant(0, dl, EltVT));

OpValues.push_back(ScalarResult);
OpChains.push_back(ScalarChain);
Expand Down Expand Up @@ -1536,10 +1531,8 @@ SDValue VectorLegalizer::UnrollVSETCC(SDNode *Node) {
TLI.getSetCCResultType(DAG.getDataLayout(),
*DAG.getContext(), TmpEltVT),
LHSElem, RHSElem, CC);
Ops[i] = DAG.getSelect(
dl, EltVT, Ops[i],
DAG.getConstant(APInt::getAllOnes(EltVT.getSizeInBits()), dl, EltVT),
DAG.getConstant(0, dl, EltVT));
Ops[i] = DAG.getSelect(dl, EltVT, Ops[i], DAG.getAllOnesConstant(dl, EltVT),
DAG.getConstant(0, dl, EltVT));
}
return DAG.getBuildVector(VT, dl, Ops);
}
Expand Down
5 changes: 1 addition & 4 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -1347,10 +1347,7 @@ SDValue SelectionDAG::getPtrExtendInReg(SDValue Op, const SDLoc &DL, EVT VT) {

/// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
SDValue SelectionDAG::getNOT(const SDLoc &DL, SDValue Val, EVT VT) {
EVT EltVT = VT.getScalarType();
SDValue NegOne =
getConstant(APInt::getAllOnes(EltVT.getSizeInBits()), DL, VT);
return getNode(ISD::XOR, DL, VT, Val, NegOne);
return getNode(ISD::XOR, DL, VT, Val, getAllOnesConstant(DL, VT));
}

SDValue SelectionDAG::getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/ARM/ARMISelLowering.cpp
Expand Up @@ -12182,7 +12182,7 @@ static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes,
// When looking for a 0 constant, N can be zext or sext.
OtherOp = DAG.getConstant(1, dl, VT);
else
OtherOp = DAG.getConstant(APInt::getAllOnes(VT.getSizeInBits()), dl, VT);
OtherOp = DAG.getAllOnesConstant(dl, VT);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Lanai/LanaiISelLowering.cpp
Expand Up @@ -1400,7 +1400,7 @@ static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, SDValue &CC,
// value is 0.
OtherOp = DAG.getConstant(0, dl, VT);
else
OtherOp = DAG.getConstant(APInt::getAllOnes(VT.getSizeInBits()), dl, VT);
OtherOp = DAG.getAllOnesConstant(dl, VT);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86ISelLowering.cpp
Expand Up @@ -41235,7 +41235,7 @@ static SDValue combineMinMaxReduction(SDNode *Extract, SelectionDAG &DAG,
else if (BinOp == ISD::SMIN)
Mask = DAG.getConstant(APInt::getSignedMinValue(MaskEltsBits), DL, SrcVT);
else if (BinOp == ISD::UMAX)
Mask = DAG.getConstant(APInt::getAllOnes(MaskEltsBits), DL, SrcVT);
Mask = DAG.getAllOnesConstant(DL, SrcVT);

if (Mask)
MinPos = DAG.getNode(ISD::XOR, DL, SrcVT, Mask, MinPos);
Expand Down

0 comments on commit d51da74

Please sign in to comment.