78 #define DEBUG_TYPE "dagcombine" 80 STATISTIC(NodesCombined ,
"Number of dag nodes combined");
81 STATISTIC(PreIndexedNodes ,
"Number of pre-indexed nodes created");
82 STATISTIC(PostIndexedNodes,
"Number of post-indexed nodes created");
83 STATISTIC(OpsNarrowed ,
"Number of load/op/store narrowed");
84 STATISTIC(LdStFP2Int ,
"Number of fp load/store pairs transformed to int");
85 STATISTIC(SlicedLoads,
"Number of load sliced");
89 cl::desc(
"Enable DAG combiner's use of IR alias analysis"));
93 cl::desc(
"Enable DAG combiner's use of TBAA"));
98 cl::desc(
"Only use DAG-combiner alias analysis in this" 106 cl::desc(
"Bypass the profitability model of load slicing"),
111 cl::desc(
"DAG combiner may split indexing from loads"));
120 bool LegalOperations =
false;
121 bool LegalTypes =
false;
151 void AddUsersToWorklist(
SDNode *
N) {
162 OptLevel(OL), AA(AA) {
165 MaximumLegalStoreInBits = 0;
169 VT.getSizeInBits() >= MaximumLegalStoreInBits)
170 MaximumLegalStoreInBits = VT.getSizeInBits();
175 void AddToWorklist(
SDNode *N) {
177 "Deleted Node added to Worklist");
184 if (WorklistMap.
insert(std::make_pair(N, Worklist.
size())).second)
189 void removeFromWorklist(
SDNode *N) {
190 CombinedNodes.
erase(N);
192 auto It = WorklistMap.
find(N);
193 if (It == WorklistMap.
end())
197 Worklist[It->second] =
nullptr;
198 WorklistMap.
erase(It);
201 void deleteAndRecombine(
SDNode *N);
202 bool recursivelyDeleteUnusedNodes(
SDNode *N);
210 return CombineTo(N, &Res, 1, AddTo);
217 return CombineTo(N, To, 2, AddTo);
223 unsigned MaximumLegalStoreInBits;
231 return SimplifyDemandedBits(Op, Demanded);
237 bool SimplifyDemandedVectorElts(
SDValue Op) {
240 return SimplifyDemandedVectorElts(Op, Demanded);
243 bool SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded);
244 bool SimplifyDemandedVectorElts(
SDValue Op,
const APInt &Demanded,
245 bool AssumeSingleUse =
false);
247 bool CombineToPreIndexedLoadStore(
SDNode *N);
248 bool CombineToPostIndexedLoadStore(
SDNode *N);
250 bool SliceUpLoad(
SDNode *N);
260 SDValue ReplaceExtractVectorEltOfLoadWithNarrowedLoad(
408 bool NotExtCompare =
false);
416 const SDLoc &DL,
bool foldBooleans);
421 bool isOneUseSetCC(
SDValue N)
const;
429 SDValue combineInsertEltToShuffle(
SDNode *N,
unsigned InsIndex);
444 bool DemandHighBits =
true);
448 unsigned PosOpcode,
unsigned NegOpcode,
462 SDValue VecIn2,
unsigned LeftIdx);
492 int64_t OffsetFromBase;
495 : MemNode(N), OffsetFromBase(Offset) {}
502 bool isMulAddWithConstProfitable(
SDNode *MulNode,
510 EVT LoadResultTy,
EVT &ExtVT);
515 EVT &MemVT,
unsigned ShAmt = 0);
536 EVT MemVT,
unsigned NumStores,
537 bool IsConstantSrc,
bool UseVector,
553 bool checkMergeStoreCandidatesForDependencies(
575 bool hasOperation(
unsigned Opcode,
EVT VT) {
589 EVT getShiftAmountTy(
EVT LHSTy) {
596 bool isTypeLegal(
const EVT &VT) {
597 if (!LegalTypes)
return true;
602 EVT getSetCCResultType(
EVT VT)
const {
617 explicit WorklistRemover(DAGCombiner &dc)
618 :
SelectionDAG::DAGUpdateListener(dc.getDAG()), DC(dc) {}
621 DC.removeFromWorklist(N);
632 ((DAGCombiner*)
DC)->AddToWorklist(N);
637 return ((DAGCombiner*)
DC)->CombineTo(N, &To[0], To.
size(), AddTo);
642 return ((DAGCombiner*)
DC)->CombineTo(N, Res, AddTo);
647 return ((DAGCombiner*)
DC)->CombineTo(N, Res0, Res1, AddTo);
652 return ((DAGCombiner*)
DC)->CommitTargetLoweringOpt(TLO);
659 void DAGCombiner::deleteAndRecombine(
SDNode *N) {
660 removeFromWorklist(N);
680 unsigned Depth = 0) {
693 if (
Depth > 6)
return 0;
696 default:
return false;
698 if (!LegalOperations)
723 if (!Options->NoSignedZerosFPMath &&
750 bool LegalOperations,
unsigned Depth = 0) {
755 assert(
Depth <= 6 &&
"GetNegatedExpression doesn't match isNegatibleForFree");
762 APFloat V = cast<ConstantFPSDNode>(
Op)->getValueAPF();
774 LegalOperations,
Depth+1),
779 LegalOperations,
Depth+1),
798 LegalOperations,
Depth+1),
805 LegalOperations,
Depth+1), Flags);
811 LegalOperations,
Depth+1));
815 LegalOperations,
Depth+1),
861 bool DAGCombiner::isOneUseSetCC(
SDValue N)
const {
877 if (isa<ConstantFPSDNode>(N))
889 return !(Const->isOpaque() && NoOpaques);
910 return Splat->isNullValue();
921 return Splat->isOne() && Splat->getAPIntValue().getBitWidth() == BitWidth;
932 return Splat->isAllOnesValue() &&
933 Splat->getAPIntValue().getBitWidth() == BitWidth;
961 AddToWorklist(OpNode.
getNode());
981 AddToWorklist(OpNode.
getNode());
996 dbgs() <<
" and " << NumTo - 1 <<
" other values\n");
997 for (
unsigned i = 0, e = NumTo; i != e; ++i)
998 assert((!To[i].getNode() ||
1000 "Cannot combine value to value of different type!");
1002 WorklistRemover DeadNodes(*
this);
1006 for (
unsigned i = 0, e = NumTo; i != e; ++i) {
1007 if (To[i].getNode()) {
1008 AddToWorklist(To[i].getNode());
1009 AddUsersToWorklist(To[i].getNode());
1018 deleteAndRecombine(N);
1026 WorklistRemover DeadNodes(*
this);
1042 bool DAGCombiner::SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded) {
1057 CommitTargetLoweringOpt(TLO);
1064 bool DAGCombiner::SimplifyDemandedVectorElts(
SDValue Op,
const APInt &Demanded,
1065 bool AssumeSingleUse) {
1067 APInt KnownUndef, KnownZero;
1069 0, AssumeSingleUse))
1081 CommitTargetLoweringOpt(TLO);
1085 void DAGCombiner::ReplaceLoadWithPromotedLoad(
SDNode *
Load,
SDNode *ExtLoad) {
1092 WorklistRemover DeadNodes(*
this);
1095 deleteAndRecombine(Load);
1096 AddToWorklist(Trunc.
getNode());
1127 return DAG.
getNode(ExtOpc, DL, PVT, Op);
1141 bool Replace =
false;
1142 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
1145 AddToWorklist(NewOp.
getNode());
1156 bool Replace =
false;
1157 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
1160 AddToWorklist(NewOp.
getNode());
1171 if (!LegalOperations)
1188 assert(PVT != VT &&
"Don't know what type to promote to!");
1192 bool Replace0 =
false;
1194 SDValue NN0 = PromoteOperand(N0, PVT, Replace0);
1196 bool Replace1 =
false;
1198 SDValue NN1 = PromoteOperand(N1, PVT, Replace1);
1207 Replace1 &= (N0 != N1) && !N1->
hasOneUse();
1236 if (!LegalOperations)
1253 assert(PVT != VT &&
"Don't know what type to promote to!");
1257 bool Replace =
false;
1261 N0 = SExtPromoteOperand(N0, PVT);
1263 N0 = ZExtPromoteOperand(N0, PVT);
1265 N0 = PromoteOperand(N0, PVT, Replace);
1286 if (!LegalOperations)
1303 assert(PVT != VT &&
"Don't know what type to promote to!");
1313 bool DAGCombiner::PromoteLoad(
SDValue Op) {
1314 if (!LegalOperations)
1334 assert(PVT != VT &&
"Don't know what type to promote to!");
1349 WorklistRemover DeadNodes(*
this);
1352 deleteAndRecombine(N);
1353 AddToWorklist(Result.
getNode());
1365 bool DAGCombiner::recursivelyDeleteUnusedNodes(
SDNode *N) {
1378 Nodes.
insert(ChildN.getNode());
1380 removeFromWorklist(N);
1385 }
while (!Nodes.
empty());
1401 AddToWorklist(&Node);
1409 while (!WorklistMap.
empty()) {
1416 bool GoodWorklistEntry = WorklistMap.
erase(N);
1417 (void)GoodWorklistEntry;
1418 assert(GoodWorklistEntry &&
1419 "Found a worklist entry without a corresponding map entry!");
1424 if (recursivelyDeleteUnusedNodes(N))
1427 WorklistRemover DeadNodes(*
this);
1433 bool NIsValid = DAG.
LegalizeOp(N, UpdatedNodes);
1435 for (
SDNode *LN : UpdatedNodes) {
1437 AddUsersToWorklist(LN);
1450 if (!CombinedNodes.
count(ChildN.getNode()))
1451 AddToWorklist(ChildN.getNode());
1464 if (RV.getNode() ==
N)
1469 "Node was deleted but visit returned new node!");
1482 AddToWorklist(RV.getNode());
1483 AddUsersToWorklist(RV.getNode());
1489 recursivelyDeleteUnusedNodes(N);
1528 case ISD::OR:
return visitOR(N);
1609 "Node was deleted but visit returned NULL!");
1616 DagCombineInfo(DAG, Level,
false,
this);
1632 RV = PromoteIntBinOp(
SDValue(N, 0));
1637 RV = PromoteIntShiftOp(
SDValue(N, 0));
1642 RV = PromoteExtend(
SDValue(N, 0));
1645 if (PromoteLoad(
SDValue(N, 0)))
1659 if (N0 != N1 && (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1))) {
1679 for (
unsigned i = 1; i < NumOps-1; ++i)
1703 bool Changed =
false;
1710 for (
unsigned i = 0; i < TFs.
size(); ++i) {
1754 bool DidPruneOps =
false;
1756 unsigned NumLeftToConsider = 0;
1757 for (
const SDValue &Op : Ops) {
1762 auto AddToWorklist = [&](
unsigned CurIdx,
SDNode *
Op,
unsigned OpNumber) {
1765 if (SeenOps.
count(Op) != 0) {
1768 unsigned OrigOpNumber = 0;
1769 while (OrigOpNumber < Ops.size() && Ops[OrigOpNumber].getNode() !=
Op)
1771 assert((OrigOpNumber != Ops.size()) &&
1772 "expected to find TokenFactor Operand");
1774 for (
unsigned i = CurIdx + 1; i < Worklist.
size(); ++i) {
1775 if (Worklist[i].
second == OrigOpNumber) {
1776 Worklist[i].second = OpNumber;
1779 OpWorkCount[OpNumber] += OpWorkCount[OrigOpNumber];
1780 OpWorkCount[OrigOpNumber] = 0;
1781 NumLeftToConsider--;
1784 if (SeenChains.
insert(Op).second) {
1785 OpWorkCount[OpNumber]++;
1786 Worklist.
push_back(std::make_pair(Op, OpNumber));
1790 for (
unsigned i = 0; i < Worklist.
size() && i < 1024; ++i) {
1792 if (NumLeftToConsider <= 1)
1794 auto CurNode = Worklist[i].first;
1795 auto CurOpNumber = Worklist[i].second;
1796 assert((OpWorkCount[CurOpNumber] > 0) &&
1797 "Node should not appear in worklist");
1798 switch (CurNode->getOpcode()) {
1804 NumLeftToConsider++;
1808 AddToWorklist(i, Op.getNode(), CurOpNumber);
1812 AddToWorklist(i, CurNode->getOperand(0).getNode(), CurOpNumber);
1815 if (
auto *MemNode = dyn_cast<MemSDNode>(CurNode))
1816 AddToWorklist(i, MemNode->getChain().getNode(), CurOpNumber);
1819 OpWorkCount[CurOpNumber]--;
1820 if (OpWorkCount[CurOpNumber] == 0)
1821 NumLeftToConsider--;
1834 for (
const SDValue &Op : Ops) {
1835 if (SeenChains.
count(Op.getNode()) == 0)
1850 WorklistRemover DeadNodes(*
this);
1856 AddUsersToWorklist(N);
1861 deleteAndRecombine(N);
1869 return Const !=
nullptr && !Const->
isOpaque() ? Const :
nullptr;
1883 "Unexpected binary operator");
1888 unsigned SelOpNo = 0;
1913 bool CanFoldNonConst = (BinOpcode ==
ISD::AND || BinOpcode ==
ISD::OR) &&
1920 if (!CanFoldNonConst &&
1940 SDValue NewCT = SelOpNo ? DAG.
getNode(BinOpcode, DL, VT, CBO, CT)
1941 : DAG.
getNode(BinOpcode, DL, VT, CT, CBO);
1942 if (!CanFoldNonConst && !NewCT.
isUndef() &&
1947 SDValue NewCF = SelOpNo ? DAG.
getNode(BinOpcode, DL, VT, CBO, CF)
1948 : DAG.
getNode(BinOpcode, DL, VT, CF, CBO);
1949 if (!CanFoldNonConst && !NewCF.
isUndef() &&
1959 "Expecting add or sub");
2000 "Expecting add or sub");
2043 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2090 if ((!LegalOperations ||
2109 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2135 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
2136 N0 == N1.getOperand(1).getOperand(0))
2138 N1.getOperand(1).getOperand(1));
2141 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
2142 N0 == N1.getOperand(1).getOperand(1))
2144 N1.getOperand(1).getOperand(0));
2148 N1.getOperand(0).getOpcode() ==
ISD::SUB &&
2149 N0 == N1.getOperand(0).getOperand(1))
2150 return DAG.
getNode(N1.getOpcode(), DL, VT, N1.getOperand(0).getOperand(0),
2172 if (SimplifyDemandedBits(
SDValue(N, 0)))
2185 if (
SDValue Combined = visitADDLike(N0, N1, N))
2188 if (
SDValue Combined = visitADDLike(N1, N0, N))
2195 bool Masked =
false;
2234 SDLoc DL(LocReference);
2251 if (NumSignBits == DestBits &&
2284 DAG.
getVTList(VT, Carry.getValueType()), N0,
2339 if (!Const)
return false;
2343 return Const->
isOne();
2375 return CombineTo(N, N0, DAG.
getConstant(0, DL, CarryVT));
2387 return CombineTo(N, Sub,
2391 if (
SDValue Combined = visitUADDOLike(N0, N1, N))
2394 if (
SDValue Combined = visitUADDOLike(N1, N0, N))
2455 if (!LegalOperations ||
2464 EVT VT = N0.getValueType();
2466 AddToWorklist(CarryExt.
getNode());
2478 return CombineTo(N, Sub,
2482 if (
SDValue Combined = visitADDCARRYLike(N0, N1, CarryIn, N))
2485 if (
SDValue Combined = visitADDCARRYLike(N1, N0, CarryIn, N))
2527 Y.getOperand(0),
Y.getOperand(1),
2529 AddToWorklist(NewY.getNode());
2559 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2570 return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations, LegalTypes);
2578 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2597 if (ShiftAmt && ShiftAmt->
getZExtValue() == BitWidth - 1) {
2633 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(0) == N1)
2637 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(1) == N1)
2652 (N0.getOperand(1).getOpcode() ==
ISD::SUB ||
2653 N0.getOperand(1).getOpcode() ==
ISD::ADD) &&
2654 N0.getOperand(1).getOperand(0) == N1)
2655 return DAG.
getNode(N0.getOperand(1).getOpcode(), DL, VT, N0.getOperand(0),
2656 N0.getOperand(1).getOperand(1));
2659 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(1).getOpcode() ==
ISD::ADD &&
2660 N0.getOperand(1).getOperand(1) == N1)
2662 N0.getOperand(1).getOperand(0));
2665 if (N0.getOpcode() ==
ISD::SUB && N0.getOperand(1).getOpcode() ==
ISD::SUB &&
2666 N0.getOperand(1).getOperand(1) == N1)
2668 N0.getOperand(1).getOperand(0));
2711 if ((X0 == S0 && X1 == N1) || (X0 == N1 && X1 == S0)) {
2712 unsigned OpSizeInBits = VT.getScalarSizeInBits();
2714 if (
C->getAPIntValue() == (OpSizeInBits - 1))
2730 if (GA->getGlobal() == GB->getGlobal())
2731 return DAG.
getConstant((uint64_t)GA->getOffset() - GB->getOffset(),
2809 return CombineTo(N, N0, DAG.
getConstant(0, DL, CarryVT));
2838 if (!LegalOperations ||
2855 bool N0IsConst =
false;
2856 bool N1IsConst =
false;
2857 bool N1IsOpaqueConst =
false;
2858 bool N0IsOpaqueConst =
false;
2859 APInt ConstValue0, ConstValue1;
2862 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2869 "Splat APInt should be element width");
2872 "Splat APInt should be element width");
2874 N0IsConst = isa<ConstantSDNode>(N0);
2876 ConstValue0 = cast<ConstantSDNode>(N0)->getAPIntValue();
2877 N0IsOpaqueConst = cast<ConstantSDNode>(N0)->isOpaque();
2879 N1IsConst = isa<ConstantSDNode>(N1);
2881 ConstValue1 = cast<ConstantSDNode>(N1)->getAPIntValue();
2882 N1IsOpaqueConst = cast<ConstantSDNode>(N1)->isOpaque();
2887 if (N0IsConst && N1IsConst && !N0IsOpaqueConst && !N1IsOpaqueConst)
2902 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2916 SDValue LogBase2 = BuildLogBase2(N1, DL);
2922 if (N1IsConst && !N1IsOpaqueConst && (-ConstValue1).isPowerOf2()) {
2923 unsigned Log2Val = (-ConstValue1).logBase2();
2946 SDValue Sh(
nullptr, 0),
Y(
nullptr, 0);
2969 isMulAddWithConstProfitable(N, N0, N1))
2991 default:
return false;
2992 case MVT::i8: LC= isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8;
break;
2993 case MVT::i16: LC= isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16;
break;
2994 case MVT::i32: LC= isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32;
break;
2995 case MVT::i64: LC= isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64;
break;
2996 case MVT::i128: LC= isSigned ? RTLIB::SDIVREM_I128:RTLIB::UDIVREM_I128;
break;
3026 unsigned OtherOpcode = 0;
3050 if ((UserOpc == Opcode || UserOpc == OtherOpcode || UserOpc == DivRemOpc) &&
3054 if (UserOpc == OtherOpcode) {
3056 combined = DAG.
getNode(DivRemOpc,
SDLoc(Node), VTs, Op0, Op1);
3057 }
else if (UserOpc == DivRemOpc) {
3060 assert(UserOpc == Opcode);
3065 CombineTo(User, combined);
3067 CombineTo(User, combined.
getValue(1));
3094 EVT CCVT = getSetCCResultType(VT);
3098 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
3109 if (N1C && N1C->
isOne())
3123 if (
SDValue NewSel = foldBinOpIntoSelect(N))
3131 if (
SDValue V = visitSDIVLike(N0, N1, N))
3148 EVT CCVT = getSetCCResultType(VT);
3156 if (
C->isNullValue() ||
C->isOpaque())
3158 if (
C->getAPIntValue().isPowerOf2())
3160 if ((-
C->getAPIntValue()).isPowerOf2())
3172 if (
SDValue Res = BuildSDIVPow2(N))
3187 AddToWorklist(Sign.
getNode());
3191 AddToWorklist(Srl.getNode());
3193 AddToWorklist(Add.getNode());
3195 AddToWorklist(Sra.getNode());
3204 Sra = DAG.
getSelect(DL, VT, IsOneOrAllOnes, N0, Sra);
3222 if (
SDValue Op = BuildSDIV(N))
3232 EVT CCVT = getSetCCResultType(VT);
3236 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
3249 if (N1C && N1C->
isOne())
3260 if (
SDValue NewSel = foldBinOpIntoSelect(N))
3263 if (
SDValue V = visitUDIVLike(N0, N1, N))
3286 SDValue LogBase2 = BuildLogBase2(N1, DL);
3287 AddToWorklist(LogBase2.
getNode());
3291 AddToWorklist(Trunc.getNode());
3300 SDValue LogBase2 = BuildLogBase2(N10, DL);
3301 AddToWorklist(LogBase2.
getNode());
3305 AddToWorklist(Trunc.
getNode());
3307 AddToWorklist(Add.getNode());
3315 if (
SDValue Op = BuildUDIV(N))
3327 EVT CCVT = getSetCCResultType(VT);
3346 if (
SDValue NewSel = foldBinOpIntoSelect(N))
3382 isSigned ? visitSDIVLike(N0, N1, N) : visitUDIVLike(N0, N1, N);
3387 AddToWorklist(OptimizedDiv.
getNode());
3395 return DivRem.getValue(1);
3494 SDValue DAGCombiner::SimplifyNodeWithTwoResults(
SDNode *N,
unsigned LoOp,
3499 (!LegalOperations ||
3502 return CombineTo(N, Res, Res);
3508 (!LegalOperations ||
3511 return CombineTo(N, Res, Res);
3515 if (LoExists && HiExists)
3523 if (LoOpt.getNode() && LoOpt.getNode() != Lo.
getNode() &&
3524 (!LegalOperations ||
3526 return CombineTo(N, LoOpt, LoOpt);
3533 if (HiOpt.getNode() && HiOpt != Hi &&
3534 (!LegalOperations ||
3536 return CombineTo(N, HiOpt, HiOpt);
3566 return CombineTo(N, Lo, Hi);
3597 return CombineTo(N, Lo, Hi);
3607 if (C2->getAPIntValue() == 2)
3617 if (C2->getAPIntValue() == 2)
3631 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
3669 SDValue DAGCombiner::SimplifyBinOpWithSameOpcodeHands(
SDNode *N) {
3703 AddToWorklist(ORNode.
getNode());
3717 AddToWorklist(ORNode.
getNode());
3764 "Inputs to shuffles are not the same type");
3770 if (SVN0->
hasOneUse() && SVN1->hasOneUse() &&
3771 SVN0->
getMask().equals(SVN1->getMask())) {
3789 AddToWorklist(NewNode.
getNode());
3810 AddToWorklist(NewNode.
getNode());
3823 SDValue LL, LR, RL, RR, N0CC, N1CC;
3824 if (!isSetCCEquivalent(N0, LL, LR, N0CC) ||
3825 !isSetCCEquivalent(N1, RL, RR, N1CC))
3829 "Unexpected operand types for bitwise logic op");
3832 "Unexpected operand types for setcc");
3839 if (LegalOperations || VT.getScalarType() !=
MVT::i1)
3840 if (VT != getSetCCResultType(OpVT))
3848 if (LR == RR && CC0 == CC1 && IsInteger) {
3853 bool AndEqZero = IsAnd && CC1 ==
ISD::SETEQ && IsZero;
3855 bool AndGtNeg1 = IsAnd && CC1 ==
ISD::SETGT && IsNeg1;
3857 bool OrNeZero = !IsAnd && CC1 ==
ISD::SETNE && IsZero;
3859 bool OrLtZero = !IsAnd && CC1 ==
ISD::SETLT && IsZero;
3865 if (AndEqZero || AndGtNeg1 || OrNeZero || OrLtZero) {
3868 return DAG.
getSetCC(DL, VT, Or, LR, CC1);
3872 bool AndEqNeg1 = IsAnd && CC1 ==
ISD::SETEQ && IsNeg1;
3874 bool AndLtZero = IsAnd && CC1 ==
ISD::SETLT && IsZero;
3876 bool OrNeNeg1 = !IsAnd && CC1 ==
ISD::SETNE && IsNeg1;
3878 bool OrGtNeg1 = !IsAnd && CC1 ==
ISD::SETGT && IsNeg1;
3884 if (AndEqNeg1 || AndLtZero || OrNeNeg1 || OrGtNeg1) {
3887 return DAG.
getSetCC(DL, VT, And, LR, CC1);
3915 return DAG.
getSetCC(DL, VT, Or, Zero, CC1);
3920 if (LL == RR && LR == RL) {
3927 if (LL == RL && LR == RR) {
3931 (!LegalOperations ||
3934 return DAG.
getSetCC(DL, VT, LL, LR, NewCC);
3952 if (
SDValue V = foldLogicOfSetCCs(
true, N0, N1, DL))
3964 APInt SRLC = SRLI->getAPIntValue();
3977 CombineTo(N0.
getNode(), NewAdd);
3994 const APInt &AndMask = CAnd->getAPIntValue();
4007 (ShiftBits + MaskBits <= Size / 2) &&
4019 assert(MaskBits <= Size);
4040 EVT LoadResultTy,
EVT &ExtVT) {
4049 if (ExtVT == LoadedVT &&
4050 (!LegalOperations ||
4063 if (!LoadedVT.bitsGT(ExtVT) || !ExtVT.
isRound())
4066 if (LegalOperations &&
4076 bool DAGCombiner::isLegalNarrowLdSt(
LSBaseSDNode *LDST,
4109 if (isa<LoadSDNode>(LDST)) {
4116 if (LegalOperations &&
4138 assert(isa<StoreSDNode>(LDST) &&
"It is not a Load nor a Store SDNode");
4144 if (LegalOperations &&
4151 bool DAGCombiner::SearchForAndLoads(
SDNode *N,
4165 if (
auto *
C = dyn_cast<ConstantSDNode>(Op)) {
4168 NodesWithConsts.
insert(N);
4177 auto *Load = cast<LoadSDNode>(
Op);
4179 if (isAndLoadExtLoad(Mask, Load, Load->
getValueType(0), ExtVT) &&
4184 ExtVT.bitsGE(Load->getMemoryVT()))
4188 if (ExtVT.bitsLE(Load->getMemoryVT()))
4212 if (!SearchForAndLoads(Op.
getNode(), Loads, NodesWithConsts,
Mask,
4226 for (
unsigned i = 0, e = NodeToMask->
getNumValues(); i < e; ++i) {
4230 NodeToMask =
nullptr;
4236 assert(HasValue &&
"Node to be masked has no data result?");
4256 SDNode *FixupNode =
nullptr;
4257 if (SearchForAndLoads(N, Loads, NodesWithConsts, Mask, FixupNode)) {
4258 if (Loads.
size() == 0)
4270 SDValue(FixupNode, 0), MaskOp);
4277 for (
auto *LogicN : NodesWithConsts) {
4281 if (isa<ConstantSDNode>(Op0))
4291 for (
auto *Load : Loads) {
4299 SDValue NewLoad = ReduceLoadWidth(And.getNode());
4301 "Shouldn't be masking the load if it can't be narrowed");
4302 CombineTo(Load, NewLoad, NewLoad.
getValue(1));
4315 SDValue DAGCombiner::unfoldExtremeBitClearingToShifts(
SDNode *N) {
4326 unsigned OuterShift;
4327 unsigned InnerShift;
4329 auto matchMask = [&OuterShift, &InnerShift, &
Y](
SDValue M) ->
bool {
4332 OuterShift = M->getOpcode();
4341 Y = M->getOperand(1);
4348 else if (matchMask(N0))
4375 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
4398 if (N0C && N1C && !N1C->
isOpaque())
4413 if (
SDValue NewSel = foldBinOpIntoSelect(N))
4422 if (
SDValue Shuffle = XformToShuffleWithZero(N))
4427 return RHS->getAPIntValue().isSubsetOf(LHS->
getAPIntValue());
4447 CombineTo(N0.
getNode(), Zext);
4470 Constant =
C->getAPIntValue();
4472 APInt SplatValue, SplatUndef;
4473 unsigned SplatBitSize;
4475 bool IsSplat = Vector->isConstantSplat(SplatValue, SplatUndef,
4476 SplatBitSize, HasAnyUndefs);
4480 SplatValue |= SplatUndef;
4486 EVT VT = Vector->getValueType(0);
4492 if (BitWidth > SplatBitSize)
4493 for (SplatValue = SplatValue.
zextOrTrunc(BitWidth);
4494 SplatBitSize < BitWidth;
4495 SplatBitSize = SplatBitSize * 2)
4496 SplatValue |= SplatValue.
shl(SplatBitSize);
4500 if (SplatBitSize % BitWidth == 0) {
4502 for (
unsigned i = 0, n = SplatBitSize/BitWidth; i < n; ++i)
4522 default: B =
false;
break;
4528 if (B && Constant.isAllOnesValue()) {
4534 CombineTo(N, (N0.
getNode() ==
Load) ? NewLoad : N0);
4547 CombineTo(Load, To, 3,
true);
4563 if (
SDValue Res = ReduceLoadWidth(N)) {
4565 ? cast<LoadSDNode>(N0.
getOperand(0)) : cast<LoadSDNode>(N0);
4568 CombineTo(LN0, Res, Res.getValue(1));
4578 if (BackwardsPropagateMask(N, DAG)) {
4583 if (
SDValue Combined = visitANDLike(N0, N1, N))
4588 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
4612 if (SimplifyDemandedBits(
SDValue(N, 0)))
4623 BitWidth - MemVT.getScalarSizeInBits())) &&
4643 BitWidth - MemVT.getScalarSizeInBits())) &&
4661 if (
SDValue Shifts = unfoldExtremeBitClearingToShifts(N))
4669 bool DemandHighBits) {
4670 if (!LegalOperations)
4680 bool LookPassAnd0 =
false;
4681 bool LookPassAnd1 =
false;
4696 LookPassAnd0 =
true;
4706 LookPassAnd1 =
true;
4720 if (N01C->
getZExtValue() != 8 || N11C->getZExtValue() != 8)
4732 LookPassAnd0 =
true;
4746 LookPassAnd1 =
true;
4755 if (DemandHighBits && OpSizeInBits > 16) {
4764 if (!LookPassAnd1 &&
4771 if (OpSizeInBits > 16) {
4775 getShiftAmountTy(VT)));
4808 unsigned MaskByteOffset;
4812 case 0xFF: MaskByteOffset = 0;
break;
4813 case 0xFF00: MaskByteOffset = 1;
break;
4822 case 0xFF0000: MaskByteOffset = 2;
break;
4823 case 0xFF000000: MaskByteOffset = 3;
break;
4828 if (MaskByteOffset == 0 || MaskByteOffset == 2) {
4848 if (MaskByteOffset != 0 && MaskByteOffset != 2)
4856 if (MaskByteOffset != 1 && MaskByteOffset != 3)
4863 if (Parts[MaskByteOffset])
4877 if (!LegalOperations)
4926 if (Parts[0] != Parts[1] || Parts[0] != Parts[2] || Parts[0] != Parts[3])
4955 if (
SDValue V = foldLogicOfSetCCs(
false, N0, N1, DL))
4970 const APInt &LHSMask = N0O1C->getAPIntValue();
4971 const APInt &RHSMask = N1O1C->getAPIntValue();
5009 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
5028 if (isa<ShuffleVectorSDNode>(N0) &&
5029 isa<ShuffleVectorSDNode>(N1) &&
5037 if ((ZeroN00 != ZeroN01) && (ZeroN10 != ZeroN11)) {
5038 assert((!ZeroN00 || !ZeroN01) &&
"Both inputs zero!");
5039 assert((!ZeroN10 || !ZeroN11) &&
"Both inputs zero!");
5042 bool CanFold =
true;
5046 for (
int i = 0; i != NumElts; ++i) {
5048 int M1 = SV1->getMaskElt(i);
5051 bool M0Zero = M0 < 0 || (ZeroN00 == (M0 < NumElts));
5052 bool M1Zero = M1 < 0 || (ZeroN10 == (M1 < NumElts));
5056 if ((M0Zero && M1 < 0) || (M1Zero && M0 < 0)) {
5062 if (M0Zero == M1Zero) {
5067 assert((M0 >= 0 || M1 >= 0) &&
"Undef index!");
5073 Mask[i] = M1Zero ? M0 % NumElts : (M1 % NumElts) + NumElts;
5097 if (N0C && N1C && !N1C->
isOpaque())
5110 if (
SDValue NewSel = foldBinOpIntoSelect(N))
5117 if (
SDValue Combined = visitORLike(N0, N1, N))
5121 if (
SDValue BSwap = MatchBSwapHWord(N, N0, N1))
5123 if (
SDValue BSwap = MatchBSwapHWordLow(N, N0, N1))
5147 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
5154 if (
SDValue Load = MatchLoadCombine(N))
5158 if (SimplifyDemandedBits(
SDValue(N, 0)))
5208 assert(OppShift && ExtractFrom &&
"Empty SDValue");
5211 "Existing shift must be valid as a rotate half");
5219 bool IsMulOrDiv =
false;
5222 auto SelectOpcode = [&](
unsigned NeededShift,
unsigned MulOrDivVariant) {
5223 IsMulOrDiv = ExtractFrom.
getOpcode() == MulOrDivVariant;
5224 if (!IsMulOrDiv && ExtractFrom.
getOpcode() != NeededShift)
5226 Opcode = NeededShift;
5254 !OppLHSCst || !OppLHSCst->getAPIntValue() ||
5255 !ExtractFromCst || !ExtractFromCst->getAPIntValue())
5264 APInt ExtractFromAmt = ExtractFromCst->getAPIntValue();
5265 APInt OppLHSAmt = OppLHSCst->getAPIntValue();
5280 if (Rem != 0 || ResultAmt != OppLHSAmt)
5286 if (OppLHSAmt != ExtractFromAmt - NeededShiftAmt.
zextOrTrunc(
5295 return DAG.
getNode(Opcode, DL, ResVT, OppShiftLHS, NewShiftNode);
5340 unsigned MaskLoBits = 0;
5346 if (NegC->getAPIntValue().getActiveBits() <= Bits &&
5368 if (PosC->getAPIntValue().getActiveBits() <= MaskLoBits &&
5408 return Width.
getLoBits(MaskLoBits) == 0;
5409 return Width == EltSize;
5419 SDValue InnerNeg,
unsigned PosOpcode,
5420 unsigned NegOpcode,
const SDLoc &DL) {
5431 return DAG.
getNode(HasPos ? PosOpcode : NegOpcode, DL, VT, Shifted,
5432 HasPos ? Pos : Neg).
getNode();
5447 bool HasROTL = hasOperation(
ISD::ROTL, VT);
5448 bool HasROTR = hasOperation(
ISD::ROTR, VT);
5449 if (!HasROTL && !HasROTR)
return nullptr;
5471 if (!LHSShift && !RHSShift)
5486 RHSShift = NewRHSShift;
5491 LHSShift = NewLHSShift;
5494 if (!RHSShift || !LHSShift)
5522 return (LHS->
getAPIntValue() + RHS->getAPIntValue()) == EltSizeInBits;
5526 LHSShiftArg, HasROTL ? LHSShiftAmt : RHSShiftAmt);
5556 SDValue LExtOp0 = LHSShiftAmt;
5557 SDValue RExtOp0 = RHSShiftAmt;
5570 SDNode *TryL = MatchRotatePosNeg(LHSShiftArg, LHSShiftAmt, RHSShiftAmt,
5575 SDNode *TryR = MatchRotatePosNeg(RHSShiftArg, RHSShiftAmt, LHSShiftAmt,
5587 struct ByteProvider {
5592 unsigned ByteOffset = 0;
5594 ByteProvider() =
default;
5597 return ByteProvider(Load, ByteOffset);
5600 static ByteProvider getConstantZero() {
return ByteProvider(
nullptr, 0); }
5602 bool isConstantZero()
const {
return !
Load; }
5603 bool isMemory()
const {
return Load; }
5606 return Other.Load == Load && Other.ByteOffset == ByteOffset;
5610 ByteProvider(
LoadSDNode *Load,
unsigned ByteOffset)
5611 :
Load(Load), ByteOffset(ByteOffset) {}
5629 bool Root =
false) {
5639 if (BitWidth % 8 != 0)
5641 unsigned ByteWidth = BitWidth / 8;
5642 assert(Index < ByteWidth &&
"invalid index requested");
5654 if (LHS->isConstantZero())
5656 if (RHS->isConstantZero())
5665 uint64_t BitShift = ShiftOp->getZExtValue();
5666 if (BitShift % 8 != 0)
5668 uint64_t ByteShift = BitShift / 8;
5670 return Index < ByteShift
5671 ? ByteProvider::getConstantZero()
5680 if (NarrowBitWidth % 8 != 0)
5682 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
5684 if (Index >= NarrowByteWidth)
5694 auto L = cast<LoadSDNode>(Op.
getNode());
5695 if (L->isVolatile() || L->isIndexed())
5698 unsigned NarrowBitWidth = L->getMemoryVT().getSizeInBits();
5699 if (NarrowBitWidth % 8 != 0)
5701 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
5703 if (Index >= NarrowByteWidth)
5746 "Can only match load combining against OR nodes");
5752 unsigned ByteWidth = VT.getSizeInBits() / 8;
5761 std::function<unsigned(unsigned, unsigned)> LittleEndianByteAt = [](
5762 unsigned BW,
unsigned i) {
return i; };
5763 std::function<unsigned(unsigned, unsigned)> BigEndianByteAt = [](
5764 unsigned BW,
unsigned i) {
return BW - i - 1; };
5767 auto MemoryByteOffset = [&] (ByteProvider
P) {
5768 assert(
P.isMemory() &&
"Must be a memory byte provider");
5769 unsigned LoadBitWidth =
P.Load->getMemoryVT().getSizeInBits();
5770 assert(LoadBitWidth % 8 == 0 &&
5771 "can only analyze providers for individual bytes not bit");
5772 unsigned LoadByteWidth = LoadBitWidth / 8;
5773 return IsBigEndianTarget
5774 ? BigEndianByteAt(LoadByteWidth,
P.ByteOffset)
5775 : LittleEndianByteAt(LoadByteWidth,
P.ByteOffset);
5788 for (
unsigned i = 0; i < ByteWidth; i++) {
5790 if (!
P || !
P->isMemory())
5795 "Must be enforced by calculateByteProvider");
5802 else if (Chain != LChain)
5807 int64_t ByteOffsetFromBase = 0;
5814 ByteOffsetFromBase += MemoryByteOffset(*
P);
5815 ByteOffsets[i] = ByteOffsetFromBase;
5818 if (ByteOffsetFromBase < FirstOffset) {
5819 FirstByteProvider =
P;
5820 FirstOffset = ByteOffsetFromBase;
5825 assert(!Loads.
empty() &&
"All the bytes of the value must be loaded from " 5826 "memory, so there must be at least one load which produces the value");
5827 assert(Base &&
"Base address of the accessed memory location must be set");
5832 bool BigEndian =
true, LittleEndian =
true;
5833 for (
unsigned i = 0; i < ByteWidth; i++) {
5834 int64_t CurrentByteOffset = ByteOffsets[i] - FirstOffset;
5835 LittleEndian &= CurrentByteOffset == LittleEndianByteAt(ByteWidth, i);
5836 BigEndian &= CurrentByteOffset == BigEndianByteAt(ByteWidth, i);
5837 if (!BigEndian && !LittleEndian)
5840 assert((BigEndian != LittleEndian) &&
"should be either or");
5841 assert(FirstByteProvider &&
"must be set");
5845 if (MemoryByteOffset(*FirstByteProvider) != 0)
5847 LoadSDNode *FirstLoad = FirstByteProvider->Load;
5853 bool NeedsBswap = IsBigEndianTarget != BigEndian;
5866 if (!Allowed || !Fast)
5906 if (And.getOpcode() !=
ISD::AND || !And.hasOneUse())
5928 if (!matchAndXor(N0, 0, N1) && !matchAndXor(N0, 1, N1) &&
5929 !matchAndXor(N1, 0, N0) && !matchAndXor(N1, 1, N0))
5935 if (isa<ConstantSDNode>(M.
getNode()))
5969 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
6000 if (
SDValue NewSel = foldBinOpIntoSelect(N))
6014 if (!LegalOperations ||
6031 isSetCCEquivalent(N0.
getOperand(0), LHS, RHS, CC)){
6044 if (isOneUseSetCC(RHS) || isOneUseSetCC(LHS)) {
6048 AddToWorklist(LHS.
getNode()); AddToWorklist(RHS.getNode());
6056 if (isa<ConstantSDNode>(RHS) || isa<ConstantSDNode>(LHS)) {
6060 AddToWorklist(LHS.
getNode()); AddToWorklist(RHS.getNode());
6069 AddToWorklist(NotX.
getNode());
6080 if ((A0 == S && A1 == S0) || (A1 == S && A0 == S0)) {
6083 if (
C->getAPIntValue() == (OpSizeInBits - 1))
6120 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
6124 if (
SDValue MM = unfoldMaskedMerge(N))
6128 if (SimplifyDemandedBits(
SDValue(N, 0)))
6144 bool HighBitSet =
false;
6164 if (!BinOpCst)
return SDValue();
6175 if ((!isShift || !isa<ConstantSDNode>(BinOpLHSVal->
getOperand(1))) &&
6190 if (BinOpRHSSignSet != HighBitSet)
6201 assert(isa<ConstantSDNode>(NewRHS) &&
"Folding was not successful!");
6212 SDValue DAGCombiner::distributeTruncateThroughAnd(
SDNode *N) {
6225 AddToWorklist(Trunc00.
getNode());
6226 AddToWorklist(Trunc01.
getNode());
6247 if (Cst->getAPIntValue().uge(Bitsize)) {
6248 uint64_t RotAmt = Cst->getAPIntValue().urem(Bitsize);
6268 bool SameSide = (N->
getOpcode() == NextOp);
6274 ISD::SREM, dl, ShiftVT, CombinedShift.getNode(),
6292 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
6319 if (N0C && N1C && !N1C->
isOpaque())
6327 return Val->getAPIntValue().uge(OpSizeInBits);
6338 if (
SDValue NewSel = foldBinOpIntoSelect(N))
6352 if (N1C && SimplifyDemandedBits(
SDValue(N, 0)))
6360 APInt c2 = RHS->getAPIntValue();
6362 return (c1 + c2).uge(OpSizeInBits);
6370 APInt c2 = RHS->getAPIntValue();
6372 return (c1 + c2).ult(OpSizeInBits);
6393 APInt c1 = N0Op0C1->getAPIntValue();
6399 if (c2.
uge(OpSizeInBits - InnerShiftSize)) {
6401 APInt Sum = c1 + c2;
6402 if (Sum.
uge(OpSizeInBits))
6421 uint64_t c1 = N0Op0C1->getZExtValue();
6430 AddToWorklist(NewSHL.
getNode());
6442 uint64_t C1 = N0C1->getZExtValue();
6459 uint64_t c1 = N0C1->getZExtValue();
6460 if (c1 < OpSizeInBits) {
6501 AddToWorklist(Shl0.
getNode());
6502 AddToWorklist(Shl1.
getNode());
6516 if (
SDValue NewSHL = visitShiftByConstant(N, N1C))
6536 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
6543 if (N0C && N1C && !N1C->
isOpaque())
6548 return Val->getAPIntValue().uge(OpSizeInBits);
6556 if (
SDValue NewSel = foldBinOpIntoSelect(N))
6567 if ((!LegalOperations ||
6576 EVT ShiftVT = N1.getValueType();
6581 APInt c2 = RHS->getAPIntValue();
6583 return (c1 + c2).uge(OpSizeInBits);
6592 APInt c2 = RHS->getAPIntValue();
6594 return (c1 + c2).ult(OpSizeInBits);
6625 if ((ShiftAmt > 0) &&
6644 N1.getOperand(0).getOpcode() ==
ISD::AND) {
6645 if (
SDValue NewOp1 = distributeTruncateThroughAnd(N1.getNode()))
6659 unsigned LargeShiftVal = LargeShift->getZExtValue();
6675 if (N1C && SimplifyDemandedBits(
SDValue(N, 0)))
6683 if (
SDValue NewSRA = visitShiftByConstant(N, N1C))
6697 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
6704 if (N0C && N1C && !N1C->
isOpaque())
6712 return Val->getAPIntValue().uge(OpSizeInBits);
6720 if (
SDValue NewSel = foldBinOpIntoSelect(N))
6733 APInt c2 = RHS->getAPIntValue();
6735 return (c1 + c2).uge(OpSizeInBits);
6743 APInt c2 = RHS->getAPIntValue();
6745 return (c1 + c2).ult(OpSizeInBits);
6759 uint64_t c1 = N001C->getZExtValue();
6765 if (c1 + OpSizeInBits == InnerShiftSize) {
6767 if (c1 + c2 >= InnerShiftSize)
6784 AddToWorklist(Mask.
getNode());
6802 getShiftAmountTy(SmallVT)));
6803 AddToWorklist(SmallShift.
getNode());
6866 if (N1C && SimplifyDemandedBits(
SDValue(N, 0)))
6870 if (
SDValue NewSRL = visitShiftByConstant(N, N1C))
6874 if (
SDValue NarrowLoad = ReduceLoadWidth(N))
7020 if (!(LHS == True && RHS == False) && !(LHS == False && RHS == True))
7032 return DAG.
getNode(Opcode, DL, VT, LHS, RHS);
7043 return DAG.
getNode(Opcode, DL, VT, LHS, RHS);
7071 if (CondVT ==
MVT::i1 && !LegalOperations) {
7072 if (C1->isNullValue() && C2->isOne()) {
7079 if (C1->isNullValue() && C2->isAllOnesValue()) {
7086 if (C1->isOne() && C2->isNullValue()) {
7092 if (C1->isAllOnesValue() && C2->isNullValue()) {
7103 if (C1->getAPIntValue() - 1 == C2->getAPIntValue()) {
7109 if (C1->getAPIntValue() + 1 == C2->getAPIntValue()) {
7134 C1->isNullValue() && C2->isOne()) {
7157 if (
const ConstantSDNode *N0C = dyn_cast<const ConstantSDNode>(N0)) {
7160 return !N0C->isNullValue() ? N1 : N2;
7168 if (
SDValue V = foldSelectOfConstants(N))
7174 AddToWorklist(NOTNode.
getNode());
7180 AddToWorklist(NOTNode.
getNode());
7189 if (SimplifySelectOps(N, N1, N2))
7201 bool normalizeToSequence =
7210 if (normalizeToSequence || !InnerSelect.
use_empty())
7220 if (normalizeToSequence || !InnerSelect.
use_empty())
7232 if (!normalizeToSequence) {
7237 if (
SDValue Combined = visitANDLike(N0, N1_0, N))
7249 if (!normalizeToSequence) {
7254 if (
SDValue Combined = visitORLike(N0, N2_0, N))
7288 if ((!LegalOperations &&
7293 return SimplifySelect(DL, N0, N1, N2);
7313 return std::make_pair(Lo, Hi);
7340 for (
int i = 0; i < NumElems / 2; ++i) {
7344 if (BottomHalf ==
nullptr)
7345 BottomHalf = cast<ConstantSDNode>(Cond.
getOperand(i));
7352 for (
int i = NumElems / 2; i < NumElems; ++i) {
7356 if (TopHalf ==
nullptr)
7357 TopHalf = cast<ConstantSDNode>(Cond.
getOperand(i));
7362 assert(TopHalf && BottomHalf &&
7363 "One half of the selector was all UNDEFs and the other was all the " 7364 "same value. This should have been addressed before this function.");
7392 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
7402 EVT LoMemVT, HiMemVT;
7406 std::tie(DataLo, DataHi) = DAG.
SplitVector(Data, DL);
7418 SDValue OpsLo[] = { Chain, DataLo, MaskLo, BasePtr, IndexLo, Scale };
7422 SDValue OpsHi[] = { Chain, DataHi, MaskHi, BasePtr, IndexHi, Scale };
7453 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
7463 unsigned SecondHalfAlignment =
7464 (Alignment == VT.
getSizeInBits() / 8) ? Alignment / 2 : Alignment;
7466 EVT LoMemVT, HiMemVT;
7470 std::tie(DataLo, DataHi) = DAG.
SplitVector(Data, DL);
7477 Lo = DAG.
getMaskedStore(Chain, DL, DataLo, Ptr, MaskLo, LoMemVT, MMO,
7490 Hi = DAG.
getMaskedStore(Chain, DL, DataHi, Ptr, MaskHi, HiMemVT, MMO,
7494 AddToWorklist(Lo.getNode());
7526 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
7530 std::tie(Src0Lo, Src0Hi) = DAG.
SplitVector(Src0, DL);
7539 EVT LoMemVT, HiMemVT;
7546 std::tie(IndexLo, IndexHi) = DAG.
SplitVector(Index, DL);
7553 SDValue OpsLo[] = { Chain, Src0Lo, MaskLo, BasePtr, IndexLo, Scale };
7557 SDValue OpsHi[] = { Chain, Src0Hi, MaskHi, BasePtr, IndexHi, Scale };
7575 SDValue RetOps[] = { GatherRes, Chain };
7600 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
7604 std::tie(Src0Lo, Src0Hi) = DAG.
SplitVector(Src0, DL);
7616 unsigned SecondHalfAlignment =
7618 Alignment/2 : Alignment;
7620 EVT LoMemVT, HiMemVT;
7628 Lo = DAG.
getMaskedLoad(LoVT, DL, Chain, Ptr, MaskLo, Src0Lo, LoMemVT, MMO,
7640 Hi = DAG.
getMaskedLoad(HiVT, DL, Chain, Ptr, MaskHi, Src0Hi, HiMemVT, MMO,
7643 AddToWorklist(Lo.getNode());
7657 SDValue RetOps[] = { LoadRes, Chain };
7679 bool AllAddOne =
true;
7680 bool AllSubOne =
true;
7682 for (
unsigned i = 0; i != Elts; ++i) {
7688 const APInt &C1 = cast<ConstantSDNode>(N1Elt)->getAPIntValue();
7689 const APInt &C2 = cast<ConstantSDNode>(N2Elt)->getAPIntValue();
7699 if (AllAddOne || AllSubOne) {
7752 AddToWorklist(Shift.
getNode());
7771 SetCCWidth != 1 && SetCCWidth < WideWidth &&
7781 EVT WideSetCCVT = getSetCCResultType(WideVT);
7782 SDValue WideSetCC = DAG.
getSetCC(DL, WideSetCCVT, WideLHS, WideRHS, CC);
7783 return DAG.
getSelect(DL, N1.getValueType(), WideSetCC, N1, N2);
7788 if (SimplifySelectOps(N, N1, N2))
7808 if (
SDValue V = foldVSelectOfConstants(N))
7828 CC,
SDLoc(N),
false)) {
7829 AddToWorklist(SCC.getNode());
7831 if (
ConstantSDNode *SCCC = dyn_cast<ConstantSDNode>(SCC.getNode())) {
7832 if (!SCCC->isNullValue())
7836 }
else if (SCC->isUndef()) {
7843 SCC.getOperand(0), SCC.getOperand(1), N2, N3,
7849 if (SimplifySelectOps(N, N2, N3))
7853 return SimplifySelectCC(
SDLoc(N), N0, N1, N2, N3, CC);
7863 SDValue Combined = SimplifySetCC(
7865 cast<CondCodeSDNode>(N->
getOperand(2))->
get(),
SDLoc(N), !PreferSetCC);
7873 SDValue NewSetCC = rebuildSetCC(Combined);
7907 bool LegalOperations) {
7915 &&
"Expected EXTEND dag node in input!");
7920 if (isa<ConstantSDNode>(N0))
7928 (!LegalTypes || (!LegalOperations && TLI.
isTypeLegal(SVT))) &&
7939 for (
unsigned i=0; i != NumElts; ++i) {
7949 APInt C = cast<ConstantSDNode>(
Op)->getAPIntValue().zextOrTrunc(EVTBits);
7967 bool HasCopyToRegUses =
false;
7975 if (UI.getUse().getResNo() != N0.
getResNo())
7984 for (
unsigned i = 0; i != 2; ++i) {
7988 if (!isa<ConstantSDNode>(UseOp))
8002 HasCopyToRegUses =
true;
8005 if (HasCopyToRegUses) {
8006 bool BothLiveOut =
false;
8018 return ExtendNodes.
size();
8028 for (
SDNode *SetCC : SetCCs) {
8031 for (
unsigned j = 0; j != 2; ++j) {
8033 if (SOp == OrigLoad)
8052 "Unexpected node type (not an extend)!");
8089 EVT SplitSrcVT = SrcVT;
8090 EVT SplitDstVT = DstVT;
8101 const unsigned NumSplits =
8108 for (
unsigned Idx = 0; Idx < NumSplits; Idx++) {
8109 const unsigned Offset = Idx * Stride;
8121 Chains.
push_back(SplitLoad.getValue(1));
8128 AddToWorklist(NewChain.
getNode());
8130 CombineTo(N, NewValue);
8137 CombineTo(N0.
getNode(), Trunc, NewChain);
8143 SDValue DAGCombiner::CombineZExtLogicopShiftLoad(
SDNode *N) {
8195 Mask = Mask.
zext(VT.getSizeInBits());
8202 if (
SDValue(Load, 0).hasOneUse()) {
8207 CombineTo(Load, Trunc, ExtLoad.
getValue(1));
8216 SDValue DAGCombiner::matchVSelectOpSizesWithSetCC(
SDNode *Cast) {
8217 unsigned CastOpcode = Cast->
getOpcode();
8221 "Unexpected opcode for vector select narrowing/widening");
8251 CastA = DAG.
getNode(CastOpcode, DL, VT, A);
8252 CastB = DAG.
getNode(CastOpcode, DL, VT, B);
8261 bool LegalOperations,
SDNode *N,
8272 if ((LegalOperations || LN0->
isVolatile()) &&
8279 Combiner.CombineTo(N, ExtLoad);
8294 ((LegalOperations || VT.
isVector() ||
8299 bool DoXform =
true;
8312 Combiner.ExtendSetCCUses(SetCCs, N0, ExtLoad, ExtOpc);
8315 Combiner.CombineTo(N, ExtLoad);
8316 if (NoReplaceTrunc) {
8321 Combiner.CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
8327 bool LegalOperations) {
8352 return DAG.
getNode(ShiftOpcode, DL, VT, NotX, ShiftAmount);
8376 if (NarrowLoad.getNode() != N0.
getNode()) {
8377 CombineTo(N0.
getNode(), NarrowLoad);
8392 if (OpBits == DestBits) {
8395 if (NumSignBits > DestBits-MidBits)
8397 }
else if (OpBits < DestBits) {
8400 if (NumSignBits > OpBits-MidBits)
8405 if (NumSignBits > OpBits-MidBits)
8412 if (OpBits < DestBits)
8414 else if (OpBits > DestBits)
8429 if (
SDValue ExtLoad = CombineExtLoad(N))
8434 DAG, *
this, TLI, VT, LegalOperations, N, N0,
ISD::SEXTLOAD))
8461 bool NoReplaceTruncAnd = !N0.
hasOneUse();
8465 if (NoReplaceTruncAnd) {
8468 CombineTo(N0.
getNode(), TruncAnd);
8470 if (NoReplaceTrunc) {
8475 CombineTo(LN00, Trunc, ExtLoad.
getValue(1));
8493 if (VT.
isVector() && !LegalOperations &&
8499 EVT SVT = getSetCCResultType(N00VT);
8507 return DAG.
getSetCC(DL, VT, N00, N01, CC);
8513 if (SVT == MatchingVecType) {
8531 SDValue ExtTrueVal = (SetCCWidth == 1)
8536 SimplifySelectCC(DL, N00, N01, ExtTrueVal, Zero, CC,
true))
8540 EVT SetCCVT = getSetCCResultType(N00VT);
8548 return DAG.
getSelect(DL, VT, SetCC, ExtTrueVal, Zero);
8558 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
8593 if (!(Known.
Zero | 1).isAllOnesValue())
8620 APInt TruncatedBits =
8637 if (NarrowLoad.getNode() != N0.
getNode()) {
8638 CombineTo(N0.
getNode(), NarrowLoad);
8699 if (
SDValue ExtLoad = CombineExtLoad(N))
8715 bool DoXform =
true;
8719 auto *AndC = cast<ConstantSDNode>(N0.
getOperand(1));
8722 if (isAndLoadExtLoad(AndC, LN00, LoadResultTy, ExtVT))
8740 bool NoReplaceTruncAnd = !N0.
hasOneUse();
8744 if (NoReplaceTruncAnd) {
8747 CombineTo(N0.
getNode(), TruncAnd);
8749 if (NoReplaceTrunc) {
8754 CombineTo(LN00, Trunc, ExtLoad.
getValue(1));
8763 if (
SDValue ZExtLoad = CombineZExtLogicopShiftLoad(N))
8768 DAG, *
this, TLI, VT, LegalOperations, N, N0,
ISD::ZEXTLOAD))
8776 if (!LegalOperations && VT.
isVector() &&
8809 if (
SDValue SCC = SimplifySelectCC(
8812 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true))
8822 unsigned ShAmtVal = cast<ConstantSDNode>(ShAmt)->getZExtValue();
8829 if (ShAmtVal > KnownZeroBits)
8844 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
8871 if (NarrowLoad.getNode() != N0.
getNode()) {
8872 CombineTo(N0.
getNode(), NarrowLoad);
8907 bool DoXform =
true;
8921 CombineTo(N, ExtLoad);
8922 if (NoReplaceTrunc) {
8927 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
8941 if (!LegalOperations || TLI.
isLoadExtLegal(ExtType, VT, MemVT)) {
8945 CombineTo(N, ExtLoad);
8957 if (VT.
isVector() && !LegalOperations) {
8970 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
8979 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
8986 if (
SDValue SCC = SimplifySelectCC(
8989 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true))
9000 EVT AssertVT = cast<VTSDNode>(N1)->getVT();
9004 AssertVT == cast<VTSDNode>(N0.
getOperand(1))->getVT())
9015 EVT BigA_AssertVT = cast<VTSDNode>(BigA.
getOperand(1))->getVT();
9017 "Asserting zero/sign-extended bits to a type larger than the " 9018 "truncated destination does not provide information");
9021 EVT MinAssertVT = AssertVT.
bitsLT(BigA_AssertVT) ? AssertVT : BigA_AssertVT;
9053 ExtVT = cast<VTSDNode>(N->
getOperand(1))->getVT();
9066 uint64_t ShiftAmt = N01->getZExtValue();
9067 uint64_t MemoryWidth = LN0->getMemoryVT().getSizeInBits();
9068 if (LN0->getExtensionType() !=
ISD::SEXTLOAD && MemoryWidth > ShiftAmt)
9087 if (
auto *ConstShift = dyn_cast<ConstantSDNode>(SRL.
getOperand(1))) {
9088 ShAmt = ConstShift->getZExtValue();
9091 if ((ShAmt & (EVTBits-1)) == 0) {
9099 if (!isa<LoadSDNode>(N0))
return SDValue();
9101 auto *LN0 = cast<LoadSDNode>(N0);
9112 if (ShAmt >= LN0->getMemoryVT().getSizeInBits())
9120 const APInt &ShiftMask =
9121 cast<ConstantSDNode>(Mask->
getOperand(1))->getAPIntValue();
9122 if (ShiftMask.
isMask()) {
9136 unsigned ShLeftAmt = 0;
9140 ShLeftAmt = N01->getZExtValue();
9146 if (!isa<LoadSDNode>(N0))
9150 if (!isLegalNarrowLdSt(LN0, ExtType, ExtVT, ShAmt))
9158 ShAmt = LVTStoreBits - EVTStoreBits - ShAmt;
9162 uint64_t PtrOff = ShAmt / 8;
9172 AddToWorklist(NewPtr.
getNode());
9186 WorklistRemover DeadNodes(*
this);
9191 if (ShLeftAmt != 0) {
9215 EVT EVT = cast<VTSDNode>(N1)->getVT();
9251 if (!LegalOperations ||
9271 if (SimplifyDemandedBits(
SDValue(N, 0)))
9276 if (
SDValue NarrowLoad = ReduceLoadWidth(N))
9284 if (ShAmt->getZExtValue()+EVTBits <= VTBits) {
9288 if (VTBits-(ShAmt->getZExtValue()+EVTBits) < InSignBits)
9300 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
9301 ((!LegalOperations && !cast<LoadSDNode>(N0)->
isVolatile() &&
9309 CombineTo(N, ExtLoad);
9310 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
9311 AddToWorklist(ExtLoad.getNode());
9317 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
9318 ((!LegalOperations && !cast<LoadSDNode>(N0)->
isVolatile()) ||
9325 CombineTo(N, ExtLoad);
9326 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
9341 SDValue DAGCombiner::visitSIGN_EXTEND_VECTOR_INREG(
SDNode *N) {
9355 SDValue DAGCombiner::visitZERO_EXTEND_VECTOR_INREG(
SDNode *N) {
9431 if (isa<ConstantSDNode>(EltNo) && isTypeLegal(NVT)) {
9432 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
9434 int Index = isLE ? (Elt*SizeRatio) : (Elt*SizeRatio + (SizeRatio-1));
9490 if (BuildVectEltTy == TruncVecEltTy) {
9494 unsigned TruncEltOffset = BuildVecNumElts / TruncVecNumElts;
9496 assert((BuildVecNumElts % TruncVecNumElts) == 0 &&
9497 "Invalid number of elements");
9500 for (
unsigned i = 0, e = BuildVecNumElts; i != e; i += TruncEltOffset)
9522 if (
SDValue Reduced = ReduceLoadWidth(N))
9547 unsigned NumDefs = 0;
9568 assert(V.
getNode() &&
"The single defined operand is empty!");
9570 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
9577 Opnds.push_back(NV);
9591 (!LegalOperations ||
9604 SimplifyDemandedBits(
SDValue(N, 0)))
9636 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
9664 LD1->getAddressSpace() != LD2->getAddressSpace())
9666 EVT LD1VT = LD1->getValueType(0);
9670 unsigned Align = LD1->getAlignment();
9674 if (NewAlign <= Align &&
9676 return DAG.
getLoad(VT,
SDLoc(N), LD1->getChain(), LD1->getBasePtr(),
9677 LD1->getPointerInfo(),
Align);
9750 "Element type of vector ValueType must not be vector!");
9752 return ConstantFoldBITCASTofBUILD_VECTOR(N0.
getNode(), DestEltVT);
9818 AddToWorklist(NewConv.
getNode());
9828 AddToWorklist(FlipBit.
getNode());
9835 AddToWorklist(Hi.getNode());
9837 AddToWorklist(FlipBit.getNode());
9841 AddToWorklist(FlipBits.getNode());
9869 if (isTypeLegal(IntXVT)) {
9875 if (OrigXWidth < VTWidth) {
9878 }
else if (OrigXWidth > VTWidth) {
9888 AddToWorklist(X.getNode());
9894 AddToWorklist(Cst.getNode());
9896 AddToWorklist(X.getNode());
9898 AddToWorklist(XorResult.getNode());
9903 AddToWorklist(XorResult64.getNode());
9907 AddToWorklist(FlipBit.getNode());
9910 AddToWorklist(FlipBits.getNode());
9916 AddToWorklist(X.getNode());
9921 AddToWorklist(Cst.getNode());
9929 if (
SDValue CombineLD = CombineConsecutiveLoads(N0.
getNode(), VT))
9944 auto PeekThroughBitcast = [&](
SDValue Op) {
9966 for (
int i = 0; i != MaskScale; ++i)
9967 NewMask.
push_back(M < 0 ? -1 : M * MaskScale + i);
9985 return CombineConsecutiveLoads(N, VT);
9991 ConstantFoldBITCASTofBUILD_VECTOR(
SDNode *BV,
EVT DstEltVT) {
9995 if (SrcEltVT == DstEltVT)
return SDValue(BV, 0);
10002 if (SrcBitSize == DstBitSize) {
10031 BV = ConstantFoldBITCASTofBUILD_VECTOR(BV, IntVT).getNode();
10039 SDNode *Tmp = ConstantFoldBITCASTofBUILD_VECTOR(BV, TmpVT).getNode();
10042 return ConstantFoldBITCASTofBUILD_VECTOR(Tmp, DstEltVT);
10050 if (SrcBitSize < DstBitSize) {
10051 unsigned NumInputsPerOutput = DstBitSize/SrcBitSize;
10055 i += NumInputsPerOutput) {
10058 bool EltIsUndef =
true;
10059 for (
unsigned j = 0; j != NumInputsPerOutput; ++j) {
10061 NewBits <<= SrcBitSize;
10064 EltIsUndef =
false;
10066 NewBits |= cast<ConstantSDNode>(
Op)->getAPIntValue().
10067 zextOrTrunc(SrcBitSize).
zext(DstBitSize);
10082 unsigned NumOutputsPerInput = SrcBitSize/DstBitSize;
10093 APInt OpVal = cast<ConstantSDNode>(
Op)->
10096 for (
unsigned j = 0; j != NumOutputsPerInput; ++j) {
10098 Ops.push_back(DAG.
getConstant(ThisVal, DL, DstEltVT));
10104 std::reverse(Ops.end()-NumOutputsPerInput, Ops.end());
10133 if (!HasFMAD && !HasFMA)
10139 CanFuse || HasFMAD);
10154 auto isContractableFMUL = [AllowFusionGlobally](
SDValue N) {
10161 if (Aggressive && isContractableFMUL(N0) && isContractableFMUL(N1)) {
10167 if (isContractableFMUL(N0) && (Aggressive || N0->
hasOneUse())) {
10168 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10174 if (isContractableFMUL(N1) && (Aggressive || N1->
hasOneUse())) {
10175 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10184 if (isContractableFMUL(N00) &&
10186 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10198 if (isContractableFMUL(N10) &&
10200 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10212 N0.
getOpcode() == PreferredFusedOpcode &&
10215 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10217 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10220 N1, Flags), Flags);
10225 N1->
getOpcode() == PreferredFusedOpcode &&
10228 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10230 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10233 N0, Flags), Flags);
10239 auto FoldFAddFMAFPExtFMul = [&] (
10242 return DAG.
getNode(PreferredFusedOpcode, SL, VT, X, Y,
10243 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10248 if (N0.
getOpcode() == PreferredFusedOpcode) {
10252 if (isContractableFMUL(N020) &&
10266 auto FoldFAddFPExtFMAFMul = [&] (
10269 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10272 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10279 if (N00.
getOpcode() == PreferredFusedOpcode) {
10281 if (isContractableFMUL(N002) &&
10292 if (N1.
getOpcode() == PreferredFusedOpcode) {
10296 if (isContractableFMUL(N120) &&
10312 if (N10.
getOpcode() == PreferredFusedOpcode) {
10314 if (isContractableFMUL(N102) &&
10344 if (!HasFMAD && !HasFMA)
10350 CanFuse || HasFMAD);
10366 auto isContractableFMUL = [AllowFusionGlobally](
SDValue N) {
10373 if (isContractableFMUL(N0) && (Aggressive || N0->
hasOneUse())) {
10374 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10381 if (isContractableFMUL(N1) && (Aggressive || N1->
hasOneUse())) {
10382 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10393 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10404 if (isContractableFMUL(N00) &&
10406 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10420 if (isContractableFMUL(N10) &&
10422 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10442 if (isContractableFMUL(N000) &&
10445 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10465 if (isContractableFMUL(N000) &&
10468 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10482 if (CanFuse && N0.
getOpcode() == PreferredFusedOpcode &&
10485 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10487 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10491 N1), Flags), Flags);
10496 if (CanFuse && N1.
getOpcode() == PreferredFusedOpcode &&
10500 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10504 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10506 N21, N0, Flags), Flags);
10512 if (N0.
getOpcode() == PreferredFusedOpcode) {
10516 if (isContractableFMUL(N020) &&
10518 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10520 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10526 N1), Flags), Flags);
10539 if (N00.
getOpcode() == PreferredFusedOpcode) {
10541 if (isContractableFMUL(N002) &&
10543 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10548 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10554 N1), Flags), Flags);
10561 if (N1.
getOpcode() == PreferredFusedOpcode &&
10564 if (isContractableFMUL(N120) &&
10568 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10571 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10577 N0, Flags), Flags);
10593 if (isContractableFMUL(N102) &&
10597 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10602 DAG.
getNode(PreferredFusedOpcode, SL, VT,
10608 N0, Flags), Flags);
10619 SDValue DAGCombiner::visitFMULForFMADistributiveCombine(
SDNode *N) {
10632 if (!Options.NoInfsFPMath)
10643 bool HasFMAD = Options.UnsafeFPMath &&
10647 if (!HasFMAD && !HasFMA)
10659 if (XC1 && XC1->isExactlyValue(+1.0))
10662 if (XC1 && XC1->isExactlyValue(-1.0))
10681 if (XC0 && XC0->isExactlyValue(+1.0))
10682 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10685 if (XC0 && XC0->isExactlyValue(-1.0))
10686 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
10691 if (XC1 && XC1->isExactlyValue(+1.0))
10694 if (XC1 && XC1->isExactlyValue(-1.0))
10713 return CFP->isExactlyValue(-2.0);
10729 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
10733 if (N0CFP && N1CFP)
10737 if (N0CFP && !N1CFP)
10740 if (
SDValue NewSel = foldBinOpIntoSelect(N))
10766 if (N1C && N1C->
isZero()) {
10811 if (CFP01 && !CFP00 && N0.
getOperand(0) == N1) {
10832 if (CFP11 && !CFP10 && N1.
getOperand(0) == N0) {
10880 if (
SDValue Fused = visitFADDForFMACombine(N)) {
10881 AddToWorklist(Fused.getNode());
10899 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
10903 if (N0CFP && N1CFP)
10906 if (
SDValue NewSel = foldBinOpIntoSelect(N))
10910 if (N1CFP && N1CFP->
isZero()) {
10924 if (N0CFP && N0CFP->
isZero()) {
10955 if (
SDValue Fused = visitFSUBForFMACombine(N)) {
10956 AddToWorklist(Fused.getNode());
10976 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
10981 if (N0CFP && N1CFP)
10993 if (
SDValue NewSel = foldBinOpIntoSelect(N))
10999 if (N1CFP && N1CFP->
isZero())
11021 (BV1 && BV01 && BV1->isConstant() && BV01->isConstant())) {
11052 if (LHSNeg == 2 || RHSNeg == 2)
11073 if (TrueOpnd && FalseOpnd &&
11075 isa<ConstantFPSDNode>(Cond.
getOperand(1)) &&
11076 cast<ConstantFPSDNode>(Cond.
getOperand(1))->isExactlyValue(0.0)) {
11094 if (TrueOpnd->isExactlyValue(-1.0) && FalseOpnd->isExactlyValue(1.0) &&
11098 if (TrueOpnd->isExactlyValue(1.0) && FalseOpnd->isExactlyValue(-1.0))
11107 if (
SDValue Fused = visitFMULForFMADistributiveCombine(N)) {
11108 AddToWorklist(Fused.getNode());
11130 if (isa<ConstantFPSDNode>(N0) &&
11131 isa<ConstantFPSDNode>(N1) &&
11132 isa<ConstantFPSDNode>(N2)) {
11136 if (UnsafeFPMath) {
11137 if (N0CFP && N0CFP->
isZero())
11139 if (N1CFP && N1CFP->isZero())
11145 if (N1CFP && N1CFP->isExactlyValue(1.0))
11153 if (UnsafeFPMath) {
11178 if (N1CFP->isExactlyValue(1.0))
11182 if (N1CFP->isExactlyValue(-1.0) &&
11185 AddToWorklist(RHSNeg.
getNode());
11199 if (UnsafeFPMath) {
11201 if (N1CFP && N0 == N2) {
11227 SDValue DAGCombiner::combineRepeatedFPDivisors(
SDNode *N) {
11243 if (!MinUses || N1->
use_size() < MinUses)
11249 for (
auto *U : N1->
uses()) {
11250 if (U->getOpcode() ==
ISD::FDIV && U->getOperand(1) == N1) {
11253 if (UnsafeMath || U->getFlags().hasAllowReciprocal())
11260 if (Users.
size() < MinUses)
11269 for (
auto *U : Users) {
11271 if (Dividend != FPOne) {
11273 Reciprocal, Flags);
11274 CombineTo(U, NewNode);
11275 }
else if (U != Reciprocal.
getNode()) {
11278 CombineTo(U, Reciprocal);
11296 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
11300 if (N0CFP && N1CFP)
11303 if (
SDValue NewSel = foldBinOpIntoSelect(N))
11310 const APFloat &N1APF = N1CFP->getValueAPF();
11316 (!LegalOperations ||
11337 AddToWorklist(RV.getNode());
11345 AddToWorklist(RV.getNode());
11365 AddToWorklist(RV.getNode());
11372 if (
SDValue RV = BuildReciprocalEstimate(N1, Flags)) {
11373 AddToWorklist(RV.getNode());
11383 if (LHSNeg == 2 || RHSNeg == 2)
11391 if (
SDValue CombineRepeatedDivisors = combineRepeatedFPDivisors(N))
11392 return CombineRepeatedDivisors;
11405 if (N0CFP && N1CFP)
11408 if (
SDValue NewSel = foldBinOpIntoSelect(N))
11425 return buildSqrtEstimate(N0, Flags);
11440 return (N1VT == N1Op0VT || N1Op0VT !=
MVT::f128);
11452 if (N0CFP && N1CFP)
11456 const APFloat &V = N1CFP->getValueAPF();
11535 (!LegalOperations ||
11553 (!LegalOperations ||
11567 (!LegalOperations ||
11592 (!LegalOperations ||
11609 (!LegalOperations ||
11650 unsigned ActualSize = std::min(InputSize, OutputSize);
11735 AddToWorklist(Tmp.
getNode());
11740 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
11753 if (N0CFP && isTypeLegal(EVT)) {
11800 CombineTo(N, ExtLoad);
11809 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
11895 AddToWorklist(Int.
getNode());
11927 if (N0CFP && N1CFP) {
11948 if (N0CFP && N1CFP) {
12000 AddToWorklist(Int.
getNode());
12030 if (
SDValue NewN1 = rebuildSetCC(N1))
12070 const APInt &AndConst = cast<ConstantSDNode>(AndOp1)->getAPIntValue();
12073 cast<ConstantSDNode>(Op1)->getAPIntValue() == AndConst.
logBase2()) {
12114 bool Equal =
false;
12123 SetCCVT = getSetCCResultType(SetCCVT);
12146 SDValue Simp = SimplifySetCC(getSetCCResultType(CondLHS.getValueType()),
12147 CondLHS, CondRHS, CC->
get(),
SDLoc(N),
12170 if (
LD->isIndexed() ||
LD->getBasePtr().getNode() !=
N)
12172 VT =
LD->getMemoryVT();
12173 AS =
LD->getAddressSpace();
12175 if (
ST->isIndexed() ||
ST->getBasePtr().getNode() !=
N)
12177 VT =
ST->getMemoryVT();
12178 AS =
ST->getAddressSpace();
12211 bool DAGCombiner::CombineToPreIndexedLoadStore(
SDNode *N) {
12219 if (
LD->isIndexed())
12221 VT =
LD->getMemoryVT();
12225 Ptr =
LD->getBasePtr();
12227 if (
ST->isIndexed())
12229 VT =
ST->getMemoryVT();
12233 Ptr =
ST->getBasePtr();
12255 bool Swapped =
false;
12256 if (isa<ConstantSDNode>(BasePtr)) {
12275 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
12280 SDValue Val = cast<StoreSDNode>(
N)->getValue();
12294 if (isa<ConstantSDNode>(Offset))
12314 if (!isa<ConstantSDNode>(Op1)) {
12332 bool RealUse =
false;
12352 BasePtr, Offset, AM);
12355 BasePtr, Offset, AM);
12360 WorklistRemover DeadNodes(*
this);
12369 deleteAndRecombine(N);
12375 for (
unsigned i = 0, e = OtherUses.
size(); i != e; ++i) {
12376 unsigned OffsetIdx = 1;
12377 if (OtherUses[i]->getOperand(OffsetIdx).getNode() == BasePtr.
getNode())
12379 assert(OtherUses[i]->getOperand(!OffsetIdx).getNode() ==
12380 BasePtr.
getNode() &&
"Expected BasePtr operand");
12394 cast<ConstantSDNode>(OtherUses[i]->getOperand(OffsetIdx));
12395 int X0, X1, Y0, Y1;
12396 const APInt &Offset0 = CN->getAPIntValue();
12397 APInt Offset1 = cast<ConstantSDNode>(
Offset)->getAPIntValue();
12399 X0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 1) ? -1 : 1;
12400 Y0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 0) ? -1 : 1;
12406 APInt CNV = Offset0;
12407 if (X0 < 0) CNV = -CNV;
12408 if (X1 * Y0 * Y1 < 0) CNV = CNV + Offset1;
12409 else CNV = CNV - Offset1;
12411 SDLoc DL(OtherUses[i]);
12419 OtherUses[i]->getValueType(0), NewOp1, NewOp2);
12421 deleteAndRecombine(OtherUses[i]);
12426 deleteAndRecombine(Ptr.
getNode());
12427 AddToWorklist(Result.
getNode());
12436 bool DAGCombiner::CombineToPostIndexedLoadStore(
SDNode *N) {
12444 if (
LD->isIndexed())
12446 VT =
LD->getMemoryVT();
12450 Ptr =
LD->getBasePtr();
12452 if (
ST->isIndexed())
12454 VT =
ST->getMemoryVT();
12458 Ptr =
ST->getBasePtr();
12487 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
12491 bool TryNext =
false;
12499 bool RealUse =
false;
12519 BasePtr, Offset, AM)
12521 BasePtr, Offset, AM);
12522 ++PostIndexedNodes;
12527 WorklistRemover DeadNodes(*
this);
12536 deleteAndRecombine(N);
12541 deleteAndRecombine(Op);
12561 !cast<ConstantSDNode>(Inc)->isOpaque()) &&
12562 "Cannot split out indexing using opaque target constants");
12593 dbgs() <<
"\nWith chain: "; Chain.getNode()->dump(&DAG);
12595 WorklistRemover DeadNodes(*
this);
12597 AddUsersToWorklist(Chain.getNode());
12599 deleteAndRecombine(N);
12612 cast<ConstantSDNode>(LD->
getOperand(2))->isOpaque();
12619 Index = SplitIndexingFromLoad(LD);
12622 AddUsersToWorklist(N);
12627 dbgs() <<
" and 2 other values\n");
12628 WorklistRemover DeadNodes(*
this);
12632 deleteAndRecombine(N);
12648 return CombineTo(N, PrevST->
getOperand(1), Chain);
12669 SDValue BetterChain = FindBetterChain(N, Chain);
12672 if (Chain != BetterChain) {
12691 return CombineTo(N, ReplLoad.
getValue(0), Token);
12696 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
12701 if (SliceUpLoad(N))
12721 struct LoadedSlice {
12728 unsigned Loads = 0;
12729 unsigned Truncates = 0;
12730 unsigned CrossRegisterBanksCopies = 0;
12731 unsigned ZExts = 0;
12732 unsigned Shift = 0;
12734 Cost(
bool ForCodeSize =
false) : ForCodeSize(ForCodeSize) {}
12737 Cost(
const LoadedSlice &
LS,
bool ForCodeSize =
false)
12738 : ForCodeSize(ForCodeSize), Loads(1) {
12739 EVT TruncType = LS.Inst->getValueType(0);
12740 EVT LoadedType = LS.getLoadedType();
12741 if (TruncType != LoadedType &&
12742 !LS.DAG->getTargetLoweringInfo().isZExtFree(LoadedType, TruncType))
12750 void addSliceGain(
const LoadedSlice &LS) {
12754 LS.Inst->getValueType(0)))
12760 if (LS.canMergeExpensiveCrossRegisterBankCopy())
12761 ++CrossRegisterBanksCopies;
12765 Loads += RHS.Loads;
12766 Truncates += RHS.Truncates;
12767 CrossRegisterBanksCopies += RHS.CrossRegisterBanksCopies;
12768 ZExts += RHS.ZExts;
12769 Shift += RHS.Shift;
12774 return Loads == RHS.Loads && Truncates == RHS.Truncates &&
12775 CrossRegisterBanksCopies == RHS.CrossRegisterBanksCopies &&
12776 ZExts == RHS.ZExts && Shift == RHS.Shift;
12779 bool operator!=(
const Cost &RHS)
const {
return !(*
this == RHS); }
12781 bool operator<(
const Cost &RHS)
const {
12784 unsigned ExpensiveOpsLHS = Loads + CrossRegisterBanksCopies;
12785 unsigned ExpensiveOpsRHS = RHS.Loads + RHS.CrossRegisterBanksCopies;
12788 if (!ForCodeSize && ExpensiveOpsLHS != ExpensiveOpsRHS)
12789 return ExpensiveOpsLHS < ExpensiveOpsRHS;
12790 return (Truncates + ZExts + Shift + ExpensiveOpsLHS) <
12791 (RHS.Truncates + RHS.ZExts + RHS.Shift + ExpensiveOpsRHS);
12794 bool operator>(
const Cost &RHS)
const {
return RHS < *
this; }
12796 bool operator<=(
const Cost &RHS)
const {
return !(RHS < *
this); }
12798 bool operator>=(
const Cost &RHS)
const {
return !(*
this < RHS); }
12817 : Inst(Inst), Origin(Origin), Shift(Shift), DAG(DAG) {}
12822 APInt getUsedBits()
const {
12827 assert(Origin &&
"No original load to compare against.");
12829 assert(Inst &&
"This slice is not bound to an instruction");
12831 "Extracted slice is bigger than the whole type!");
12834 UsedBits = UsedBits.zext(BitWidth);
12835 UsedBits <<= Shift;
12840 unsigned getLoadedSize()
const {
12841 unsigned SliceSize = getUsedBits().countPopulation();
12842 assert(!(SliceSize & 0x7) &&
"Size is not a multiple of a byte.");
12843 return SliceSize / 8;
12848 EVT getLoadedType()
const {
12849 assert(DAG &&
"Missing context");
12857 unsigned Offset = getOffsetFromBase();
12859 Alignment =
MinAlign(Alignment, Alignment + Offset);
12864 bool isLegal()
const {
12866 if (!Origin || !Inst || !DAG)
12876 EVT SliceType = getLoadedType();
12900 if (TruncateType != SliceType &&
12910 uint64_t getOffsetFromBase()
const {
12911 assert(DAG &&
"Missing context.");
12913 assert(!(Shift & 0x7) &&
"Shifts not aligned on Bytes are not supported.");
12914 uint64_t
Offset = Shift / 8;
12917 "The size of the original loaded type is not a multiple of a" 12921 assert(TySizeInBytes > Offset &&
12922 "Invalid shift amount for given loaded size");
12924 Offset = TySizeInBytes - Offset - getLoadedSize();
12935 assert(Inst && Origin &&
"Unable to replace a non-existing slice.");
12937 SDValue BaseAddr = OldBaseAddr;
12939 int64_t
Offset =
static_cast<int64_t
>(getOffsetFromBase());
12940 assert(Offset >= 0 &&
"Offset too big to fit in int64_t!");
12950 EVT SliceType = getLoadedType();
12960 if (SliceType != FinalType)
12970 bool canMergeExpensiveCrossRegisterBankCopy()
const {
12976 assert(DAG &&
"Missing context");
13035 const LoadedSlice &Second) {
13036 assert(First.Origin == Second.Origin && First.Origin &&
13037 "Unable to match different memory origins.");
13038 APInt UsedBits = First.getUsedBits();
13039 assert((UsedBits & Second.getUsedBits()) == 0 &&
13040 "Slices are not supposed to overlap.");
13041 UsedBits |= Second.getUsedBits();
13050 LoadedSlice::Cost &GlobalLSCost) {
13051 unsigned NumberOfSlices = LoadedSlices.
size();
13053 if (NumberOfSlices < 2)
13059 [](
const LoadedSlice &LHS,
const LoadedSlice &RHS) {
13060 assert(LHS.Origin == RHS.Origin &&
"Different bases not implemented.");
13061 return LHS.getOffsetFromBase() < RHS.getOffsetFromBase();
13063 const TargetLowering &TLI = LoadedSlices[0].DAG->getTargetLoweringInfo();
13066 const LoadedSlice *First =
nullptr;
13067 const LoadedSlice *Second =
nullptr;
13068 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice,
13071 Second = &LoadedSlices[CurrSlice];
13078 EVT LoadedType = First->getLoadedType();
13081 if (LoadedType != Second->getLoadedType())
13085 unsigned RequiredAlignment = 0;
13086 if (!TLI.hasPairedLoad(LoadedType, RequiredAlignment)) {
13092 if (RequiredAlignment > First->getAlignment())
13099 assert(GlobalLSCost.Loads > 0 &&
"We save more loads than we created!");
13100 --GlobalLSCost.Loads;
13117 const APInt &UsedBits,
bool ForCodeSize) {
13118 unsigned NumberOfSlices = LoadedSlices.
size();
13120 return NumberOfSlices > 1;
13123 if (NumberOfSlices != 2)
13131 LoadedSlice::Cost OrigCost(ForCodeSize), GlobalSlicingCost(ForCodeSize);
13133 OrigCost.Loads = 1;
13134 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice) {
13135 const LoadedSlice &
LS = LoadedSlices[CurrSlice];
13137 LoadedSlice::Cost SliceCost(LS, ForCodeSize);
13138 GlobalSlicingCost += SliceCost;
13142 OrigCost.addSliceGain(LS);
13147 return OrigCost > GlobalSlicingCost;
13156 bool DAGCombiner::SliceUpLoad(
SDNode *N) {
13175 UI != UIEnd; ++UI) {
13177 if (UI.getUse().getResNo() != 0)
13181 unsigned Shift = 0;
13204 LoadedSlice
LS(User, LD, Shift, &DAG);
13205 APInt CurrentUsedBits = LS.getUsedBits();
13208 if ((CurrentUsedBits & UsedBits) != 0)
13211 UsedBits |= CurrentUsedBits;
13218 LoadedSlices.push_back(LS);
13233 LSIt = LoadedSlices.begin(),
13234 LSItEnd = LoadedSlices.end();
13235 LSIt != LSItEnd; ++LSIt) {
13236 SDValue SliceInst = LSIt->loadSlice();
13237 CombineTo(LSIt->Inst, SliceInst,
true);
13241 "It takes more than a zext to get to the loaded slice!!");
13248 AddToWorklist(Chain.
getNode());
13255 static std::pair<unsigned, unsigned>
13257 std::pair<unsigned, unsigned>
Result(0, 0);
13278 uint64_t NotMask = ~cast<ConstantSDNode>(V->
getOperand(1))->getSExtValue();
13280 if (NotMaskLZ & 7)
return Result;
13282 if (NotMaskTZ & 7)
return Result;
13283 if (NotMaskLZ == 64)
return Result;
13294 switch (MaskedBytes) {
13298 default:
return Result;
13303 if (NotMaskTZ && NotMaskTZ/8 % MaskedBytes)
return Result;
13314 if (ChainOp.getNode() ==
LD) {
13323 Result.first = MaskedBytes;
13324 Result.second = NotMaskTZ/8;
13335 unsigned NumBytes = MaskInfo.first;
13336 unsigned ByteShift = MaskInfo.second;
13342 ByteShift*8, (ByteShift+NumBytes)*8);
13349 if (!DC->isTypeLegal(VT))
13366 StOffset = ByteShift;
13375 NewAlign =
MinAlign(NewAlign, StOffset);
13413 std::pair<unsigned, unsigned> MaskedLoad;
13415 if (MaskedLoad.first)
13422 if (MaskedLoad.first)
13444 APInt Imm = cast<ConstantSDNode>(N1)->getAPIntValue();
13455 while (NewBW < BitWidth &&
13462 if (NewBW >= BitWidth)
13468 ShAmt = (((ShAmt + NewBW - 1) / NewBW) * NewBW) - NewBW;
13470 std::min(BitWidth, ShAmt + NewBW));
13471 if ((Imm & Mask) == Imm) {
13475 uint64_t PtrOff = ShAmt / 8;
13479 PtrOff = (BitWidth + 7 - NewBW) / 8 - PtrOff;
13501 AddToWorklist(NewPtr.
getNode());
13502 AddToWorklist(NewLD.
getNode());
13503 AddToWorklist(NewVal.
getNode());
13504 WorklistRemover DeadNodes(*
this);
13526 if (!VT.isFloatingPoint() ||
13545 if (LDAlign < ABIAlign || STAlign < ABIAlign)
13556 AddToWorklist(NewLD.
getNode());
13557 AddToWorklist(NewST.
getNode());
13558 WorklistRemover DeadNodes(*
this);
13580 bool DAGCombiner::isMulAddWithConstProfitable(
SDNode *MulNode,
13591 if (
Use == MulNode)
13599 if (
Use->getOperand(0) == ConstNode)
13600 OtherOp =
Use->getOperand(1).getNode();
13602 OtherOp =
Use->getOperand(0).getNode();
13614 if (OtherOp == MulVar)
13642 unsigned NumStores) {
13645 SDLoc StoreDL(StoreNodes[0].MemNode);
13647 for (
unsigned i = 0; i < NumStores; ++i) {
13648 Visited.
insert(StoreNodes[i].MemNode);
13652 for (
unsigned i = 0; i < NumStores; ++i) {
13653 if (Visited.
count(StoreNodes[i].MemNode->getChain().getNode()) == 0)
13654 Chains.
push_back(StoreNodes[i].MemNode->getChain());
13657 assert(Chains.
size() > 0 &&
"Chain should have generated a chain");
13661 bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
13663 bool IsConstantSrc,
bool UseVector,
bool UseTrunc) {
13669 SDLoc DL(StoreNodes[0].MemNode);
13672 unsigned SizeInBits = NumStores * ElementSizeBits;
13677 unsigned Elts = NumStores * NumMemElts;
13685 if (IsConstantSrc) {
13687 for (
unsigned I = 0;
I != NumStores; ++
I) {
13688 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[
I].MemNode);
13691 if (MemVT != Val.getValueType()) {
13694 if (ElementSizeBits != Val.getValueSizeInBits()) {
13697 if (isa<ConstantFPSDNode>(Val)) {
13700 }
else if (
auto *
C = dyn_cast<ConstantSDNode>(Val))
13702 .zextOrTrunc(Val.getValueSizeInBits())
13703 .zextOrTrunc(ElementSizeBits),
13713 DL, StoreTy, BuildVector);
13716 for (
unsigned i = 0; i < NumStores; ++i) {
13717 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
13725 if ((MemVT != Val.getValueType()) &&
13753 assert(IsConstantSrc &&
"Merged vector elements should use vector store");
13755 APInt StoreInt(SizeInBits, 0);
13760 for (
unsigned i = 0; i < NumStores; ++i) {
13761 unsigned Idx = IsLE ? (NumStores - 1 - i) : i;
13762 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[Idx].MemNode);
13764 SDValue Val = St->getValue();
13766 StoreInt <<= ElementSizeBits;
13768 StoreInt |=
C->getAPIntValue()
13769 .zextOrTrunc(ElementSizeBits)
13770 .zextOrTrunc(SizeInBits);
13772 StoreInt |=
C->getValueAPF()
13774 .zextOrTrunc(ElementSizeBits)
13775 .zextOrTrunc(SizeInBits);
13785 StoredVal = DAG.
getConstant(StoreInt, DL, StoreTy);
13789 SDValue NewChain = getMergeStoreChains(StoreNodes, NumStores);
13798 EVT LegalizedStoredValTy =
13800 unsigned LegalizedStoreSize = LegalizedStoredValTy.
getSizeInBits();
13804 LegalizedStoredValTy);
13806 NewChain, DL, ExtendedStoreVal, FirstInChain->
getBasePtr(),
13813 for (
unsigned i = 0; i < NumStores; ++i)
13814 CombineTo(StoreNodes[i].MemNode, NewStore);
13816 AddToWorklist(NewChain.
getNode());
13820 void DAGCombiner::getStoreMergeCandidates(
13837 bool IsConstantSrc = isa<ConstantSDNode>(Val) || isa<ConstantFPSDNode>(Val);
13840 bool IsLoadSrc = isa<LoadSDNode>(Val);
13845 auto *Ld = cast<LoadSDNode>(Val);
13847 LoadVT = Ld->getMemoryVT();
13849 if (MemVT != LoadVT)
13852 if (!Ld->hasNUsesOfValue(1, 0))
13855 if (Ld->isVolatile() || Ld->isIndexed())
13859 int64_t &
Offset) ->
bool {
13870 if (
LoadSDNode *OtherLd = dyn_cast<LoadSDNode>(Val)) {
13872 if (LoadVT != OtherLd->getMemoryVT())
13875 if (!OtherLd->hasNUsesOfValue(1, 0))
13878 if (OtherLd->isVolatile() || OtherLd->isIndexed())
13880 if (!(LBasePtr.equalBaseIndex(LPtr, DAG)))
13885 if (IsConstantSrc) {
13888 if (!(isa<ConstantSDNode>(Val) || isa<ConstantFPSDNode>(Val)))
13891 if (IsExtractVecSrc) {
13923 if (
LoadSDNode *Ldn = dyn_cast<LoadSDNode>(RootNode)) {
13924 RootNode = Ldn->getChain().getNode();
13926 if (
I.getOperandNo() == 0 && isa<LoadSDNode>(*I))
13927 for (
auto I2 = (*I)->use_begin(), E2 = (*I)->use_end(); I2 != E2; ++I2)
13928 if (I2.getOperandNo() == 0)
13929 if (
StoreSDNode *OtherST = dyn_cast<StoreSDNode>(*I2)) {
13932 if (CandidateMatch(OtherST, Ptr, PtrDiff))
13933 StoreNodes.
push_back(MemOpLink(OtherST, PtrDiff));
13937 if (
I.getOperandNo() == 0)
13938 if (
StoreSDNode *OtherST = dyn_cast<StoreSDNode>(*
I)) {
13941 if (CandidateMatch(OtherST, Ptr, PtrDiff))
13942 StoreNodes.
push_back(MemOpLink(OtherST, PtrDiff));
13951 bool DAGCombiner::checkMergeStoreCandidatesForDependencies(
13967 while (!Worklist.
empty()) {
13977 unsigned int Max = 1024 + Visited.
size();
13979 for (
unsigned i = 0; i < NumStores; ++i) {
13980 SDNode *N = StoreNodes[i].MemNode;
13992 if (Visited.
insert(Op).second)
13996 for (
unsigned i = 0; i < NumStores; ++i)
14003 bool DAGCombiner::MergeConsecutiveStores(
StoreSDNode *St) {
14015 Attribute::NoImplicitFloat);
14027 bool IsLoadSrc = isa<LoadSDNode>(StoredVal);
14028 bool IsConstantSrc = isa<ConstantSDNode>(StoredVal) ||
14029 isa<ConstantFPSDNode>(StoredVal);
14033 if (!IsConstantSrc && !IsLoadSrc && !IsExtractVecSrc)
14039 getStoreMergeCandidates(St, StoreNodes, RootNode);
14042 if (StoreNodes.
size() < 2)
14048 [](MemOpLink LHS, MemOpLink RHS) {
14049 return LHS.OffsetFromBase < RHS.OffsetFromBase;
14061 while (StoreNodes.
size() > 1) {
14062 unsigned StartIdx = 0;
14063 while ((StartIdx + 1 < StoreNodes.
size()) &&
14064 StoreNodes[StartIdx].OffsetFromBase + ElementSizeBytes !=
14065 StoreNodes[StartIdx + 1].OffsetFromBase)
14069 if (StartIdx + 1 >= StoreNodes.
size())
14077 unsigned NumConsecutiveStores = 1;
14078 int64_t StartAddress = StoreNodes[0].OffsetFromBase;
14081 for (
unsigned i = 1, e = StoreNodes.
size(); i < e; ++i) {
14082 int64_t CurrAddress = StoreNodes[i].OffsetFromBase;
14083 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
14085 NumConsecutiveStores = i + 1;
14088 if (NumConsecutiveStores < 2) {
14090 StoreNodes.
begin() + NumConsecutiveStores);
14099 if (IsConstantSrc) {
14100 while (NumConsecutiveStores >= 2) {
14103 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
14104 unsigned LastLegalType = 1;
14105 unsigned LastLegalVectorType = 1;
14106 bool LastIntegerTrunc =
false;
14107 bool NonZero =
false;
14108 unsigned FirstZeroAfterNonZero = NumConsecutiveStores;
14109 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
14110 StoreSDNode *
ST = cast<StoreSDNode>(StoreNodes[i].MemNode);
14112 bool IsElementZero =
false;
14114 IsElementZero =
C->isNullValue();
14116 IsElementZero =
C->getConstantFPValue()->isNullValue();
14117 if (IsElementZero) {
14118 if (NonZero && FirstZeroAfterNonZero == NumConsecutiveStores)
14119 FirstZeroAfterNonZero = i;
14121 NonZero |= !IsElementZero;
14124 unsigned SizeInBits = (i + 1) * ElementSizeBytes * 8;
14126 bool IsFast =
false;
14135 FirstStoreAlign, &IsFast) &&
14137 LastIntegerTrunc =
false;
14138 LastLegalType = i + 1;
14142 EVT LegalizedStoredValTy =
14147 FirstStoreAlign, &IsFast) &&
14149 LastIntegerTrunc =
true;
14150 LastLegalType = i + 1;
14161 unsigned Elts = (i + 1) * NumMemElts;
14166 FirstStoreAlign, &IsFast) &&
14168 LastLegalVectorType = i + 1;
14172 bool UseVector = (LastLegalVectorType > LastLegalType) && !NoVectors;
14173 unsigned NumElem = (UseVector) ? LastLegalVectorType : LastLegalType;
14185 unsigned NumSkip = 1;
14187 (NumSkip < NumConsecutiveStores) &&
14188 (NumSkip < FirstZeroAfterNonZero) &&
14189 (StoreNodes[NumSkip].MemNode->getAlignment() <= FirstStoreAlign))
14193 NumConsecutiveStores -= NumSkip;
14198 if (!checkMergeStoreCandidatesForDependencies(StoreNodes, NumElem,
14201 NumConsecutiveStores -= NumElem;
14205 RV |= MergeStoresOfConstantsOrVecElts(StoreNodes, MemVT, NumElem,
true,
14206 UseVector, LastIntegerTrunc);
14210 NumConsecutiveStores -= NumElem;
14217 if (IsExtractVecSrc) {
14219 while (NumConsecutiveStores >= 2) {
14222 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
14223 unsigned NumStoresToMerge = 1;
14224 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
14226 unsigned Elts = (i + 1) * NumMemElts;
14238 FirstStoreAlign, &IsFast) &&
14240 NumStoresToMerge = i + 1;
14245 if (NumStoresToMerge < 2) {
14252 unsigned NumSkip = 1;
14254 (NumSkip < NumConsecutiveStores) &&
14255 (StoreNodes[NumSkip].MemNode->getAlignment() <= FirstStoreAlign))
14259 NumConsecutiveStores -= NumSkip;
14264 if (!checkMergeStoreCandidatesForDependencies(
14265 StoreNodes, NumStoresToMerge, RootNode)) {
14267 StoreNodes.
begin() + NumStoresToMerge);
14268 NumConsecutiveStores -= NumStoresToMerge;
14272 RV |= MergeStoresOfConstantsOrVecElts(
14273 StoreNodes, MemVT, NumStoresToMerge,
false,
true,
false);
14276 StoreNodes.
begin() + NumStoresToMerge);
14277 NumConsecutiveStores -= NumStoresToMerge;
14293 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
14294 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
14300 int64_t LdOffset = 0;
14311 LoadNodes.
push_back(MemOpLink(Ld, LdOffset));
14314 while (NumConsecutiveStores >= 2 && LoadNodes.
size() >= 2) {
14317 unsigned RequiredAlignment;
14318 if (LoadNodes.
size() == 2 &&
14320 StoreNodes[0].MemNode->getAlignment() >= RequiredAlignment) {
14327 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
14328 LoadSDNode *FirstLoad = cast<LoadSDNode>(LoadNodes[0].MemNode);
14336 unsigned LastConsecutiveLoad = 1;
14339 unsigned LastLegalVectorType = 1;
14340 unsigned LastLegalIntegerType = 1;
14341 bool isDereferenceable =
true;
14342 bool DoIntegerTruncate =
false;
14343 StartAddress = LoadNodes[0].OffsetFromBase;
14345 for (
unsigned i = 1; i < LoadNodes.
size(); ++i) {
14347 if (LoadNodes[i].MemNode->getChain() != FirstChain)
14350 int64_t CurrAddress = LoadNodes[i].OffsetFromBase;
14351 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
14353 LastConsecutiveLoad = i;
14355 if (isDereferenceable && !LoadNodes[i].MemNode->isDereferenceable())
14356 isDereferenceable =
false;
14359 unsigned Elts = (i + 1) * NumMemElts;
14366 bool IsFastSt, IsFastLd;
14370 FirstStoreAlign, &IsFastSt) &&
14373 FirstLoadAlign, &IsFastLd) &&
14375 LastLegalVectorType = i + 1;
14379 unsigned SizeInBits = (i + 1) * ElementSizeBytes * 8;
14384 FirstStoreAlign, &IsFastSt) &&
14387 FirstLoadAlign, &IsFastLd) &&
14389 LastLegalIntegerType = i + 1;
14390 DoIntegerTruncate =
false;
14403 FirstStoreAlign, &IsFastSt) &&
14406 FirstLoadAlign, &IsFastLd) &&
14408 LastLegalIntegerType = i + 1;
14409 DoIntegerTruncate =
true;
14417 LastLegalVectorType > LastLegalIntegerType && !NoVectors;
14418 unsigned LastLegalType =
14419 std::max(LastLegalVectorType, LastLegalIntegerType);
14424 std::min(NumConsecutiveStores, LastConsecutiveLoad + 1);
14425 NumElem = std::min(LastLegalType, NumElem);
14435 unsigned NumSkip = 1;
14436 while ((NumSkip < LoadNodes.
size()) &&
14437 (LoadNodes[NumSkip].MemNode->getAlignment() <= FirstLoadAlign) &&
14438 (StoreNodes[NumSkip].MemNode->getAlignment() <= FirstStoreAlign))
14442 NumConsecutiveStores -= NumSkip;
14447 if (!checkMergeStoreCandidatesForDependencies(StoreNodes, NumElem,
14451 NumConsecutiveStores -= NumElem;
14460 unsigned Elts = NumElem * NumMemElts;
14463 unsigned SizeInBits = NumElem * ElementSizeBytes * 8;
14467 SDLoc LoadDL(LoadNodes[0].MemNode);
14468 SDLoc StoreDL(StoreNodes[0].MemNode);
14473 SDValue NewStoreChain = getMergeStoreChains(StoreNodes, NumElem);
14474 AddToWorklist(NewStoreChain.
getNode());
14481 if (UseVectorTy || !DoIntegerTruncate) {
14485 FirstLoadAlign, MMOFlags);
14487 NewStoreChain, StoreDL, NewLoad, FirstInChain->
getBasePtr(),
14495 FirstLoadAlign, MMOFlags);
14496 NewStore = DAG.
getTruncStore(NewStoreChain, StoreDL, NewLoad,
14504 for (
unsigned i = 0; i < NumElem; ++i) {
14505 LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[i].MemNode);
14512 for (
unsigned i = 0; i < NumElem; ++i) {
14513 SDValue Val = StoreNodes[i].MemNode->getOperand(1);
14514 CombineTo(StoreNodes[i].MemNode, NewStore);
14516 recursivelyDeleteUnusedNodes(Val.
getNode());
14522 NumConsecutiveStores -= NumElem;
14547 AddToWorklist(Token.
getNode());
14550 return CombineTo(ST, Token,
false);
14584 bitcastToAPInt().getZExtValue(),
SDLoc(CFP),
14597 return DAG.
getStore(Chain, DL, Tmp,
14620 Alignment =
MinAlign(Alignment, 4U);
14623 Alignment, MMOFlags, AAInfo);
14643 if (((!LegalOperations && !ST->
isVolatile()) ||
14679 if (
SDValue NewST = TransformFPLoadStorePair(N))
14685 if (findBetterNeighborChains(ST)) {
14702 AddToWorklist(Value.
getNode());
14709 if (SimplifyDemandedBits(
14725 if (
LoadSDNode *Ld = dyn_cast<LoadSDNode>(Value)) {
14726 if (Ld->getBasePtr() == Ptr && ST->
getMemoryVT() == Ld->getMemoryVT() &&
14730 Chain.reachesChainWithoutSideEffects(
SDValue(Ld, 1))) {
14736 if (
StoreSDNode *ST1 = dyn_cast<StoreSDNode>(Chain)) {
14738 !ST1->isVolatile() && ST1->getBasePtr() == Ptr &&
14742 if (ST1->getValue() == Value) {
14752 !ST1->getBasePtr().isUndef()) {
14755 CombineTo(ST1, ST1->getChain());
14779 bool Changed = MergeConsecutiveStores(ST);
14780 if (!Changed)
break;
14789 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
14797 if (isa<ConstantFPSDNode>(ST->
getValue())) {
14798 if (
SDValue NewSt = replaceStoreOfFPConstant(ST))
14805 return ReduceLoadOpStoreWidth(N);
14910 Alignment / 2, MMOFlags, AAInfo);
14919 SDValue DAGCombiner::combineInsertEltToShuffle(
SDNode *N,
unsigned InsIndex) {
14931 unsigned NumMaskVals = ExtendRatio * NumSrcElts;
14939 for (
unsigned i = 0; i != NumMaskVals; ++i) {
14940 if (i / NumSrcElts == InsIndex)
14941 Mask[i] = (i % NumSrcElts) + NumMaskVals;
14956 ConcatOps[0] = SubVec;
14962 AddToWorklist(PaddedSubV.
getNode());
14963 AddToWorklist(DestVecBC.
getNode());
14964 AddToWorklist(Shuf.
getNode());
14990 unsigned Elt = IndexC->getZExtValue();
14992 if (
SDValue Shuf = combineInsertEltToShuffle(N, Elt))
15003 && isa<ConstantSDNode>(InVec.getOperand(2))) {
15004 unsigned OtherElt = InVec.getConstantOperandVal(2);
15005 if (Elt < OtherElt) {
15008 InVec.getOperand(0), InVal, EltNo);
15009 AddToWorklist(NewOp.
getNode());
15026 Ops.
append(InVec.getNode()->op_begin(),
15027 InVec.getNode()->op_end());
15028 }
else if (InVec.isUndef()) {
15036 if (Elt < Ops.
size()) {
15039 EVT OpVT = Ops[0].getValueType();
15047 SDValue DAGCombiner::ReplaceExtractVectorEltOfLoadWithNarrowedLoad(
15072 if (
auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo)) {
15073 int Elt = ConstEltNo->getZExtValue();
15094 if (ResultVT.bitsGT(VecEltVT)) {
15102 OriginalLoad->
getChain(), NewPtr, MPI, VecEltVT,
15111 if (ResultVT.bitsLT(VecEltVT))
15116 WorklistRemover DeadNodes(*
this);
15122 AddToWorklist(Load.
getNode());
15123 AddUsersToWorklist(Load.
getNode());
15125 AddToWorklist(EVE);
15168 if (NVT == InEltVT)
15213 if (OrigElt < NumElem) {
15217 OrigElt -= NumElem;
15233 if (!LegalOperations ||
15247 Use->getOperand(0) == InVec &&
15248 isa<ConstantSDNode>(
Use->getOperand(1));
15252 auto *CstElt = cast<ConstantSDNode>(
Use->getOperand(1));
15254 DemandedElts.
setBit(CstElt->getZExtValue());
15256 if (SimplifyDemandedVectorElts(InVec, DemandedElts,
true))
15260 bool BCNumEltsChanged =
false;
15278 BCNumEltsChanged =
true;
15284 if (!LegalOperations && !ConstEltNo && InVec.
hasOneUse() &&
15288 if (
LoadSDNode *OrigLoad = dyn_cast<LoadSDNode>(InVec)) {
15289 if (!OrigLoad->isVolatile()) {
15290 return ReplaceExtractVectorEltOfLoadWithNarrowedLoad(N, VT, Index,
15298 if (!LegalOperations)
return SDValue();
15305 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
15310 LN0 = cast<LoadSDNode>(InVec);
15318 LN0 = cast<LoadSDNode>(InVec.
getOperand(0));
15319 }
else if ((SVN = dyn_cast<ShuffleVectorSDNode>(InVec))) {
15330 if (BCNumEltsChanged)
15335 int Idx = (Elt > (int)NumElems) ? -1 : SVN->
getMaskElt(Elt);
15346 LN0 = cast<LoadSDNode>(InVec);
15347 Elt = (Idx < (int)NumElems) ? Idx : Idx - (int)NumElems;
15361 return ReplaceExtractVectorEltOfLoadWithNarrowedLoad(N, VT, EltNo, LN0);
15368 SDValue DAGCombiner::reduceBuildVecExtToExtBuildVec(
SDNode *N) {
15388 bool AllAnyExt =
true;
15390 for (
unsigned i = 0; i != NumInScalars; ++i) {
15399 if (!ZeroExt && !AnyExt) {
15411 else if (InTy != SourceType) {
15418 AllAnyExt &= AnyExt;
15425 bool ValidTypes = SourceType !=
MVT::Other &&
15436 assert(ElemRatio > 1 &&
"Invalid element size ratio");
15448 Cast.
isUndef()) &&
"Invalid cast opcode");
15454 unsigned Index = isLE ? (i * ElemRatio) :
15455 (i * ElemRatio + (ElemRatio - 1));
15457 assert(Index < Ops.
size() &&
"Invalid index");
15464 "Invalid vector size");
15466 if (!isTypeLegal(VecVT) ||
15480 SDValue DAGCombiner::reduceBuildVecConvertToConvertBuildVec(
SDNode *N) {
15488 unsigned NumDefs = 0;
15490 for (
unsigned i = 0; i != NumInScalars; ++i) {
15523 &&
"Should only handle conversion from integer to float.");
15533 if (!isTypeLegal(NVT))
15537 for (
unsigned i = 0; i != NumInScalars; ++i) {
15548 return DAG.
getNode(Opcode, DL, VT, BV);
15554 unsigned LeftIdx) {
15562 unsigned Vec2Offset = 0;
15564 unsigned ShuffleNumElems = NumElems;
15576 if (InVT1 != VT || InVT2 != VT) {
15581 assert(NumConcats >= 2 &&
"Concat needs at least two inputs!");
15583 ConcatOps[0] = VecIn1;
15584 ConcatOps[1] = VecIn2 ? VecIn2 : DAG.
getUNDEF(InVT1);
15599 Vec2Offset = NumElems;
15605 if (LegalOperations &&
15612 if (InVT1 != InVT2) {
15616 DAG.
getUNDEF(InVT1), VecIn2, ZeroIdx);
15618 ShuffleNumElems = NumElems * 2;
15628 ConcatOps[0] = VecIn2;
15645 for (
unsigned i = 0; i != NumElems; ++i) {
15646 if (VectorMask[i] <= 0)
15650 if (VectorMask[i] == (
int)LeftIdx) {
15651 Mask[i] = ExtIndex;
15652 }
else if (VectorMask[i] == (
int)LeftIdx + 1) {
15653 Mask[i] = Vec2Offset + ExtIndex;
15666 if (ShuffleNumElems > NumElems)
15680 if (!isTypeLegal(VT))
15687 bool UsesZeroVector =
false;
15700 for (
unsigned i = 0; i != NumElems; ++i) {
15710 UsesZeroVector =
true;
15722 APInt ExtractIdx = cast<ConstantSDNode>(Op.
getOperand(1))->getAPIntValue();
15734 unsigned Idx = std::distance(
15736 if (Idx == VecIn.
size())
15739 VectorMask[i] = Idx;
15743 if (VecIn.
size() < 2)
15750 if (VecIn.
size() == 2) {
15751 unsigned MaxIndex = 0;
15752 unsigned NearestPow2 = 0;
15758 for (
unsigned i = 0; i < NumElems; i++) {
15759 if (VectorMask[i] <= 0)
15762 IndexVec[i] =
Index;
15763 MaxIndex =
std::max(MaxIndex, Index);
15767 if (InVT.
isSimple() && NearestPow2 > 2 && MaxIndex < NearestPow2 &&
15768 NumElems * 2 < NearestPow2) {
15769 unsigned SplitSize = NearestPow2 / 2;
15781 for (
unsigned i = 0; i < NumElems; i++) {
15782 if (VectorMask[i] <= 0)
15784 VectorMask[i] = (IndexVec[i] < SplitSize) ? 1 : 2;
15810 for (
unsigned In = 0, Len = (VecIn.
size() / 2);
In < Len; ++
In) {
15811 unsigned LeftIdx = 2 *
In + 1;
15812 SDValue VecLeft = VecIn[LeftIdx];
15814 (LeftIdx + 1) < VecIn.
size() ? VecIn[LeftIdx + 1] :
SDValue();
15816 if (
SDValue Shuffle = createBuildVecShuffle(DL, N, VectorMask, VecLeft,
15817 VecRight, LeftIdx))
15825 if (UsesZeroVector)
15830 if (Shuffles.
size() == 1)
15831 return Shuffles[0];
15834 for (
int &Vec : VectorMask)
15836 Vec = Shuffles.
size() - 1;
15838 Vec = (Vec - 1) / 2;
15852 if (Shuffles.
size() % 2)
15855 for (
unsigned CurSize = Shuffles.
size(); CurSize > 1; CurSize /= 2) {
15857 Shuffles[CurSize] = DAG.
getUNDEF(VT);
15860 for (
unsigned In = 0, Len = CurSize / 2;
In < Len; ++
In) {
15864 for (
unsigned i = 0; i != NumElems; ++i) {
15865 if (VectorMask[i] == Left) {
15867 VectorMask[i] =
In;
15868 }
else if (VectorMask[i] == Right) {
15869 Mask[i] = i + NumElems;
15870 VectorMask[i] =
In;
15878 return Shuffles[0];
15886 SDValue DAGCombiner::convertBuildVecZextToZext(
SDNode *N) {
15887 if (LegalOperations)
15893 auto checkElem = [&](
SDValue Op) -> int64_t {
15898 return C->getZExtValue();
15904 int64_t
Offset = checkElem(Op0);
15918 for (
unsigned i = 1; i != NumElems; ++i) {
15919 if ((Offset + i) != checkElem(N->
getOperand(i)))
15944 if (!LegalOperations) {
15947 EVT SrcVT = Splat.getValueType();
15965 auto checkElem = [&](
SDValue Op) -> uint64_t {
15968 if (
auto CNode = dyn_cast<ConstantSDNode>(Op.
getOperand(1)))
15969 return CNode->getZExtValue();
15973 int Offset = checkElem(Op0);
15975 if (Offset + i != checkElem(N->
getOperand(i))) {
15981 if ((Offset == 0) &&
15984 if ((Offset != -1) &&
15991 if (
SDValue V = convertBuildVecZextToZext(N))
15994 if (
SDValue V = reduceBuildVecExtToExtBuildVec(N))
15997 if (
SDValue V = reduceBuildVecConvertToConvertBuildVec(N))
16000 if (
SDValue V = reduceBuildVecToShuffle(N))
16022 bool AnyInteger =
false;
16023 bool AnyFP =
false;
16086 Mask.
append((
unsigned)NumOpElts, -1);
16105 Mask.
append((
unsigned)NumOpElts, -1);
16120 if (0 == (NumExtElts % NumElts))
16121 ExtIdx /= (NumExtElts / NumElts);
16122 else if (0 == (NumElts % NumExtElts))
16123 ExtIdx *= (NumElts / NumExtElts);
16128 if (SV0.
isUndef() || SV0 == ExtVec) {
16130 for (
int i = 0; i != NumOpElts; ++i)
16132 }
else if (SV1.isUndef() || SV1 == ExtVec) {
16134 for (
int i = 0; i != NumOpElts; ++i)
16188 if (VNTNumElms < 2)
16204 auto IsBuildVectorOrUndef = [](
const SDValue &
Op) {
16215 bool FoundMinVT =
false;
16219 MinVT = (!FoundMinVT || OpSVT.
bitsLE(MinVT)) ? OpSVT : MinVT;
16222 assert(FoundMinVT &&
"Concat vector type mismatch");
16237 for (
unsigned i = 0; i != NumElts; ++i)
16245 "Concat vector type mismatch");
16276 if (SingleSource.
getNode()) {
16289 unsigned IdentityIndex = i * PartNumElem;
16301 return SingleSource;
16323 assert((ExtractIndex->getZExtValue() % NumElems) == 0 &&
16324 "Extract index is not a multiple of the vector length.");
16350 if (!TLI.isOperationLegalOrCustomOrPromote(BOpcode, NarrowBVT))
16364 if (!ConcatL && !ConcatR)
16370 unsigned ConcatOpNum = ExtractIndex->getZExtValue() / NumElems;
16388 SDValue NarrowBinOp = DAG.
getNode(BOpcode, DL, NarrowBVT, X, Y);
16404 if (!Ld || !Ld->hasOneUse() || Ld->getExtensionType() || Ld->isVolatile() ||
16420 SDValue NewLd = DAG.
getLoad(VT, DL, Ld->getChain(), NewAddr, MMO);
16448 assert((Idx % NumElems) == 0 &&
16449 "IDX in concat is not a multiple of the result vector length.");
16458 if (
auto *Idx = dyn_cast<ConstantSDNode>(N->
getOperand(1))) {
16463 if (ExtractSize % EltSize == 0) {
16464 unsigned NumElems = ExtractSize / EltSize;
16466 EVT ExtractVT = NumElems == 1 ? EltVT :
16474 if (NumElems == 1) {
16496 if (!NVT.
bitsEq(SmallVT))
16503 if (InsIdx && ExtIdx) {
16522 if (SimplifyDemandedVectorElts(
SDValue(N, 0)))
16541 unsigned NumConcats = NumElts / NumElemsPerConcat;
16546 if (NumElemsPerConcat * 2 == NumElts && N1.
isUndef() &&
16548 SVN->
getMask().end(), [](
int i) {
return i == -1; })) {
16557 for (
unsigned I = 0;
I != NumConcats; ++
I) {
16559 unsigned Begin =
I * NumElemsPerConcat;
16560 bool AllUndef =
true, NoUndef =
true;
16561 for (
unsigned J = Begin; J != Begin + NumElemsPerConcat; ++J) {
16569 if (SVN->
getMaskElt(Begin) % NumElemsPerConcat != 0)
16572 for (
unsigned J = 1; J != NumElemsPerConcat; ++J)
16576 unsigned FirstElt = SVN->
getMaskElt(Begin) / NumElemsPerConcat;
16582 }
else if (AllUndef) {
16632 bool IsSplat =
false;
16636 if (
SDValue Splat0 = BV0->getSplatValue())
16637 IsSplat = (Splat0 == BV1->getSplatValue());
16641 for (
int M : SVN->
getMask()) {
16644 int Idx = M < (int)NumElts ? M : M - NumElts;
16645 SDValue &S = (M < (int)NumElts ? N0 : N1);
16649 assert(Idx == 0 &&
"Unexpected SCALAR_TO_VECTOR operand index.");
16661 if (!Op.
isUndef() && !isa<ConstantSDNode>(
Op) && !isa<ConstantFPSDNode>(Op))
16662 if (!IsSplat && !DuplicateOps.
insert(Op).second)
16689 bool LegalOperations,
16704 auto isAnyExtend = [&
Mask, &NumElts](
unsigned Scale) {
16705 for (
unsigned i = 0; i != NumElts; ++i) {
16708 if ((i % Scale) == 0 && Mask[i] == (int)(i / Scale))
16717 for (
unsigned Scale = 2; Scale < NumElts; Scale *= 2) {
16719 if (NumElts % Scale != 0)
16721 if (!isAnyExtend(Scale))
16727 if (!LegalOperations ||
16765 if (ExtDstSizeInBits % ExtSrcSizeInBits != 0)
16767 unsigned ExtScale = ExtDstSizeInBits / ExtSrcSizeInBits;
16772 auto isTruncate = [&
Mask, &NumElts](
unsigned Scale) {
16773 for (
unsigned i = 0; i != NumElts; ++i) {
16776 if ((i * Scale) < NumElts && Mask[i] == (int)(i * Scale))
16786 if (EltSizeInBits != ExtSrcSizeInBits)
16791 if (isTruncate(ExtScale))
16806 assert(UserMask.
size() == SplatMask.
size() &&
"Mask length mismatch");
16824 auto CanSimplifyToExistingSplat = [](
ArrayRef<int> UserMask,
16826 for (
unsigned i = 0, e = UserMask.
size(); i != e; ++i)
16827 if (UserMask[i] != -1 && SplatMask[i] == -1 &&
16828 SplatMask[UserMask[i]] != -1)
16832 if (CanSimplifyToExistingSplat(UserMask, SplatMask))
16838 for (
int Idx : UserMask)
16839 NewMask.
push_back(Idx == -1 ? -1 : SplatMask[Idx]);
16851 int MaskSize = Mask.
size();
16852 int EltFromOp0 = -1;
16857 for (
int i = 0; i != MaskSize; ++i) {
16858 if (Mask[i] >= 0 && Mask[i] < MaskSize) {
16860 if (EltFromOp0 != -1)
16863 }
else if (Mask[i] != i + MaskSize) {
16883 if (ShufOp0Index == -1) {
16887 if (ShufOp0Index == -1)
16891 Mask = CommutedMask;
16899 assert(Mask[ShufOp0Index] >= 0 && Mask[ShufOp0Index] < (
int)Mask.
size() &&
16900 "Shuffle mask value must be from operand 0");
16905 if (!InsIndexC || InsIndexC->getSExtValue() != Mask[ShufOp0Index])
16919 Op0.getOperand(2).getValueType());
16921 Op1, Op0.getOperand(1), NewInsIndex);
16942 for (
unsigned i = 0; i != NumElts; ++i) {
16944 if (Idx >= (
int)NumElts) Idx -= NumElts;
16956 bool Changed =
false;
16958 for (
unsigned i = 0; i != NumElts; ++i) {
16960 if (Idx >= (
int)NumElts) {
16974 if (
auto *N0Shuf = dyn_cast<ShuffleVectorSDNode>(N0))
16975 if (N1->
isUndef() && N0Shuf->isSplat())
16995 "BUILD_VECTOR has wrong number of operands");
16997 bool AllSame =
true;
16998 for (
unsigned i = 0; i != NumElts; ++i) {
17005 if (!Base.getNode())
17007 for (
unsigned i = 0; i != NumElts; ++i) {
17031 if (SimplifyDemandedVectorElts(
SDValue(N, 0)))
17078 for (
int s = 0; s != Scale; ++s)
17079 NewMask.
push_back(M < 0 ? -1 : Scale * M + s);
17089 EVT ScaleVT = SVT.
bitsLT(InnerSVT) ? VT : InnerVT;
17101 ScaleShuffleMask(InnerSVN->
getMask(), InnerScale);
17103 ScaleShuffleMask(SVN->
getMask(), OuterScale);
17107 for (
int M : OuterMask)
17108 NewMask.
push_back(M < 0 ? -1 : InnerMask[M]);
17140 "Shuffle types don't match");
17144 bool HasSameOp0 = N0 == SV0;
17145 bool IsSV1Undef = SV1.
isUndef();
17146 if (HasSameOp0 || IsSV1Undef || N0 == SV1)
17170 "Shuffle types don't match");
17176 for (
unsigned i = 0; i != NumElts; ++i) {
17185 if (Idx < (
int)NumElts) {
17195 CurrentVec = (Idx < (int) NumElts) ? OtherSV->
getOperand(0)
17210 Idx = Idx % NumElts;
17211 if (!SV0.getNode() || SV0 == CurrentVec) {
17220 if (SV1.getNode() && SV1 != CurrentVec)
17230 bool isUndefMask =
true;
17231 for (
unsigned i = 0; i != NumElts && isUndefMask; ++i)
17232 isUndefMask &= Mask[i] < 0;
17237 if (!SV0.getNode())
17239 if (!SV1.getNode())
17276 int Elt = C0->getZExtValue();
17378 if (!isa<ConstantSDNode>(N2))
17381 unsigned InsIdx = cast<ConstantSDNode>(N2)->getZExtValue();
17391 if (InsIdx < OtherIdx) {
17395 AddToWorklist(NewOp.
getNode());
17408 Ops[cast<ConstantSDNode>(N2)->getZExtValue() / Factor] = N1;
17455 if (LegalOperations)
17467 auto BuildClearMask = [&](
int Split) {
17468 int NumSubElts = NumElts *
Split;
17472 for (
int i = 0; i != NumSubElts; ++i) {
17473 int EltIdx = i /
Split;
17474 int SubIdx = i %
Split;
17482 if (isa<ConstantSDNode>(Elt))
17483 Bits = cast<ConstantSDNode>(Elt)->getAPIntValue();
17484 else if (isa<ConstantFPSDNode>(Elt))
17485 Bits = cast<ConstantFPSDNode>(Elt)->getValueAPF().bitcastToAPInt();
17491 Bits.
lshrInPlace((Split - SubIdx - 1) * NumSubBits);
17497 Bits = Bits.
trunc(NumSubBits);
17501 else if (Bits == 0)
17535 "SimplifyVBinOp only works on vectors!");
17549 if (LegalTypes && isa<ShuffleVectorSDNode>(LHS) &&
17550 isa<ShuffleVectorSDNode>(RHS) && LHS.hasOneUse() && RHS.hasOneUse() &&
17551 LHS.getOperand(1).isUndef() &&
17552 RHS.getOperand(1).isUndef()) {
17556 if (SVN0->
getMask().equals(SVN1->getMask())) {
17560 LHS.getOperand(0), RHS.getOperand(0),
17562 AddUsersToWorklist(N);
17576 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
17581 if (SCC.getNode()) {
17587 SCC.getOperand(0), SCC.getOperand(1),
17588 SCC.getOperand(4));
17589 AddToWorklist(SETCC.
getNode());
17591 SCC.getOperand(2), SCC.getOperand(3));
17604 bool DAGCombiner::SimplifySelectOps(
SDNode *TheSelect,
SDValue LHS,
17617 CC = cast<CondCodeSDNode>(TheSelect->
getOperand(4))->
get();
17624 CC = cast<CondCodeSDNode>(Cmp.
getOperand(2))->
get();
17629 if (Zero && Zero->
isZero() &&
17633 CombineTo(TheSelect, Sqrt);
17661 LLD->
isIndexed() || RLD->isIndexed() ||
17675 RLD->getPointerInfo().getAddrSpace() != 0 ||
17687 (RLD->hasAnyUseOfValue(1) && RLD->isPredecessorOf(CondNode)))
17691 RLD->isPredecessorOf(LLD))
17696 RLD->getBasePtr());
17703 (RLD->hasAnyUseOfValue(1) &&
17704 (RLD->isPredecessorOf(CondLHS) || RLD->isPredecessorOf(CondRHS))))
17719 unsigned Alignment = std::min(LLD->
getAlignment(), RLD->getAlignment());
17721 if (!RLD->isInvariant())
17723 if (!RLD->isDereferenceable())
17740 CombineTo(TheSelect, Load);
17787 if (N2C && ((N2C->getAPIntValue() & (N2C->getAPIntValue() - 1)) == 0)) {
17788 unsigned ShCt = XType.
getSizeInBits() - N2C->getAPIntValue().logBase2() - 1;
17791 AddToWorklist(Shift.
getNode());
17793 if (XType.
bitsGT(AType)) {
17795 AddToWorklist(Shift.
getNode());
17799 Shift = DAG.
getNOT(DL, Shift, AType);
17806 AddToWorklist(Shift.
getNode());
17808 if (XType.
bitsGT(AType)) {
17810 AddToWorklist(Shift.
getNode());
17814 Shift = DAG.
getNOT(DL, Shift, AType);
17823 bool NotExtCompare) {
17825 if (N2 == N3)
return N2;
17833 N0, N1, CC, DL,
false);
17834 if (SCC.getNode()) AddToWorklist(SCC.getNode());
17836 if (
ConstantSDNode *SCCC = dyn_cast_or_null<ConstantSDNode>(SCC.getNode())) {
17839 return !SCCC->isNullValue() ? N2 : N3;
17855 !TLI.
isFPImmLegal(TV->getValueAPF(), TV->getValueType(0)) &&
17856 !TLI.
isFPImmLegal(FV->getValueAPF(), FV->getValueType(0))) &&
17859 (TV->hasOneUse() || FV->hasOneUse())) {
17861 const_cast<ConstantFP*
>(FV->getConstantFPValue()),
17862 const_cast<ConstantFP*>(TV->getConstantFPValue())
17872 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
17883 AddToWorklist(Cond.
getNode());
17886 AddToWorklist(CstOffset.getNode());
17889 AddToWorklist(CPIdx.getNode());
17897 if (
SDValue V = foldSelectCCToShiftAnd(DL, N0, N1, N2, N3, CC))
17930 if (N2C &&
isNullConstant(N3) && N2C->getAPIntValue().isPowerOf2() &&
17936 if (NotExtCompare && N2C->isOne())
17941 if (!LegalOperations ||
17960 AddToWorklist(SCC.
getNode());
17961 AddToWorklist(Temp.
getNode());
17985 SubC = dyn_cast<ConstantSDNode>(N3.
getOperand(0));
17989 SubC = dyn_cast<ConstantSDNode>(N2.
getOperand(0));
17991 EVT XType = N0.getValueType();
17997 getShiftAmountTy(N0.getValueType())));
18000 AddToWorklist(Shift.
getNode());
18001 AddToWorklist(Add.
getNode());
18021 if (
auto *ValueOnZeroC = dyn_cast<ConstantSDNode>(ValueOnZero)) {
18047 bool foldBooleans) {
18049 DagCombineInfo(DAG, Level,
false,
this);
18050 return TLI.
SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL);
18155 if (Enabled == TLI.ReciprocalEstimate::Disabled)
18162 AddToWorklist(Est.getNode());
18170 for (
int i = 0; i < Iterations; ++i) {
18172 AddToWorklist(NewEst.
getNode());
18175 AddToWorklist(NewEst.getNode());
18178 AddToWorklist(NewEst.getNode());
18181 AddToWorklist(Est.getNode());
18197 unsigned Iterations,
18206 AddToWorklist(HalfArg.
getNode());
18209 AddToWorklist(HalfArg.getNode());
18212 for (
unsigned i = 0; i < Iterations; ++i) {
18214 AddToWorklist(NewEst.
getNode());
18217 AddToWorklist(NewEst.getNode());
18220 AddToWorklist(NewEst.getNode());
18223 AddToWorklist(Est.getNode());
18229 AddToWorklist(Est.
getNode());
18241 unsigned Iterations,
18254 for (
unsigned i = 0; i < Iterations; ++i) {
18259 AddToWorklist(AEE.getNode());
18262 AddToWorklist(RHS.getNode());
18268 if (Reciprocal || (i + 1) < Iterations) {
18275 AddToWorklist(LHS.getNode());
18278 AddToWorklist(Est.getNode());
18300 if (Enabled == TLI.ReciprocalEstimate::Disabled)
18307 bool UseOneConstNR =
false;
18311 AddToWorklist(Est.
getNode());
18314 Est = UseOneConstNR
18315 ? buildSqrtNROneConst(Op, Est, Iterations, Flags, Reciprocal)
18316 : buildSqrtNRTwoConst(Op, Est, Iterations, Flags, Reciprocal);
18323 EVT CCVT = getSetCCResultType(VT);
18335 Est = DAG.
getNode(SelOpcode, DL, VT, IsDenorm, FPZero, Est);
18336 AddToWorklist(Fabs.
getNode());
18337 AddToWorklist(IsDenorm.
getNode());
18338 AddToWorklist(Est.
getNode());
18343 Est = DAG.
getNode(SelOpcode, DL, VT, IsZero, FPZero, Est);
18344 AddToWorklist(IsZero.
getNode());
18345 AddToWorklist(Est.
getNode());
18356 return buildSqrtEstimateImpl(Op, Flags,
true);
18360 return buildSqrtEstimateImpl(Op, Flags,
false);
18389 return !((NumBytes0 <= PtrDiff) || (PtrDiff + NumBytes1 <= 0));
18395 if (
auto *A = dyn_cast<FrameIndexSDNode>(BasePtr0.
getBase()))
18396 if (
auto *
B = dyn_cast<FrameIndexSDNode>(BasePtr1.
getBase())) {
18405 bool IsFI0 = isa<FrameIndexSDNode>(BasePtr0.
getBase());
18406 bool IsFI1 = isa<FrameIndexSDNode>(BasePtr1.
getBase());
18407 bool IsGV0 = isa<GlobalAddressSDNode>(BasePtr0.
getBase());
18408 bool IsGV1 = isa<GlobalAddressSDNode>(BasePtr1.
getBase());
18409 bool IsCV0 = isa<ConstantPoolSDNode>(BasePtr0.
getBase());
18410 bool IsCV1 = isa<ConstantPoolSDNode>(BasePtr1.
getBase());
18415 (IsGV0 != IsGV1) || (IsCV0 != IsCV1)) &&
18416 (IsFI0 || IsGV0 || IsCV0) && (IsFI1 || IsGV1 || IsCV1))
18428 if (OrigAlignment0 == OrigAlignment1 && SrcValOffset0 != SrcValOffset1 &&
18429 NumBytes0 == NumBytes1 && OrigAlignment0 > NumBytes0) {
18430 int64_t OffAlign0 = SrcValOffset0 % OrigAlignment0;
18431 int64_t OffAlign1 = SrcValOffset1 % OrigAlignment1;
18435 if ((OffAlign0 + NumBytes0) <= OffAlign1 ||
18436 (OffAlign1 + NumBytes1) <= OffAlign0)
18452 int64_t MinOffset = std::min(SrcValOffset0, SrcValOffset1);
18453 int64_t Overlap0 = NumBytes0 + SrcValOffset0 - MinOffset;
18454 int64_t Overlap1 = NumBytes1 + SrcValOffset1 - MinOffset;
18470 void DAGCombiner::GatherAllAliases(
SDNode *N,
SDValue OriginalChain,
18476 bool IsLoad = isa<LoadSDNode>(
N) && !cast<LSBaseSDNode>(N)->isVolatile();
18480 unsigned Depth = 0;
18485 while (!Chains.
empty()) {
18512 bool IsOpLoad = isa<LoadSDNode>(Chain.
getNode()) &&
18516 if (!(IsLoad && IsOpLoad) &&
18517 isAlias(cast<LSBaseSDNode>(N), cast<LSBaseSDNode>(Chain.
getNode()))) {
18565 GatherAllAliases(N, OldChain, Aliases);
18568 if (Aliases.
size() == 0)
18572 if (Aliases.
size() == 1)
18591 bool DAGCombiner::findBetterNeighborChains(
StoreSDNode *St) {
18616 if (Index != St && !
SDValue(Index, 0)->hasOneUse())
18633 if (
StoreSDNode *STn = dyn_cast<StoreSDNode>(NextInChain)) {
18635 if (STn->isVolatile() || STn->isIndexed()) {
18642 }
else if (
LoadSDNode *Ldn = dyn_cast<LoadSDNode>(NextInChain)) {
18643 NextInChain = Ldn->getChain().getNode();
18657 bool MadeChangeToSt =
false;
18660 for (
StoreSDNode *ChainedStore : ChainedStores) {
18661 SDValue Chain = ChainedStore->getChain();
18662 SDValue BetterChain = FindBetterChain(ChainedStore, Chain);
18664 if (Chain != BetterChain) {
18665 if (ChainedStore == St)
18666 MadeChangeToSt =
true;
18667 BetterChains.
push_back(std::make_pair(ChainedStore, BetterChain));
18673 for (
auto Replacement : BetterChains)
18674 replaceStoreChain(Replacement.first, Replacement.second);
18676 return MadeChangeToSt;
18683 DAGCombiner(*
this, AA, OptLevel).Run(Level);
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
bool LegalizeOp(SDNode *N, SmallSetVector< SDNode *, 16 > &UpdatedNodes)
Transforms a SelectionDAG node and any operands to it into a node that is compatible with the target ...
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B, const MVT::SimpleValueType SVT=MVT::SimpleValueType::Any) const
Find the largest common subclass of A and B.
static bool isBSwapHWordElement(SDValue N, MutableArrayRef< SDNode *> Parts)
Return true if the specified node is an element that makes up a 32-bit packed halfword byteswap...
SDValue getGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, bool isTargetGA=false, unsigned char TargetFlags=0)
static MVT getIntegerVT(unsigned BitWidth)
std::string & operator+=(std::string &buffer, StringRef string)
void push_back(const T &Elt)
SDValue BuildUDIV(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, bool IsAfterLegalization, SmallVectorImpl< SDNode *> &Created) const
Given an ISD::UDIV node expressing a divide by constant, return a DAG expression to select that will ...
BUILTIN_OP_END - This must be the last enum value in this list.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
virtual MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
EVT getValueType() const
Return the ValueType of the referenced return value.
static SDValue FoldIntToFPToInt(SDNode *N, SelectionDAG &DAG)
static void commuteMask(MutableArrayRef< int > Mask)
Change values in a shuffle permute mask assuming the two vector operands have swapped position...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const SDValue & getOffset() const
iterator_range< use_iterator > uses()
static SDValue foldAddSubBoolOfMaskedVal(SDNode *N, SelectionDAG &DAG)
virtual bool canMergeStoresTo(unsigned AS, EVT MemVT, const SelectionDAG &DAG) const
Returns if it's reasonable to merge stores to MemVT size.
static bool isConstant(const MachineInstr &MI)
bool hasNoSignedZeros() const
SDValue getBoolExtOrTrunc(SDValue Op, const SDLoc &SL, EVT VT, EVT OpVT)
Convert Op, which must be of integer type, to the integer type VT, by using an extension appropriate ...
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant, which is required to be operand #1) half of the integer or float value specified as operand #0.
uint64_t getZExtValue() const
Get zero extended value.
APInt sext(unsigned width) const
Sign extend to a new width.
static bool areSlicesNextToEachOther(const LoadedSlice &First, const LoadedSlice &Second)
Check whether or not First and Second are next to each other in memory.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
bool isBuildVectorOfConstantSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantSDNode or undef...
DiagnosticInfoOptimizationBase::Argument NV
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
typename SuperClass::const_iterator const_iterator
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
SDValue CombineTo(SDNode *N, ArrayRef< SDValue > To, bool AddTo=true)
SDValue getIndexedLoad(SDValue OrigLoad, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
DELETED_NODE - This is an illegal value that is used to catch errors.
LLVM_NODISCARD T pop_back_val()
ConstantSDNode * isConstOrConstSplat(SDValue N)
Returns the SDNode if it is a constant splat BuildVector or constant int.
virtual bool isFPImmLegal(const APFloat &, EVT) const
Returns true if the target can instruction select the specified FP immediate natively.
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
BR_CC - Conditional branch.
Compute iterated dominance frontiers using a linear time algorithm.
bool isNON_TRUNCStore(const SDNode *N)
Returns true if the specified node is a non-truncating store.
bool isOperationCustom(unsigned Op, EVT VT) const
Return true if the operation uses custom lowering, regardless of whether the type is legal or not...
size_type size() const
Determine the number of elements in the SetVector.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
static SDValue foldAddSubOfSignBit(SDNode *N, SelectionDAG &DAG)
Try to fold a 'not' shifted sign-bit with add/sub with constant operand into a shift and add with a d...
int getSplatIndex() const
static SDValue simplifyDivRem(SDNode *N, SelectionDAG &DAG)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
static uint64_t * getMemory(unsigned numWords)
A utility function for allocating memory and checking for allocation failure.
SDValue getSignExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return an operation which will sign extend the low lanes of the operand into the specified vector typ...
const SDValue & getBasePtr() const
bool isNegative() const
Return true if the value is negative.
Carry-setting nodes for multiple precision addition and subtraction.
static bool isTruncateOf(SelectionDAG &DAG, SDValue N, SDValue &Op, KnownBits &Known)
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
static SDValue combineShuffleOfScalars(ShuffleVectorSDNode *SVN, SelectionDAG &DAG, const TargetLowering &TLI)
Clients of various APIs that cause global effects on the DAG can optionally implement this interface...
SDValue makeEquivalentMemoryOrdering(LoadSDNode *Old, SDValue New)
If an existing load has uses of its chain, create a token factor node with that chain and the new mem...
APInt zext(unsigned width) const
Zero extend to a new width.
bool operator>(int64_t V1, const APSInt &V2)
virtual bool enableAggressiveFMAFusion(EVT VT) const
Return true if target always beneficiates from combining into FMA for a given value type...
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
const SDValue & getValue() const
virtual bool getPreIndexedAddressParts(SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
Returns true by value, base pointer and offset pointer and addressing mode by reference if the node's...
virtual SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps, bool &UseOneConstNR, bool Reciprocal) const
Hooks for building estimates in place of slower divisions and square roots.
SDVTList getVTList() const
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
virtual bool isFNegFree(EVT VT) const
Return true if an fneg operation is free to the point where it is never worthwhile to replace it with...
CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger)
Return the result of a logical AND between different comparisons of identical values: ((X op1 Y) & (X...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
virtual unsigned combineRepeatedFPDivisors() const
Indicate whether this target prefers to combine FDIVs with the same divisor.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
const SDValue & getBasePtr() const
virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const
This method will be invoked for all target nodes and for any target-independent nodes that the target...
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
The two locations do not alias at all.
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
const SDValue & getChain() const
unsigned getResNo() const
Convenience function for get().getResNo().
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
virtual bool isCommutativeBinOp(unsigned Opcode) const
Returns true if the opcode is a commutative binary operation.
static const fltSemantics & EVTToAPFloatSemantics(EVT VT)
Returns an APFloat semantics tag appropriate for the given type.
unsigned getAlignment() const
unsigned getValueSizeInBits(unsigned ResNo) const
Returns MVT::getSizeInBits(getValueType(ResNo)).
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isBitwiseNot(SDValue V)
Returns true if V is a bitwise not operation.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
APInt trunc(unsigned width) const
Truncate to new width.
void setAllBits()
Set every bit to 1.
bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const
Return true if the specified store with truncation is legal on this target.
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS)
Helper function to make it easier to build Select's if you just have operands and don't want to check...
const fltSemantics & getSemantics() const
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
virtual bool isTypeDesirableForOp(unsigned, EVT VT) const
Return true if the target has native support for the specified value type and it is 'desirable' to us...
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
const SDNodeFlags getFlags() const
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
SDNode * getNode() const
get the SDNode which holds the desired result
ConstantFPSDNode * isConstOrConstSplatFP(SDValue N)
Returns the SDNode if it is a constant splat BuildVector or constant float.
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
iv Induction Variable Users
static bool isAllOnesConstantOrAllOnesSplatConstant(SDValue N)
virtual bool isZExtFree(Type *FromTy, Type *ToTy) const
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
virtual bool storeOfVectorConstantIsCheap(EVT MemVT, unsigned NumElem, unsigned AddrSpace) const
Return true if it is expected to be cheaper to do a store of a non-zero vector constant with the give...
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
bool isByteSized() const
Return true if the bit size is a multiple of 8.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
void DeleteNode(SDNode *N)
Remove the specified node from the system.
static SDValue combineTruncationShuffle(ShuffleVectorSDNode *SVN, SelectionDAG &DAG)
bool isConstTrueVal(const SDNode *N) const
Return if the N is a constant or constant vector equal to the true value from getBooleanContents().
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
SDValue getConstantPool(const Constant *C, EVT VT, unsigned Align=0, int Offs=0, bool isT=false, unsigned char TargetFlags=0)
unsigned getBitWidth() const
Get the bit width of this value.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
static SDNode * ShrinkLoadReplaceStoreWithStore(const std::pair< unsigned, unsigned > &MaskInfo, SDValue IVal, StoreSDNode *St, DAGCombiner *DC)
Check to see if IVal is something that provides a value as specified by MaskInfo. ...
virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, SmallVectorImpl< SDNode *> &Created) const
Targets may override this function to provide custom SDIV lowering for power-of-2 denominators...
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
EntryToken - This is the marker used to indicate the start of a region.
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
const SDValue & getValue() const
void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To, unsigned Num)
Like ReplaceAllUsesOfValueWith, but for multiple values at once.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
const ConstantFP * getConstantFPValue() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
bool isAllOnesValue() const
bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal on this target.
void transferDbgValues(SDValue From, SDValue To, unsigned OffsetInBits=0, unsigned SizeInBits=0, bool InvalidateDbg=true)
Transfer debug values from one node to another, while optionally generating fragment expressions for ...
virtual bool isFPExtFree(EVT DestVT, EVT SrcVT) const
Return true if an fpext operation is free (for instance, because single-precision floating-point numb...
bool hasApproximateFuncs() const
virtual bool isStoreBitCastBeneficial(EVT StoreVT, EVT BitcastVT) const
Return true if the following transform is beneficial: (store (y (conv x)), y*)) -> (store x...
bool isTruncatingStore() const
Return true if the op does a truncation before store.
int getRecipEstimateSqrtEnabled(EVT VT, MachineFunction &MF) const
Return a ReciprocalEstimate enum value for a square root of the given type based on the function's at...
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode *> &Visited, SmallVectorImpl< const SDNode *> &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, const SDLoc &DL)
Returns sum of the base pointer and offset.
SDValue getAnyExtendVectorInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return an operation which will any-extend the low lanes of the operand into the specified vector type...
A convenience struct that encapsulates a DAG, and two SDValues for returning information from TargetL...
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
bool operator<=(int64_t V1, const APSInt &V2)
static SDValue combineShuffleToVectorExtend(ShuffleVectorSDNode *SVN, SelectionDAG &DAG, const TargetLowering &TLI, bool LegalOperations, bool LegalTypes)
static bool CanCombineFCOPYSIGN_EXTEND_ROUND(SDNode *N)
copysign(x, fp_extend(y)) -> copysign(x, y) copysign(x, fp_round(y)) -> copysign(x, y)
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
static cl::opt< bool > UseTBAA("combiner-use-tbaa", cl::Hidden, cl::init(true), cl::desc("Enable DAG combiner's use of TBAA"))
bool isSEXTLoad(const SDNode *N)
Returns true if the specified node is a SEXTLOAD.
static bool isNullConstantOrNullSplatConstant(SDValue N)
static uint32_t getAlignment(const MCSectionCOFF &Sec)
bool hasOneUse() const
Return true if there is exactly one use of this node.
static bool isContractable(SDNode *N)
A description of a memory reference used in the backend.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
OverflowKind computeOverflowKind(SDValue N0, SDValue N1) const
Determine if the result of the addition of 2 node can overflow.
bool SimplifyDemandedVectorElts(SDValue Op, const APInt &DemandedEltMask, APInt &KnownUndef, APInt &KnownZero, TargetLoweringOpt &TLO, unsigned Depth=0, bool AssumeSingleUse=false) const
Look at Vector Op.
void setBit(unsigned BitPosition)
Set a given bit to 1.
static ManagedStatic< DebugCounter > DC
SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, bool foldBooleans, DAGCombinerInfo &DCI, const SDLoc &dl) const
Try to simplify a setcc built with the specified operands and cc.
bool operator>=(int64_t V1, const APSInt &V2)
bool isUndef(unsigned Opcode, ArrayRef< SDValue > Ops)
Return true if the result of this operation is always undefined.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static cl::opt< std::string > CombinerAAOnlyFunc("combiner-aa-only-func", cl::Hidden, cl::desc("Only use DAG-combiner alias analysis in this" " function"))
bool equalBaseIndex(BaseIndexOffset &Other, const SelectionDAG &DAG)
APInt shl(unsigned shiftAmt) const
Left-shift function.
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
static cl::opt< bool > Aggressive("aggressive-ext-opt", cl::Hidden, cl::desc("Aggressive extension optimization"))
static unsigned getPPCf128HiElementSelector(const SelectionDAG &DAG)
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
Base class for LoadSDNode and StoreSDNode.
bool isBuildVectorAllZeros(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are 0 or undef...
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
A Use represents the edge between a Value definition and its users.
SDValue getMaskedScatter(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO)
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static bool isLoad(int Opcode)
CopyToReg - This node has three operands: a chain, a register number to set to this value...
op_iterator op_end() const
unsigned getScalarValueSizeInBits() const
uint64_t getConstantOperandVal(unsigned i) const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
This file contains the simple types necessary to represent the attributes associated with functions a...
virtual bool generateFMAsInMachineCombiner(CodeGenOpt::Level OptLevel) const
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal or custom on this target.
The memory access is dereferenceable (i.e., doesn't trap).
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasBigEndianPartOrdering(EVT VT, const DataLayout &DL) const
When splitting a value of the specified type into parts, does the Lo or Hi part come first...
const SDValue & getValue() const
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
virtual bool convertSetCCLogicToBitwiseLogic(EVT VT) const
Use bitwise logic to make pairs of compares more efficient.
virtual bool isMultiStoresCheaperThanBitsMerge(EVT LTy, EVT HTy) const
Return true if it is cheaper to split the store of a merged int val from a pair of smaller values int...
const DataLayout & getDataLayout() const
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
This class is used to represent EVT's, which are used to parameterize some operations.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual bool aggressivelyPreferBuildVectorSources(EVT VecVT) const
zlib-gnu style compression
This file implements a class to represent arbitrary precision integral constant values and operations...
SDValue BuildSDIV(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, bool IsAfterLegalization, SmallVectorImpl< SDNode *> &Created) const
Given an ISD::SDIV node expressing a divide by constant, return a DAG expression to select that will ...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
iterator_range< allnodes_iterator > allnodes()
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
bool isConstantSplatVector(const SDNode *N, APInt &SplatValue)
Node predicates.
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
This class is used to represent an MSTORE node.
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
unsigned getSizeInBits() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
unsigned getActiveBits() const
Compute the number of active bits in the value.
int64_t getSExtValue() const
static BaseIndexOffset match(LSBaseSDNode *N, const SelectionDAG &DAG)
Parses tree in Ptr for base, index, offset addresses.
SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
static SDValue combineMinNumMaxNum(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode CC, const TargetLowering &TLI, SelectionDAG &DAG)
Generate Min/Max node.
unsigned getScalarSizeInBits() const
virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT) const
Return true if the following transform is beneficial: fold (conv (load x)) -> (load (conv*)x) On arch...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
static Value * peekThroughBitcast(Value *V, bool OneUseOnly=false)
Return the source operand of a potentially bitcasted value while optionally checking if it has one us...
int64_t getSExtValue() const
Get sign extended value.
Type * getType() const
All values are typed, get the type of this value.
bool getBoolValue() const
Convert APInt to a boolean value.
MachineFunction & getMachineFunction() const
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
bool insert(const value_type &X)
Insert a new element into the SetVector.
SDValue getMaskedGather(SDVTList VTs, EVT VT, const SDLoc &dl, ArrayRef< SDValue > Ops, MachineMemOperand *MMO)
static bool isAnyConstantBuildVector(const SDNode *N)
bool isKnownNeverZero(SDValue Op) const
Test whether the given SDValue is known to contain non-zero value(s).
const SDValue & getScale() const
const TargetMachine & getTarget() const
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
static bool isBooleanFlip(SDValue V, EVT VT, const TargetLowering &TLI)
Simple integer binary arithmetic operators.
static cl::opt< bool > StressLoadSlicing("combiner-stress-load-slicing", cl::Hidden, cl::desc("Bypass the profitability model of load slicing"), cl::init(false))
Hidden option to stress test load slicing, i.e., when this option is enabled, load slicing bypasses m...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isLittleEndian() const
Layout endianness...
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
AttributeList getAttributes() const
Return the attribute list for this Function.
SDValue getMaskedStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, SDValue Mask, EVT MemVT, MachineMemOperand *MMO, bool IsTruncating=false, bool IsCompressing=false)
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
op_iterator op_begin() const
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace, Instruction *I=nullptr) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
ArrayRef< SDUse > ops() const
int64_t getSrcValueOffset() const
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
SDValue GetDemandedBits(SDValue V, const APInt &Mask)
See if the specified operand can be simplified with the knowledge that only the bits specified by Mas...
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
int getRecipEstimateDivEnabled(EVT VT, MachineFunction &MF) const
Return a ReciprocalEstimate enum value for a division of the given type based on the function's attri...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
UNDEF - An undefined node.
This class is used to represent ISD::STORE nodes.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
bool hasAllowReciprocal() const
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
AliasResult
The possible results of an alias query.
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
const Value * getValue() const
Return the base address of the memory access.
iterator find(const_arg_type_t< KeyT > Val)
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits...
static bool isFMulNegTwo(SDValue &N)
bool isZero() const
Return true if the value is positive or negative zero.
bool hasAllowContract() const
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
bool isNegative() const
Determine sign of this APInt.
const SDValue & getBasePtr() const
initializer< Ty > init(const Ty &Val)
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
bool erase(const KeyT &Val)
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
static SDValue foldBitcastedFPLogic(SDNode *N, SelectionDAG &DAG, const TargetLowering &TLI)
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
bool isAllOnesValue() const
Determine if all bits are set.
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
SDValue getCommutedVectorShuffle(const ShuffleVectorSDNode &SV)
Returns an ISD::VECTOR_SHUFFLE node semantically equivalent to the shuffle node in input but with swa...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
bool SignBitIsZero(SDValue Op, unsigned Depth=0) const
Return true if the sign bit of Op is known to be zero.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
unsigned countPopulation() const
Count the number of bits set.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isExpandingLoad() const
static SDValue combineConcatVectorOfExtracts(SDNode *N, SelectionDAG &DAG)
static SDValue ConvertSelectToConcatVector(SDNode *N, SelectionDAG &DAG)
The instances of the Type class are immutable: once they are created, they are never changed...
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
This is an important class for using LLVM in a threaded context.
Simple binary floating point operators.
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
bool matchUnaryPredicate(SDValue Op, std::function< bool(ConstantSDNode *)> Match)
Attempt to match a unary predicate against a scalar/splat constant or every element of a constant BUI...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
static int getShuffleMaskIndexOfOneElementFromOp0IntoOp1(ArrayRef< int > Mask)
If the shuffle mask is taking exactly one element from the first vector operand and passing through a...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
iterator_range< value_op_iterator > op_values() const
LLVM_NODISCARD bool empty() const
bool isRound() const
Return true if the size is a power-of-two number of bytes.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const SDValue & getOperand(unsigned Num) const
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Carry-using nodes for multiple precision addition and subtraction.
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isMask(unsigned numBits) const
bool isOneValue() const
Determine if this is a value of 1.
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
Split the node's operand with EXTRACT_SUBVECTOR and return the low/high part.
virtual bool isFPExtFoldable(unsigned Opcode, EVT DestVT, EVT SrcVT) const
Return true if an fpext operation input to an Opcode operation is free (for instance, because half-precision floating-point numbers are implicitly extended to float-precision) for an FMA instruction.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
void AddToWorklist(SDNode *N)
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
void Combine(CombineLevel Level, AliasAnalysis *AA, CodeGenOpt::Level OptLevel)
This iterates over the nodes in the SelectionDAG, folding certain types of nodes together, or eliminating superfluous nodes.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This class provides iterator support for SDUse operands that use a specific SDNode.
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
const APInt & getAPIntValue() const
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
static bool matchRotateHalf(SelectionDAG &DAG, SDValue Op, SDValue &Shift, SDValue &Mask)
Match "(X shl/srl V1) & V2" where V2 may not be present.
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
virtual bool hasPairedLoad(EVT, unsigned &) const
Return true if the target supplies and combines to a paired load two loaded values of type LoadedType...
static SDValue narrowExtractedVectorBinOp(SDNode *Extract, SelectionDAG &DAG)
If we are extracting a subvector produced by a wide binary operator with at at least one operand that...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
unsigned getOriginalAlignment() const
Returns alignment and volatility of the memory access.
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y)...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
static cl::opt< bool > CombinerGlobalAA("combiner-global-alias-analysis", cl::Hidden, cl::desc("Enable DAG combiner's use of IR alias analysis"))
virtual bool isDesirableToTransformToIntegerOp(unsigned, EVT) const
Return true if it is profitable for dag combiner to transform a floating point op of specified opcode...
SDValue getMaskedLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, SDValue Mask, SDValue Src0, EVT MemVT, MachineMemOperand *MMO, ISD::LoadExtType, bool IsExpanding=false)
Bit counting operators with an undefined result for zero inputs.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
static const Optional< ByteProvider > calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth, bool Root=false)
Recursively traverses the expression calculating the origin of the requested byte of the given value...
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
const SDValue & getIndex() const
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static SDValue tryToFoldExtOfExtload(SelectionDAG &DAG, DAGCombiner &Combiner, const TargetLowering &TLI, EVT VT, bool LegalOperations, SDNode *N, SDValue N0, ISD::LoadExtType ExtLoadType)
iterator erase(const_iterator CI)
const SDValue & getBasePtr() const
bool haveNoCommonBitsSet(SDValue A, SDValue B) const
Return true if A and B have no common bits set.
static bool areUsedBitsDense(const APInt &UsedBits)
Check that all bits set in UsedBits form a dense region, i.e., UsedBits looks like 0...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static void adjustCostForPairing(SmallVectorImpl< LoadedSlice > &LoadedSlices, LoadedSlice::Cost &GlobalLSCost)
Adjust the GlobalLSCost according to the target paring capabilities and the layout of the slices...
const SDValue & getSrc0() const
SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
int getDivRefinementSteps(EVT VT, MachineFunction &MF) const
Return the refinement step count for a division of the given type based on the function's attributes...
This class contains a discriminated union of information about pointers in memory operands...
unsigned getNumOperands() const
Return the number of values used by this operation.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
HANDLENODE node - Used as a handle for various purposes.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
bool isKnownNeverNaN(SDValue Op) const
Test whether the given SDValue is known to never be NaN.
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value...
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT)
Create a true or false constant of type VT using the target's BooleanContent for type OpVT...
static char isNegatibleForFree(SDValue Op, bool LegalOperations, const TargetLowering &TLI, const TargetOptions *Options, unsigned Depth=0)
Return 1 if we can compute the negated form of the specified expression for the same cost as the expr...
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands...
const SDValue & getMask() const
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
static SDValue getAsCarry(const TargetLowering &TLI, SDValue V)
bool isEXTLoad(const SDNode *N)
Returns true if the specified node is a EXTLOAD.
void sort(IteratorTy Start, IteratorTy End)
bool isUNINDEXEDLoad(const SDNode *N)
Returns true if the specified node is an unindexed load.
The memory access writes data.
static SDValue combineShuffleOfSplat(ArrayRef< int > UserMask, ShuffleVectorSDNode *Splat, SelectionDAG &DAG)
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type...
bool use_empty() const
Return true if there are no uses of this node.
Representation for a specific memory location.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
virtual bool IsDesirableToPromoteOp(SDValue, EVT &) const
This method query the target whether it is beneficial for dag combiner to promote the specified node...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base, unsigned Bytes, int Dist) const
Return true if loads are next to each other and can be merged.
bool isBuildVectorAllOnes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are ~0 or undef...
void dump() const
Dump this node, for debugging.
static bool canFoldInAddressingMode(SDNode *N, SDNode *Use, SelectionDAG &DAG, const TargetLowering &TLI)
Return true if 'Use' is a load or a store that uses N as its base pointer and that N may be folded in...
const TargetLowering & getTargetLoweringInfo() const
Helper struct to parse and store a memory address as base + index + offset.
A SetVector that performs no allocations if smaller than a certain size.
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
void setNoUnsignedWrap(bool b)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static void zeroExtendToMatch(APInt &LHS, APInt &RHS, unsigned Offset=0)
virtual bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT) const
virtual bool shouldNormalizeToSelectSequence(LLVMContext &Context, EVT VT) const
Returns true if we should normalize select(N0&N1, X, Y) => select(N0, select(N1, X, Y), Y) and select(N0|N1, X, Y) => select(N0, select(N1, X, Y, Y)) if it is likely that it saves us from materializing N0 and N1 in an integer register.
virtual bool getPostIndexedAddressParts(SDNode *, SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
Returns true by value, base pointer and offset pointer and addressing mode by reference if this node ...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
EVT getVectorElementType() const
Given a vector type, return the type of each element.
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provides VTs and return the low/high part...
static SDValue foldExtendedSignBitTest(SDNode *N, SelectionDAG &DAG, bool LegalOperations)
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, but op #2 is a boolean indicating ...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and rounds it to a floating point val...
SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, unsigned Index) const
Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type from this source type with ...
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
bool allOperandsUndef(const SDNode *N)
Return true if the node has at least one operand and all operands of the specified node are ISD::UNDE...
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
BRCOND - Conditional branch.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Byte Swap and Counting operators.
static SDValue flipBoolean(SDValue V, const SDLoc &DL, EVT VT, SelectionDAG &DAG, const TargetLowering &TLI)
APFloat neg(APFloat X)
Returns the negated value of the argument.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
virtual bool isVectorLoadExtDesirable(SDValue ExtVal) const
Return true if folding a vector load into ExtVal (a sign, zero, or any extend node) is profitable...
LLVM_NODISCARD T pop_back_val()
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
SDValue IncrementMemoryAddress(SDValue Addr, SDValue Mask, const SDLoc &DL, EVT DataVT, SelectionDAG &DAG, bool IsCompressedMemory) const
Increments memory address Addr according to the type of the value DataVT that should be stored...
Represents one node in the SelectionDAG.
static SDNode * tryToFoldExtendOfConstant(SDNode *N, const TargetLowering &TLI, SelectionDAG &DAG, bool LegalTypes, bool LegalOperations)
Try to fold a sext/zext/aext dag node into a ConstantSDNode or a build_vector of constants.
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner, const TargetLowering &TLI, EVT VT, bool LegalOperations, SDNode *N, SDValue N0, ISD::LoadExtType ExtLoadType, ISD::NodeType ExtOpc)
static unsigned int semanticsPrecision(const fltSemantics &)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
static bool isOneConstantOrOneSplatConstant(SDValue N)
static std::pair< SDValue, SDValue > SplitVSETCC(const SDNode *N, SelectionDAG &DAG)
bool isConstFalseVal(const SDNode *N) const
Return if the N is a constant or constant vector equal to the false value from getBooleanContents().
unsigned logBase2() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachinePointerInfo getWithOffset(int64_t O) const
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
size_t use_size() const
Return the number of uses of this node.
SDNode * isConstantIntBuildVectorOrConstantInt(SDValue N)
Test whether the given value is a constant int or similar node.
static SDValue foldFPToIntToFP(SDNode *N, SelectionDAG &DAG, const TargetLowering &TLI)
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT...
EVT getMemoryVT() const
Return the type of the in-memory value.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
Class for arbitrary precision integers.
static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned EltSize, SelectionDAG &DAG)
bool isBuildVectorOfConstantFPSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantFPSDNode or undef...
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
static SDValue replaceShuffleOfInsert(ShuffleVectorSDNode *Shuf, SelectionDAG &DAG)
If a shuffle inserts exactly one element from a source vector operand into another vector operand and...
virtual bool preferShiftsToClearExtremeBits(SDValue X) const
There are two ways to clear extreme bits (either low or high): Mask: x & (-1 << y) (the instcombine c...
virtual bool hasAndNot(SDValue X) const
Return true if the target has a bitwise and-not operation: X = ~A & B This can be used to simplify se...
iterator_range< use_iterator > uses()
static cl::opt< bool > MaySplitLoadIndex("combiner-split-load-index", cl::Hidden, cl::init(true), cl::desc("DAG combiner may split indexing from loads"))
static SDNode * getBuildPairElt(SDNode *N, unsigned i)
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, SDNode *Cst1, SDNode *Cst2)
A "pseudo-class" with methods for operating on BUILD_VECTORs.
Select(COND, TRUEVAL, FALSEVAL).
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static SDValue GetNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOperations, unsigned Depth=0)
If isNegatibleForFree returns true, return the newly negated expression.
static use_iterator use_end()
bool SimplifyDemandedBits(SDNode *User, unsigned OpIdx, const APInt &Demanded, DAGCombinerInfo &DCI, TargetLoweringOpt &TLO) const
Helper for SimplifyDemandedBits that can simplify an operation with multiple uses.
bool isNullFPConstant(SDValue V)
Returns true if V is an FP constant with a value of positive zero.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
AddrMode
ARM Addressing Modes.
ANY_EXTEND - Used for integer types. The high bits are undefined.
static std::pair< unsigned, unsigned > CheckForMaskedLoad(SDValue V, SDValue Ptr, SDValue Chain)
Check to see if V is (and load (ptr), imm), where the load is having specific bytes cleared out...
virtual bool isFMAFasterThanFMulAndFAdd(EVT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger)
Return the result of a logical OR between different comparisons of identical values: ((X op1 Y) | (X ...
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
int getMaskElt(unsigned Idx) const
static SDValue partitionShuffleOfConcats(SDNode *N, SelectionDAG &DAG)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
SDValue FoldConstantVectorArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops, const SDNodeFlags Flags=SDNodeFlags())
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
Flags
Flags values. These may be or'd together.
int getSqrtRefinementSteps(EVT VT, MachineFunction &MF) const
Return the refinement step count for a square root of the given type based on the function's attribut...
amdgpu Simplify well known AMD library false Value Value * Arg
The memory access reads data.
bool hasNoSignedWrap() const
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool operator!=(uint64_t V1, const APInt &V2)
static mvt_range all_valuetypes()
SimpleValueType Iteration.
opStatus
IEEE-754R 7: Default exception handling.
These are IR-level optimization flags that may be propagated to SDNodes.
Represents a use of a SDNode.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool isVector() const
Return true if this is a vector value type.
static SDValue extractShiftForRotate(SelectionDAG &DAG, SDValue OppShift, SDValue ExtractFrom, SDValue &Mask, const SDLoc &DL)
Helper function for visitOR to extract the needed side of a rotate idiom from a shl/srl/mul/udiv.
const SDValue & getValue() const
virtual bool convertSelectOfConstantsToMath(EVT VT) const
Return true if a select of constants (select Cond, C1, C2) should be transformed into simple math ops...
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
Bitwise operators - logical and, logical or, logical xor.
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
LLVM_NODISCARD bool empty() const
StringRef getValueAsString() const
Return the attribute's value as a string.
bool isKnownToBeAPowerOfTwo(SDValue Val) const
Test if the given value is known to have exactly one bit set.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
This file provides utility analysis objects describing memory locations.
static SDValue tryFoldToZero(const SDLoc &DL, const TargetLowering &TLI, EVT VT, SelectionDAG &DAG, bool LegalOperations, bool LegalTypes)
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
static bool isSigned(Value *V)
Can the given value generate sign bits.
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
Return how we should legalize values of this type, either it is already legal (return 'Legal') or we ...
virtual SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps) const
Return a reciprocal estimate value for the input operand.
ISD::CondCode get() const
const ConstantInt * getConstantIntValue() const
const TargetSubtargetInfo & getSubtarget() const
bool empty() const
Determine if the SetVector is empty or not.
Flags getFlags() const
Return the raw flags of the source value,.
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
The memory access always returns the same value (or traps).
unsigned InferPtrAlignment(SDValue Ptr) const
Infer alignment of a load / store address.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static bool splitMergedValStore(StoreInst &SI, const DataLayout &DL, const TargetLowering &TLI)
For the instruction sequence of store below, F and I values are bundled together as an i64 value befo...
static SDValue getInputChainForNode(SDNode *N)
Given a node, return its input chain if it has one, otherwise return a null sd operand.
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
unsigned getOpcode() const
SDValue getValue(unsigned R) const
virtual bool isIntDivCheap(EVT VT, AttributeList Attr) const
Return true if integer divide is usually cheaper than a sequence of several shifts, adds, and multiplies for this target.
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
This class is used to represent an MSCATTER node.
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
LLVM_NODISCARD bool empty() const
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
static SDValue stripConstantMask(SelectionDAG &DAG, SDValue Op, SDValue &Mask)
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
const MachinePointerInfo & getPointerInfo() const
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, unsigned Alignment=1, bool *Fast=nullptr) const
Return true if the target supports a memory access of this type for the given address space and align...
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
This class is used to represent an MLOAD node.
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
bool operator<(int64_t V1, const APSInt &V2)
static ConstantSDNode * getAsNonOpaqueConstant(SDValue N)
If N is a ConstantSDNode with isOpaque() == false return it casted to a ConstantSDNode pointer else n...
static bool ExtendUsesToFormExtLoad(EVT VT, SDNode *N, SDValue N0, unsigned ExtOpc, SmallVectorImpl< SDNode *> &ExtendNodes, const TargetLowering &TLI)
ArrayRef< int > getMask() const
LLVM Value Representation.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
FMA - Perform a * b + c with no intermediate rounding step.
static bool isSlicingProfitable(SmallVectorImpl< LoadedSlice > &LoadedSlices, const APInt &UsedBits, bool ForCodeSize)
Check the profitability of all involved LoadedSlice.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
A vector that has set insertion semantics.
static bool isShift(MachineInstr *MI, unsigned Opcode, int64_t Imm)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isTruncatingStore() const
Return true if the op does a truncation before store.
static bool isDivRemLibcallAvailable(SDNode *Node, bool isSigned, const TargetLowering &TLI)
Return true if divmod libcall is available.
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond)
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
This class is used to represent an MGATHER node.
bool hasNoUnsignedWrap() const
SDValue getValueType(EVT)
virtual bool isVectorClearMaskLegal(ArrayRef< int >, EVT) const
Similar to isShuffleMaskLegal.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
virtual bool isFsqrtCheap(SDValue X, SelectionDAG &DAG) const
Return true if SQRT(X) shouldn't be replaced with X*RSQRT(X).
bool isNonTemporal() const
bool isUndef() const
Return true if the type of the node type undefined.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone...
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal on this target.
virtual bool mergeStoresAfterLegalization() const
Allow store merging after legalization in addition to before legalization.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
bool matchBinaryPredicate(SDValue LHS, SDValue RHS, std::function< bool(ConstantSDNode *, ConstantSDNode *)> Match)
Attempt to match a binary predicate against a pair of scalar/splat constants or every element of a pa...
bool hasAllowReassociation() const
virtual bool useAA() const
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine, etc.).
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
const APFloat & getValueAPF() const
unsigned NoSignedZerosFPMath
NoSignedZerosFPMath - This flag is enabled when the -enable-no-signed-zeros-fp-math is specified on t...
virtual const SelectionDAGTargetInfo * getSelectionDAGInfo() const
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations...
SetCC operator - This evaluates to a true value iff the condition is true.
virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const
Return true if folding a constant offset with the given GlobalAddress is legal.
APInt bitcastToAPInt() const
static SDNode * isConstantFPBuildVectorOrConstantFP(SDValue N)
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
static SDValue narrowExtractedVectorLoad(SDNode *Extract, SelectionDAG &DAG)
If we are extracting a subvector from a wide vector load, convert to a narrow load to eliminate the e...
bool operator==(uint64_t V1, const APInt &V2)
unsigned getNumOperands() const
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
virtual bool isShuffleMaskLegal(ArrayRef< int >, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
static bool isVolatile(Instruction *Inst)
static APInt getNullValue(unsigned numBits)
Get the '0' value.
const SDValue & getOperand(unsigned i) const
SDNode * getUser()
This returns the SDNode that contains this Use.
unsigned getGatherAllAliasesMaxDepth() const
uint64_t getZExtValue() const
SDNode * getNodeIfExists(unsigned Opcode, SDVTList VTList, ArrayRef< SDValue > Ops, const SDNodeFlags Flags=SDNodeFlags())
Get the specified node if it's already available, or else return NULL.
TRUNCATE - Completely drop the high bits.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
bool hasTargetDAGCombine(ISD::NodeType NT) const
If true, the target has custom DAG combine transformations that it can perform for the specified node...
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
virtual bool hasBitPreservingFPLogic(EVT VT) const
Return true if it is safe to transform an integer-domain bitwise operation into the equivalent floati...
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
virtual bool isDesirableToCommuteWithShift(const SDNode *N) const
Return true if it is profitable to move a following shift through this.
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
const SDValue & getBasePtr() const
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
LLVMContext * getContext() const
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
bool isOperationExpand(unsigned Op, EVT VT) const
Return true if the specified operation is illegal on this target or unlikely to be made legal with cu...
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL, bool LegalTypes=true) const
bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
Carry-using nodes for multiple precision addition and subtraction.
const SDValue & getMask() const
bool isNullValue() const
Determine if all bits are clear.
CARRY_FALSE - This node is used when folding other nodes, like ADDC/SUBC, which indicate the carry re...
virtual bool isNarrowingProfitable(EVT, EVT) const
Return true if it's profitable to narrow operations of type VT1 to VT2.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
virtual bool isFAbsFree(EVT VT) const
Return true if an fabs operation is free to the point where it is never worthwhile to replace it with...
This file describes how to lower LLVM code to machine code.
void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO)
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
static bool isConstantOrConstantVector(SDValue N, bool NoOpaques=false)
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
This class is used to represent ISD::LOAD nodes.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.