47 #define DEBUG_TYPE "dagcombine"
49 STATISTIC(NodesCombined ,
"Number of dag nodes combined");
50 STATISTIC(PreIndexedNodes ,
"Number of pre-indexed nodes created");
51 STATISTIC(PostIndexedNodes,
"Number of post-indexed nodes created");
52 STATISTIC(OpsNarrowed ,
"Number of load/op/store narrowed");
53 STATISTIC(LdStFP2Int ,
"Number of fp load/store pairs transformed to int");
54 STATISTIC(SlicedLoads,
"Number of load sliced");
58 CombinerGlobalAA(
"combiner-global-alias-analysis",
cl::Hidden,
59 cl::desc(
"Enable DAG combiner's use of IR alias analysis"));
63 cl::desc(
"Enable DAG combiner's use of TBAA"));
67 CombinerAAOnlyFunc(
"combiner-aa-only-func",
cl::Hidden,
68 cl::desc(
"Only use DAG-combiner alias analysis in this"
75 StressLoadSlicing(
"combiner-stress-load-slicing",
cl::Hidden,
76 cl::desc(
"Bypass the profitability model of load "
82 cl::desc(
"DAG combiner may split indexing from loads"));
122 void AddUsersToWorklist(
SDNode *
N) {
133 void AddToWorklist(
SDNode *N) {
135 "Deleted Node added to Worklist");
142 if (WorklistMap.insert(std::make_pair(N, Worklist.size())).second)
143 Worklist.push_back(N);
147 void removeFromWorklist(
SDNode *N) {
148 CombinedNodes.erase(N);
150 auto It = WorklistMap.find(N);
151 if (It == WorklistMap.end())
155 Worklist[It->second] =
nullptr;
156 WorklistMap.erase(It);
159 void deleteAndRecombine(
SDNode *N);
160 bool recursivelyDeleteUnusedNodes(
SDNode *N);
168 return CombineTo(N, &Res, 1, AddTo);
175 return CombineTo(N, To, 2, AddTo);
181 unsigned MaximumLegalStoreInBits;
189 return SimplifyDemandedBits(Op, Demanded);
192 bool SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded);
194 bool CombineToPreIndexedLoadStore(
SDNode *N);
195 bool CombineToPostIndexedLoadStore(
SDNode *N);
197 bool SliceUpLoad(
SDNode *N);
207 SDValue ReplaceExtractVectorEltOfLoadWithNarrowedLoad(
357 bool NotExtCompare =
false);
363 const SDLoc &
DL,
bool foldBooleans =
true);
367 bool isOneUseSetCC(
SDValue N)
const;
388 bool DemandHighBits =
true);
392 unsigned PosOpcode,
unsigned NegOpcode,
406 SDValue VecIn2,
unsigned LeftIdx);
438 : MemNode(N), OffsetFromBase(Offset) {}
442 int64_t OffsetFromBase;
449 bool isMulAddWithConstProfitable(
SDNode *MulNode,
460 EVT LoadResultTy,
EVT &ExtVT,
EVT &LoadedVT,
473 EVT MemVT,
unsigned NumStores,
474 bool IsConstantSrc,
bool UseVector,
485 bool checkMergeStoreCandidatesForDependencies(
505 OptLevel(OL), LegalOperations(
false), LegalTypes(
false), AA(AA) {
506 ForCodeSize = DAG.getMachineFunction().getFunction()->optForSize();
508 MaximumLegalStoreInBits = 0;
511 TLI.isTypeLegal(
EVT(VT)) &&
512 VT.getSizeInBits() >= MaximumLegalStoreInBits)
513 MaximumLegalStoreInBits = VT.getSizeInBits();
523 EVT getShiftAmountTy(
EVT LHSTy) {
527 auto &
DL = DAG.getDataLayout();
528 return LegalTypes ? TLI.getScalarShiftAmountTy(
DL, LHSTy)
529 : TLI.getPointerTy(
DL);
534 bool isTypeLegal(
const EVT &VT) {
535 if (!LegalTypes)
return true;
536 return TLI.isTypeLegal(VT);
540 EVT getSetCCResultType(
EVT VT)
const {
541 return TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
553 explicit WorklistRemover(DAGCombiner &dc)
557 DC.removeFromWorklist(N);
567 ((DAGCombiner*)
DC)->AddToWorklist(N);
572 return ((DAGCombiner*)
DC)->CombineTo(N, &To[0], To.
size(), AddTo);
577 return ((DAGCombiner*)
DC)->CombineTo(N, Res, AddTo);
583 return ((DAGCombiner*)
DC)->CombineTo(N, Res0, Res1, AddTo);
588 return ((DAGCombiner*)
DC)->CommitTargetLoweringOpt(TLO);
595 void DAGCombiner::deleteAndRecombine(
SDNode *N) {
596 removeFromWorklist(N);
616 unsigned Depth = 0) {
624 if (
Depth > 6)
return 0;
627 default:
return false;
629 if (!LegalOperations)
643 if (LegalOperations &&
656 if (!Options->NoSignedZerosFPMath &&
665 if (Options->HonorSignDependentRoundingFPMath())
return 0;
685 bool LegalOperations,
unsigned Depth = 0) {
693 assert(
Depth <= 6 &&
"GetNegatedExpression doesn't match isNegatibleForFree");
700 APFloat V = cast<ConstantFPSDNode>(
Op)->getValueAPF();
713 LegalOperations,
Depth+1),
718 LegalOperations,
Depth+1),
739 LegalOperations,
Depth+1),
746 LegalOperations,
Depth+1), Flags);
752 LegalOperations,
Depth+1));
756 LegalOperations,
Depth+1),
802 bool DAGCombiner::isOneUseSetCC(
SDValue N)
const {
812 if (isa<ConstantFPSDNode>(N))
824 return !(Const->isOpaque() && NoOpaques);
844 return Splat->isNullValue();
854 return Splat->isOne() && Splat->getAPIntValue().getBitWidth() == BitWidth;
864 return Splat->isAllOnesValue() &&
865 Splat->getAPIntValue().getBitWidth() == BitWidth;
881 if (
SDNode *R = DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
883 if (
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, DL, VT,
L, R))
884 return DAG.getNode(Opc, DL, VT, N0.
getOperand(0), OpNode);
893 AddToWorklist(OpNode.
getNode());
900 if (
SDNode *R = DAG.isConstantIntBuildVectorOrConstantInt(N1.
getOperand(1))) {
901 if (
SDNode *
L = DAG.isConstantIntBuildVectorOrConstantInt(N0)) {
903 if (
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, DL, VT, R,
L))
904 return DAG.getNode(Opc, DL, VT, N1.
getOperand(0), OpNode);
913 AddToWorklist(OpNode.
getNode());
928 dbgs() <<
"\nWith: ";
930 dbgs() <<
" and " << NumTo-1 <<
" other values\n");
931 for (
unsigned i = 0, e = NumTo; i != e; ++i)
932 assert((!To[i].getNode() ||
934 "Cannot combine value to value of different type!");
936 WorklistRemover DeadNodes(*
this);
937 DAG.ReplaceAllUsesWith(N, To);
940 for (
unsigned i = 0, e = NumTo; i != e; ++i) {
941 if (To[i].getNode()) {
942 AddToWorklist(To[i].getNode());
943 AddUsersToWorklist(To[i].getNode());
952 deleteAndRecombine(N);
960 WorklistRemover DeadNodes(*
this);
961 DAG.ReplaceAllUsesOfValueWith(TLO.
Old, TLO.
New);
976 bool DAGCombiner::SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded) {
979 if (!TLI.SimplifyDemandedBits(Op, Demanded, Known, TLO))
989 dbgs() <<
"\nWith: ";
993 CommitTargetLoweringOpt(TLO);
997 void DAGCombiner::ReplaceLoadWithPromotedLoad(
SDNode *
Load,
SDNode *ExtLoad) {
1004 dbgs() <<
"\nWith: ";
1007 WorklistRemover DeadNodes(*
this);
1008 DAG.ReplaceAllUsesOfValueWith(
SDValue(Load, 0), Trunc);
1009 DAG.ReplaceAllUsesOfValueWith(
SDValue(Load, 1),
SDValue(ExtLoad, 1));
1010 deleteAndRecombine(Load);
1011 AddToWorklist(Trunc.
getNode());
1025 return DAG.getExtLoad(ExtType, DL, PVT,
1044 return DAG.getNode(ExtOpc, DL, PVT, Op);
1058 bool Replace =
false;
1059 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
1062 AddToWorklist(NewOp.
getNode());
1073 bool Replace =
false;
1074 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
1077 AddToWorklist(NewOp.
getNode());
1081 return DAG.getZeroExtendInReg(NewOp, DL, OldVT);
1088 if (!LegalOperations)
1098 if (TLI.isTypeDesirableForOp(Opc, VT))
1104 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
1105 assert(PVT != VT &&
"Don't know what type to promote to!");
1109 bool Replace0 =
false;
1111 SDValue NN0 = PromoteOperand(N0, PVT, Replace0);
1113 bool Replace1 =
false;
1115 SDValue NN1 = PromoteOperand(N1, PVT, Replace1);
1124 Replace1 &= (N0 != N1) && !N1->
hasOneUse();
1153 if (!LegalOperations)
1163 if (TLI.isTypeDesirableForOp(Opc, VT))
1169 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
1170 assert(PVT != VT &&
"Don't know what type to promote to!");
1174 bool Replace =
false;
1178 N0 = SExtPromoteOperand(N0, PVT);
1180 N0 = ZExtPromoteOperand(N0, PVT);
1182 N0 = PromoteOperand(N0, PVT, Replace);
1203 if (!LegalOperations)
1213 if (TLI.isTypeDesirableForOp(Opc, VT))
1219 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
1220 assert(PVT != VT &&
"Don't know what type to promote to!");
1231 bool DAGCombiner::PromoteLoad(
SDValue Op) {
1232 if (!LegalOperations)
1245 if (TLI.isTypeDesirableForOp(Opc, VT))
1251 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
1252 assert(PVT != VT &&
"Don't know what type to promote to!");
1262 SDValue NewLD = DAG.getExtLoad(ExtType, DL, PVT,
1272 WorklistRemover DeadNodes(*
this);
1273 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 0), Result);
1275 deleteAndRecombine(N);
1276 AddToWorklist(Result.
getNode());
1288 bool DAGCombiner::recursivelyDeleteUnusedNodes(
SDNode *N) {
1301 Nodes.
insert(ChildN.getNode());
1303 removeFromWorklist(N);
1308 }
while (!Nodes.
empty());
1323 for (
SDNode &Node : DAG.allnodes())
1324 AddToWorklist(&Node);
1332 while (!WorklistMap.empty()) {
1336 N = Worklist.pop_back_val();
1339 bool GoodWorklistEntry = WorklistMap.erase(N);
1340 (void)GoodWorklistEntry;
1341 assert(GoodWorklistEntry &&
1342 "Found a worklist entry without a corresponding map entry!");
1347 if (recursivelyDeleteUnusedNodes(N))
1350 WorklistRemover DeadNodes(*
this);
1356 bool NIsValid = DAG.LegalizeOp(N, UpdatedNodes);
1358 for (
SDNode *LN : UpdatedNodes) {
1360 AddUsersToWorklist(LN);
1371 CombinedNodes.insert(N);
1373 if (!CombinedNodes.count(ChildN.getNode()))
1374 AddToWorklist(ChildN.getNode());
1387 if (RV.getNode() ==
N)
1392 "Node was deleted but visit returned new node!");
1395 RV.getNode()->dump(&DAG));
1398 DAG.ReplaceAllUsesWith(N, RV.getNode());
1402 DAG.ReplaceAllUsesWith(N, &RV);
1406 AddToWorklist(RV.getNode());
1407 AddUsersToWorklist(RV.getNode());
1413 recursivelyDeleteUnusedNodes(N);
1417 DAG.setRoot(
Dummy.getValue());
1418 DAG.RemoveDeadNodes();
1452 case ISD::OR:
return visitOR(N);
1533 "Node was deleted but visit returned NULL!");
1540 DagCombineInfo(DAG,
Level,
false,
this);
1542 RV = TLI.PerformDAGCombine(N, DagCombineInfo);
1556 RV = PromoteIntBinOp(
SDValue(N, 0));
1561 RV = PromoteIntShiftOp(
SDValue(N, 0));
1566 RV = PromoteExtend(
SDValue(N, 0));
1569 if (PromoteLoad(
SDValue(N, 0)))
1583 if (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1)) {
1603 for (
unsigned i = 1; i < NumOps-1; ++i)
1623 bool Changed =
false;
1630 for (
unsigned i = 0; i < TFs.
size(); ++i) {
1675 bool DidPruneOps =
false;
1677 unsigned NumLeftToConsider = 0;
1678 for (
const SDValue &Op : Ops) {
1683 auto AddToWorklist = [&](
unsigned CurIdx,
SDNode *
Op,
unsigned OpNumber) {
1686 if (SeenOps.
count(Op) != 0) {
1689 unsigned OrigOpNumber = 0;
1690 while (OrigOpNumber < Ops.size() && Ops[OrigOpNumber].getNode() !=
Op)
1692 assert((OrigOpNumber != Ops.size()) &&
1693 "expected to find TokenFactor Operand");
1695 for (
unsigned i = CurIdx + 1; i < Worklist.
size(); ++i) {
1696 if (Worklist[i].
second == OrigOpNumber) {
1697 Worklist[i].second = OpNumber;
1700 OpWorkCount[OpNumber] += OpWorkCount[OrigOpNumber];
1701 OpWorkCount[OrigOpNumber] = 0;
1702 NumLeftToConsider--;
1705 if (SeenChains.
insert(Op).second) {
1706 OpWorkCount[OpNumber]++;
1707 Worklist.
push_back(std::make_pair(Op, OpNumber));
1711 for (
unsigned i = 0; i < Worklist.
size() && i < 1024; ++i) {
1713 if (NumLeftToConsider <= 1)
1715 auto CurNode = Worklist[i].first;
1716 auto CurOpNumber = Worklist[i].second;
1717 assert((OpWorkCount[CurOpNumber] > 0) &&
1718 "Node should not appear in worklist");
1719 switch (CurNode->getOpcode()) {
1725 NumLeftToConsider++;
1729 AddToWorklist(i, Op.getNode(), CurOpNumber);
1733 AddToWorklist(i, CurNode->getOperand(0).getNode(), CurOpNumber);
1736 if (
auto *MemNode = dyn_cast<MemSDNode>(CurNode))
1737 AddToWorklist(i, MemNode->getChain().getNode(), CurOpNumber);
1740 OpWorkCount[CurOpNumber]--;
1741 if (OpWorkCount[CurOpNumber] == 0)
1742 NumLeftToConsider--;
1750 Result = DAG.getEntryNode();
1755 for (
const SDValue &Op : Ops) {
1756 if (SeenChains.
count(Op.getNode()) == 0)
1771 WorklistRemover DeadNodes(*
this);
1777 AddUsersToWorklist(N);
1782 deleteAndRecombine(N);
1790 return Const !=
nullptr && !Const->
isOpaque() ? Const :
nullptr;
1804 "Unexpected binary operator");
1837 "Failed to constant fold a binop with constant operands");
1842 "Failed to constant fold a binop with constant operands");
1844 return DAG.getSelect(DL, VT, Sel.
getOperand(0), NewCT, NewCF);
1855 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
1872 if (DAG.isConstantIntBuildVectorOrConstantInt(N0)) {
1874 if (!DAG.isConstantIntBuildVectorOrConstantInt(N1))
1902 if ((!LegalOperations ||
1912 if (
SDValue NewSel = foldBinOpIntoSelect(N))
1938 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
1939 N0 == N1.getOperand(1).getOperand(0))
1941 N1.getOperand(1).getOperand(1));
1944 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
1945 N0 == N1.getOperand(1).getOperand(1))
1946 return DAG.getNode(
ISD::SUB, DL, VT, N1.getOperand(0),
1947 N1.getOperand(1).getOperand(0));
1951 N1.getOperand(0).getOpcode() ==
ISD::SUB &&
1952 N0 == N1.getOperand(0).getOperand(1))
1953 return DAG.getNode(N1.getOpcode(),
DL, VT, N1.getOperand(0).getOperand(0),
1973 if ((!LegalOperations || TLI.isOperationLegal(
ISD::OR, VT)) &&
1974 DAG.haveNoCommonBitsSet(N0, N1))
1977 if (
SDValue Combined = visitADDLike(N0, N1, N))
1980 if (
SDValue Combined = visitADDLike(N1, N0, N))
1987 bool Masked =
false;
2031 return DAG.getNode(
ISD::SUB, DL, VT, N0,
2038 unsigned NumSignBits = DAG.ComputeNumSignBits(AndOp0);
2043 if (NumSignBits == DestBits &&
2045 return DAG.getNode(
ISD::SUB, DL, VT, N0, AndOp0);
2053 return DAG.getNode(
ISD::SUB, DL, VT, N1, ZExt);
2061 DAG.getConstant(1, DL, VT));
2062 return DAG.getNode(
ISD::SUB, DL, VT, N0, ZExt);
2075 DAG.getVTList(VT, Carry.getValueType()), N0,
2076 DAG.getConstant(0, DL, VT), Carry);
2089 return CombineTo(N, DAG.getNode(
ISD::ADD, DL, VT, N0, N1),
2105 return CombineTo(N, DAG.getNode(
ISD::ADD, DL, VT, N0, N1),
2123 return CombineTo(N, DAG.getNode(
ISD::ADD, DL, VT, N0, N1),
2124 DAG.getUNDEF(CarryVT));
2134 return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT));
2138 return CombineTo(N, DAG.getNode(
ISD::ADD, DL, VT, N0, N1),
2139 DAG.getConstant(0, DL, CarryVT));
2141 if (
SDValue Combined = visitUADDOLike(N0, N1, N))
2144 if (
SDValue Combined = visitUADDOLike(N1, N0, N))
2167 DAG.getConstant(0,
SDLoc(N), VT), Carry);
2209 EVT VT = N0.getValueType();
2211 SDValue CarryExt = DAG.getBoolExtOrTrunc(CarryIn, DL, VT, CarryVT);
2212 AddToWorklist(CarryExt.
getNode());
2213 return CombineTo(N, DAG.getNode(
ISD::AND, DL, VT, CarryExt,
2214 DAG.getConstant(1, DL, VT)),
2215 DAG.getConstant(0, DL, CarryVT));
2218 if (
SDValue Combined = visitADDCARRYLike(N0, N1, CarryIn, N))
2221 if (
SDValue Combined = visitADDCARRYLike(N1, N0, CarryIn, N))
2263 Y.getOperand(0), Y.getOperand(1),
2265 AddToWorklist(NewY.getNode());
2295 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2306 return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations, LegalTypes);
2307 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
2308 DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
2314 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2321 return DAG.getNode(
ISD::ADD, DL, VT, N0,
2333 if (ShiftAmt && ShiftAmt->
getZExtValue() == BitWidth - 1) {
2335 if (!LegalOperations || TLI.isOperationLegal(NewSh, VT))
2364 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(0) == N1)
2368 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(1) == N1)
2383 (N0.getOperand(1).getOpcode() ==
ISD::SUB ||
2384 N0.getOperand(1).getOpcode() ==
ISD::ADD) &&
2385 N0.getOperand(1).getOperand(0) == N1)
2386 return DAG.getNode(N0.getOperand(1).getOpcode(),
DL, VT, N0.getOperand(0),
2387 N0.getOperand(1).getOperand(1));
2390 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(1).getOpcode() ==
ISD::ADD &&
2391 N0.getOperand(1).getOperand(1) == N1)
2392 return DAG.getNode(
ISD::ADD, DL, VT, N0.getOperand(0),
2393 N0.getOperand(1).getOperand(0));
2396 if (N0.getOpcode() ==
ISD::SUB && N0.getOperand(1).getOpcode() ==
ISD::SUB &&
2397 N0.getOperand(1).getOperand(1) == N1)
2398 return DAG.getNode(
ISD::SUB, DL, VT, N0.getOperand(0),
2399 N0.getOperand(1).getOperand(0));
2409 if (!LegalOperations && TLI.isOffsetFoldingLegal(GA)) {
2412 return DAG.getGlobalAddress(GA->getGlobal(),
SDLoc(N1C), VT,
2417 if (GA->getGlobal() == GB->getGlobal())
2418 return DAG.getConstant((uint64_t)GA->getOffset() - GB->getOffset(),
2427 DAG.getConstant(1, DL, VT));
2428 return DAG.getNode(
ISD::ADD, DL, VT, N0, ZExt);
2443 return CombineTo(N, DAG.getNode(
ISD::SUB, DL, VT, N0, N1),
2448 return CombineTo(N, DAG.getConstant(0, DL, VT),
2457 return CombineTo(N, DAG.getNode(
ISD::XOR, DL, VT, N1, N0),
2475 return CombineTo(N, DAG.getNode(
ISD::SUB, DL, VT, N0, N1),
2476 DAG.getUNDEF(CarryVT));
2480 return CombineTo(N, DAG.getConstant(0, DL, VT),
2481 DAG.getConstant(0, DL, CarryVT));
2485 return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT));
2489 return CombineTo(N, DAG.getNode(
ISD::XOR, DL, VT, N1, N0),
2490 DAG.getConstant(0, DL, CarryVT));
2526 return DAG.getConstant(0,
SDLoc(N), VT);
2528 bool N0IsConst =
false;
2529 bool N1IsConst =
false;
2530 bool N1IsOpaqueConst =
false;
2531 bool N0IsOpaqueConst =
false;
2532 APInt ConstValue0, ConstValue1;
2535 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2541 N0IsConst = isa<ConstantSDNode>(N0);
2543 ConstValue0 = cast<ConstantSDNode>(N0)->getAPIntValue();
2544 N0IsOpaqueConst = cast<ConstantSDNode>(N0)->isOpaque();
2546 N1IsConst = isa<ConstantSDNode>(N1);
2548 ConstValue1 = cast<ConstantSDNode>(N1)->getAPIntValue();
2549 N1IsOpaqueConst = cast<ConstantSDNode>(N1)->isOpaque();
2554 if (N0IsConst && N1IsConst && !N0IsOpaqueConst && !N1IsOpaqueConst)
2559 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
2560 !DAG.isConstantIntBuildVectorOrConstantInt(N1))
2570 if (N1IsConst && ConstValue1.
isOneValue() && IsFullSplat)
2573 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2579 return DAG.getNode(
ISD::SUB, DL, VT,
2580 DAG.getConstant(0, DL, VT), N0);
2583 if (N1IsConst && !N1IsOpaqueConst && ConstValue1.
isPowerOf2() &&
2586 return DAG.getNode(
ISD::SHL, DL, VT, N0,
2591 if (N1IsConst && !N1IsOpaqueConst && (-ConstValue1).isPowerOf2() &&
2593 unsigned Log2Val = (-ConstValue1).logBase2();
2597 return DAG.getNode(
ISD::SUB, DL, VT,
2598 DAG.getConstant(0, DL, VT),
2600 DAG.getConstant(Log2Val, DL,
2616 SDValue Sh(
nullptr, 0),
Y(
nullptr, 0);
2636 if (DAG.isConstantIntBuildVectorOrConstantInt(N1) &&
2638 DAG.isConstantIntBuildVectorOrConstantInt(N0.
getOperand(1)) &&
2639 isMulAddWithConstProfitable(N, N0, N1))
2661 default:
return false;
2686 if (!TLI.isTypeLegal(VT) && !TLI.isOperationCustom(DivRemOpc, VT))
2691 if (!TLI.isOperationLegalOrCustom(DivRemOpc, VT) &&
2696 unsigned OtherOpcode = 0;
2699 if (TLI.isOperationLegalOrCustom(Opcode, VT))
2703 if (TLI.isOperationLegalOrCustom(OtherOpcode, VT))
2719 if ((UserOpc == Opcode || UserOpc == OtherOpcode || UserOpc == DivRemOpc) &&
2723 if (UserOpc == OtherOpcode) {
2724 SDVTList VTs = DAG.getVTList(VT, VT);
2725 combined = DAG.
getNode(DivRemOpc,
SDLoc(Node), VTs, Op0, Op1);
2726 }
else if (UserOpc == DivRemOpc) {
2729 assert(UserOpc == Opcode);
2734 CombineTo(User, combined);
2736 CombineTo(User, combined.
getValue(1));
2766 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2775 return DAG.FoldConstantArithmetic(
ISD::SDIV, DL, VT, N0C, N1C);
2777 if (N1C && N1C->
isOne())
2786 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2791 if (DAG.SignBitIsZero(N1) && DAG.SignBitIsZero(N0))
2820 AddToWorklist(SRL.getNode());
2823 DAG.getConstant(lg2, DL,
2831 AddToWorklist(SRA.getNode());
2832 return DAG.getNode(
ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
SRA);
2839 if (N1C && !TLI.isIntDivCheap(N->
getValueType(0), Attr))
2846 if (!N1C || TLI.isIntDivCheap(N->
getValueType(0), Attr))
2860 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
2876 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2881 DAG.isKnownToBeAPowerOfTwo(N1)) {
2882 SDValue LogBase2 = BuildLogBase2(N1, DL);
2883 AddToWorklist(LogBase2.
getNode());
2886 SDValue Trunc = DAG.getZExtOrTrunc(LogBase2, DL, ShiftVT);
2887 AddToWorklist(Trunc.getNode());
2895 DAG.isKnownToBeAPowerOfTwo(N10)) {
2896 SDValue LogBase2 = BuildLogBase2(N10, DL);
2897 AddToWorklist(LogBase2.
getNode());
2900 SDValue Trunc = DAG.getZExtOrTrunc(LogBase2, DL, ADDVT);
2901 AddToWorklist(Trunc.
getNode());
2903 AddToWorklist(Add.getNode());
2904 return DAG.getNode(
ISD::SRL, DL, VT, N0, Add);
2910 if (N1C && !TLI.isIntDivCheap(N->
getValueType(0), Attr))
2917 if (!N1C || TLI.isIntDivCheap(N->
getValueType(0), Attr))
2937 if (
SDValue Folded = DAG.FoldConstantArithmetic(Opcode, DL, VT, N0C, N1C))
2943 if (
SDValue NewSel = foldBinOpIntoSelect(N))
2949 if (DAG.SignBitIsZero(N1) && DAG.SignBitIsZero(N0))
2950 return DAG.getNode(
ISD::UREM, DL, VT, N0, N1);
2952 SDValue NegOne = DAG.getAllOnesConstant(DL, VT);
2953 if (DAG.isKnownToBeAPowerOfTwo(N1)) {
2957 return DAG.getNode(
ISD::AND, DL, VT, N0, Add);
2960 DAG.isKnownToBeAPowerOfTwo(N1.
getOperand(0))) {
2964 return DAG.getNode(
ISD::AND, DL, VT, N0, Add);
2978 if (N1C && !N1C->
isNullValue() && !TLI.isIntDivCheap(VT, Attr)) {
2983 if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.
getNode()) {
2995 return DivRem.getValue(1);
3018 return DAG.getConstant(0,
SDLoc(N), VT);
3026 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
3031 DAG.getConstant(SimpleSize, DL,
3054 return DAG.getConstant(0, DL, VT);
3062 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
3067 DAG.getConstant(SimpleSize, DL,
3079 SDValue DAGCombiner::SimplifyNodeWithTwoResults(
SDNode *N,
unsigned LoOp,
3084 (!LegalOperations ||
3085 TLI.isOperationLegalOrCustom(LoOp, N->
getValueType(0)))) {
3087 return CombineTo(N, Res, Res);
3093 (!LegalOperations ||
3096 return CombineTo(N, Res, Res);
3100 if (LoExists && HiExists)
3108 if (LoOpt.getNode() && LoOpt.getNode() != Lo.
getNode() &&
3109 (!LegalOperations ||
3110 TLI.isOperationLegal(LoOpt.getOpcode(), LoOpt.getValueType())))
3111 return CombineTo(N, LoOpt, LoOpt);
3118 if (HiOpt.getNode() && HiOpt != Hi &&
3119 (!LegalOperations ||
3120 TLI.isOperationLegal(HiOpt.getOpcode(), HiOpt.getValueType())))
3121 return CombineTo(N, HiOpt, HiOpt);
3140 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
3146 DAG.getConstant(SimpleSize, DL,
3151 return CombineTo(N, Lo, Hi);
3171 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
3177 DAG.getConstant(SimpleSize, DL,
3182 return CombineTo(N, Lo, Hi);
3192 if (C2->getAPIntValue() == 2)
3202 if (C2->getAPIntValue() == 2)
3216 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
3223 return DAG.FoldConstantArithmetic(N->
getOpcode(),
SDLoc(N), VT, N0C, N1C);
3226 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
3227 !DAG.isConstantIntBuildVectorOrConstantInt(N1))
3235 SDValue DAGCombiner::SimplifyBinOpWithSameOpcodeHands(
SDNode *N) {
3258 (!LegalTypes || TLI.isTypeDesirableForOp(N->
getOpcode(), Op0VT))) ||
3260 (!TLI.isZExtFree(VT, Op0VT) ||
3261 !TLI.isTruncateFree(Op0VT, VT)) &&
3262 TLI.isTypeLegal(Op0VT))) &&
3265 (!LegalOperations || TLI.isOperationLegal(N->
getOpcode(), Op0VT))) {
3269 AddToWorklist(ORNode.
getNode());
3283 AddToWorklist(ORNode.
getNode());
3330 "Inputs to shuffles are not the same type");
3336 if (SVN0->
hasOneUse() && SVN1->hasOneUse() &&
3337 SVN0->
getMask().equals(SVN1->getMask())) {
3344 ShOp = DAG.getConstant(0,
SDLoc(N), VT);
3355 AddToWorklist(NewNode.
getNode());
3356 return DAG.getVectorShuffle(VT,
SDLoc(N), NewNode, ShOp,
3365 ShOp = DAG.getConstant(0,
SDLoc(N), VT);
3376 AddToWorklist(NewNode.
getNode());
3377 return DAG.getVectorShuffle(VT,
SDLoc(N), ShOp, NewNode,
3389 SDValue LL, LR, RL, RR, N0CC, N1CC;
3390 if (!isSetCCEquivalent(N0, LL, LR, N0CC) ||
3391 !isSetCCEquivalent(N1, RL, RR, N1CC))
3395 "Unexpected operand types for bitwise logic op");
3398 "Unexpected operand types for setcc");
3405 if (LegalOperations || VT !=
MVT::i1)
3414 if (LR == RR && CC0 == CC1 && IsInteger) {
3419 bool AndEqZero = IsAnd && CC1 ==
ISD::SETEQ && IsZero;
3421 bool AndGtNeg1 = IsAnd && CC1 ==
ISD::SETGT && IsNeg1;
3423 bool OrNeZero = !IsAnd && CC1 ==
ISD::SETNE && IsZero;
3425 bool OrLtZero = !IsAnd && CC1 ==
ISD::SETLT && IsZero;
3431 if (AndEqZero || AndGtNeg1 || OrNeZero || OrLtZero) {
3434 return DAG.getSetCC(DL, VT, Or, LR, CC1);
3438 bool AndEqNeg1 = IsAnd && CC1 ==
ISD::SETEQ && IsNeg1;
3440 bool AndLtZero = IsAnd && CC1 ==
ISD::SETLT && IsZero;
3442 bool OrNeNeg1 = !IsAnd && CC1 ==
ISD::SETNE && IsNeg1;
3444 bool OrGtNeg1 = !IsAnd && CC1 ==
ISD::SETGT && IsNeg1;
3450 if (AndEqNeg1 || AndLtZero || OrNeNeg1 || OrGtNeg1) {
3453 return DAG.getSetCC(DL, VT, And, LR, CC1);
3459 if (IsAnd && LL == RL && CC0 == CC1 && IsInteger && CC0 ==
ISD::SETNE &&
3462 SDValue One = DAG.getConstant(1, DL, OpVT);
3463 SDValue Two = DAG.getConstant(2, DL, OpVT);
3466 return DAG.getSetCC(DL, VT, Add, Two,
ISD::SETUGE);
3471 if (IsInteger && TLI.convertSetCCLogicToBitwiseLogic(OpVT) && CC0 == CC1 &&
3480 return DAG.getSetCC(DL, VT, Or, Zero, CC1);
3485 if (LL == RR && LR == RL) {
3492 if (LL == RL && LR == RR) {
3496 (!LegalOperations ||
3499 return DAG.getSetCC(DL, VT, LL, LR, NewCC);
3515 return DAG.getConstant(0, DL, VT);
3517 if (
SDValue V = foldLogicOfSetCCs(
true, N0, N1, DL))
3531 SRLI->getZExtValue());
3538 N0.
getOperand(0), DAG.getConstant(ADDC, DL, VT));
3539 CombineTo(N0.
getNode(), NewAdd);
3556 const APInt &AndMask = CAnd->getAPIntValue();
3569 (ShiftBits + MaskBits <= Size / 2) &&
3570 TLI.isNarrowingProfitable(VT, HalfVT) &&
3571 TLI.isTypeDesirableForOp(
ISD::AND, HalfVT) &&
3572 TLI.isTypeDesirableForOp(
ISD::SRL, HalfVT) &&
3573 TLI.isTruncateFree(VT, HalfVT) &&
3574 TLI.isZExtFree(HalfVT, VT)) {
3581 assert(MaskBits <= Size);
3584 EVT ShiftVT = TLI.getShiftAmountTy(HalfVT, DAG.getDataLayout());
3588 SDValue NewMask = DAG.getConstant(AndMask.
trunc(Size / 2), SL, HalfVT);
3589 SDValue ShiftK = DAG.getConstant(ShiftBits, SL, ShiftVT);
3602 EVT LoadResultTy,
EVT &ExtVT,
EVT &LoadedVT,
3612 if (ExtVT == LoadedVT &&
3613 (!LegalOperations ||
3627 if (!LoadedVT.bitsGT(ExtVT) || !ExtVT.
isRound())
3630 if (LegalOperations &&
3634 if (!TLI.shouldReduceLoadWidth(LoadN,
ISD::ZEXTLOAD, ExtVT))
3652 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
3675 if (N0C && N1C && !N1C->
isOpaque())
3676 return DAG.FoldConstantArithmetic(
ISD::AND,
SDLoc(N), VT, N0C, N1C);
3678 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
3679 !DAG.isConstantIntBuildVectorOrConstantInt(N1))
3686 if (N1C && DAG.MaskedValueIsZero(
SDValue(N, 0),
3688 return DAG.getConstant(0,
SDLoc(N), VT);
3690 if (
SDValue NewSel = foldBinOpIntoSelect(N))
3706 if (DAG.MaskedValueIsZero(N0Op0, Mask)) {
3716 CombineTo(N0.
getNode(), Zext);
3739 Constant =
C->getAPIntValue();
3741 APInt SplatValue, SplatUndef;
3742 unsigned SplatBitSize;
3744 bool IsSplat = Vector->isConstantSplat(SplatValue, SplatUndef,
3745 SplatBitSize, HasAnyUndefs);
3749 SplatValue |= SplatUndef;
3755 EVT VT = Vector->getValueType(0);
3761 if (BitWidth > SplatBitSize)
3762 for (SplatValue = SplatValue.
zextOrTrunc(BitWidth);
3763 SplatBitSize < BitWidth;
3764 SplatBitSize = SplatBitSize * 2)
3765 SplatValue |= SplatValue.
shl(SplatBitSize);
3769 if (SplatBitSize % BitWidth == 0) {
3771 for (
unsigned i = 0, n = SplatBitSize/BitWidth; i < n; ++i)
3780 bool CanZextLoadProfitably = TLI.isLoadExtLegal(
ISD::ZEXTLOAD,
3791 default: B =
false;
break;
3797 if (B && Constant.isAllOnesValue()) {
3803 CombineTo(N, (N0.
getNode() ==
Load) ? NewLoad : N0);
3816 CombineTo(Load, To, 3,
true);
3818 CombineTo(Load, NewLoad.getValue(0), NewLoad.getValue(1));
3835 : cast<LoadSDNode>(N0);
3838 auto NarrowLoad =
false;
3840 EVT ExtVT, LoadedVT;
3841 if (isAndLoadExtLoad(N1C, LN0, LoadResultTy, ExtVT, LoadedVT,
3849 CombineTo(LN0, NewLoad, NewLoad.
getValue(1));
3860 if (DAG.getDataLayout().isBigEndian()) {
3863 unsigned PtrOff = LVTStoreBytes - EVTStoreBytes;
3866 NewPtr, DAG.getConstant(PtrOff, DL, PtrType));
3867 Alignment =
MinAlign(Alignment, PtrOff);
3870 AddToWorklist(NewPtr.
getNode());
3872 SDValue Load = DAG.getExtLoad(
3877 CombineTo(LN0, Load, Load.getValue(1));
3884 if (
SDValue Combined = visitANDLike(N0, N1, N))
3889 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
3924 BitWidth - MemVT.getScalarSizeInBits())) &&
3944 BitWidth - MemVT.getScalarSizeInBits())) &&
3967 bool DemandHighBits) {
3968 if (!LegalOperations)
3974 if (!TLI.isOperationLegalOrCustom(
ISD::BSWAP, VT))
3978 bool LookPassAnd0 =
false;
3979 bool LookPassAnd1 =
false;
3991 LookPassAnd0 =
true;
4001 LookPassAnd1 =
true;
4015 if (N01C->
getZExtValue() != 8 || N11C->getZExtValue() != 8)
4027 LookPassAnd0 =
true;
4038 LookPassAnd1 =
true;
4047 if (DemandHighBits && OpSizeInBits > 16) {
4056 if (!LookPassAnd1 &&
4057 !DAG.MaskedValueIsZero(
4063 if (OpSizeInBits > 16) {
4066 DAG.getConstant(OpSizeInBits - 16, DL,
4100 unsigned MaskByteOffset;
4104 case 0xFF: MaskByteOffset = 0;
break;
4105 case 0xFF00: MaskByteOffset = 1;
break;
4106 case 0xFF0000: MaskByteOffset = 2;
break;
4107 case 0xFF000000: MaskByteOffset = 3;
break;
4112 if (MaskByteOffset == 0 || MaskByteOffset == 2) {
4132 if (MaskByteOffset != 0 && MaskByteOffset != 2)
4140 if (MaskByteOffset != 1 && MaskByteOffset != 3)
4147 if (Parts[MaskByteOffset])
4161 if (!LegalOperations)
4167 if (!TLI.isOperationLegalOrCustom(
ISD::BSWAP, VT))
4210 if (Parts[0] != Parts[1] || Parts[0] != Parts[2] || Parts[0] != Parts[3])
4220 if (TLI.isOperationLegalOrCustom(
ISD::ROTL, VT))
4222 if (TLI.isOperationLegalOrCustom(
ISD::ROTR, VT))
4223 return DAG.getNode(
ISD::ROTR, DL, VT, BSwap, ShAmt);
4224 return DAG.getNode(
ISD::OR, DL, VT,
4225 DAG.getNode(
ISD::SHL, DL, VT, BSwap, ShAmt),
4226 DAG.getNode(
ISD::SRL, DL, VT, BSwap, ShAmt));
4237 return DAG.getAllOnesConstant(DL, VT);
4239 if (
SDValue V = foldLogicOfSetCCs(
false, N0, N1, DL))
4254 const APInt &LHSMask = N0O1C->getAPIntValue();
4255 const APInt &RHSMask = N1O1C->getAPIntValue();
4257 if (DAG.MaskedValueIsZero(N0.
getOperand(0), RHSMask&~LHSMask) &&
4258 DAG.MaskedValueIsZero(N1.
getOperand(0), LHSMask&~RHSMask)) {
4261 return DAG.getNode(
ISD::AND, DL, VT, X,
4262 DAG.getConstant(LHSMask | RHSMask, DL, VT));
4293 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
4312 if (isa<ShuffleVectorSDNode>(N0) &&
4313 isa<ShuffleVectorSDNode>(N1) &&
4315 TLI.isTypeLegal(VT)) {
4321 if ((ZeroN00 != ZeroN01) && (ZeroN10 != ZeroN11)) {
4322 assert((!ZeroN00 || !ZeroN01) &&
"Both inputs zero!");
4323 assert((!ZeroN10 || !ZeroN11) &&
"Both inputs zero!");
4326 bool CanFold =
true;
4330 for (
int i = 0; i != NumElts; ++i) {
4332 int M1 = SV1->getMaskElt(i);
4335 bool M0Zero = M0 < 0 || (ZeroN00 == (M0 < NumElts));
4336 bool M1Zero = M1 < 0 || (ZeroN10 == (M1 < NumElts));
4340 if ((M0Zero && M1 < 0) || (M1Zero && M0 < 0)) {
4346 if (M0Zero == M1Zero) {
4351 assert((M0 >= 0 || M1 >= 0) &&
"Undef index!");
4357 Mask[i] = M1Zero ? M0 % NumElts : (M1 % NumElts) + NumElts;
4364 bool LegalMask = TLI.isShuffleMaskLegal(Mask, VT);
4368 LegalMask = TLI.isShuffleMaskLegal(Mask, VT);
4372 return DAG.getVectorShuffle(VT,
SDLoc(N), NewLHS, NewRHS, Mask);
4381 if (N0C && N1C && !N1C->
isOpaque())
4382 return DAG.FoldConstantArithmetic(
ISD::OR,
SDLoc(N), VT, N0C, N1C);
4384 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
4385 !DAG.isConstantIntBuildVectorOrConstantInt(N1))
4394 if (
SDValue NewSel = foldBinOpIntoSelect(N))
4398 if (N1C && DAG.MaskedValueIsZero(N0, ~N1C->
getAPIntValue()))
4401 if (
SDValue Combined = visitORLike(N0, N1, N))
4405 if (
SDValue BSwap = MatchBSwapHWord(N, N0, N1))
4407 if (
SDValue BSwap = MatchBSwapHWordLow(N, N0, N1))
4420 DAG.FoldConstantArithmetic(
ISD::OR,
SDLoc(N1), VT, N1C, C1))
4431 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
4438 if (
SDValue Load = MatchLoadCombine(N))
4451 if (DAG.isConstantIntBuildVectorOrConstantInt(Op.
getOperand(1))) {
4508 unsigned MaskLoBits = 0;
4511 if (NegC->getAPIntValue() == EltSize - 1) {
4513 MaskLoBits =
Log2_64(EltSize);
4530 if (PosC->getAPIntValue() == EltSize - 1)
4566 return Width.
getLoBits(MaskLoBits) == 0;
4567 return Width == EltSize;
4577 SDValue InnerNeg,
unsigned PosOpcode,
4578 unsigned NegOpcode,
const SDLoc &DL) {
4588 bool HasPos = TLI.isOperationLegalOrCustom(PosOpcode, VT);
4589 return DAG.getNode(HasPos ? PosOpcode : NegOpcode, DL, VT, Shifted,
4590 HasPos ? Pos : Neg).getNode();
4604 if (!ShiftSum)
return false;
4616 if (!TLI.isTypeLegal(VT))
return nullptr;
4619 bool HasROTL = TLI.isOperationLegalOrCustom(
ISD::ROTL, VT);
4620 bool HasROTR = TLI.isOperationLegalOrCustom(
ISD::ROTR, VT);
4621 if (!HasROTL && !HasROTR)
return nullptr;
4626 if (!MatchRotateHalf(LHS, LHSShift, LHSMask))
4631 if (!MatchRotateHalf(RHS, RHSShift, RHSMask))
4657 LHSShiftArg, HasROTL ? LHSShiftAmt : RHSShiftAmt);
4661 SDValue AllOnes = DAG.getAllOnesConstant(DL, VT);
4687 SDValue LExtOp0 = LHSShiftAmt;
4688 SDValue RExtOp0 = RHSShiftAmt;
4701 SDNode *TryL = MatchRotatePosNeg(LHSShiftArg, LHSShiftAmt, RHSShiftAmt,
4702 LExtOp0, RExtOp0,
ISD::ROTL, ISD::ROTR, DL);
4706 SDNode *TryR = MatchRotatePosNeg(RHSShiftArg, RHSShiftAmt, LHSShiftAmt,
4707 RExtOp0, LExtOp0, ISD::ROTR,
ISD::ROTL, DL);
4717 struct ByteProvider {
4722 unsigned ByteOffset;
4724 ByteProvider() : Load(nullptr), ByteOffset(0) {}
4727 return ByteProvider(Load, ByteOffset);
4729 static ByteProvider getConstantZero() {
return ByteProvider(
nullptr, 0); }
4731 bool isConstantZero()
const {
return !
Load; }
4732 bool isMemory()
const {
return Load; }
4734 bool operator==(
const ByteProvider &Other)
const {
4735 return Other.Load == Load && Other.ByteOffset == ByteOffset;
4739 ByteProvider(
LoadSDNode *Load,
unsigned ByteOffset)
4740 : Load(Load), ByteOffset(ByteOffset) {}
4756 bool Root =
false) {
4766 if (BitWidth % 8 != 0)
4768 unsigned ByteWidth = BitWidth / 8;
4769 assert(Index < ByteWidth &&
"invalid index requested");
4774 auto LHS = calculateByteProvider(Op->
getOperand(0), Index, Depth + 1);
4777 auto RHS = calculateByteProvider(Op->
getOperand(1), Index, Depth + 1);
4781 if (LHS->isConstantZero())
4783 if (RHS->isConstantZero())
4792 uint64_t BitShift = ShiftOp->getZExtValue();
4793 if (BitShift % 8 != 0)
4795 uint64_t ByteShift = BitShift / 8;
4797 return Index < ByteShift
4798 ? ByteProvider::getConstantZero()
4799 : calculateByteProvider(Op->getOperand(0), Index - ByteShift,
4807 if (NarrowBitWidth % 8 != 0)
4809 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
4811 if (Index >= NarrowByteWidth)
4815 return calculateByteProvider(NarrowOp, Index, Depth + 1);
4818 return calculateByteProvider(Op->
getOperand(0), ByteWidth - Index - 1,
4821 auto L = cast<LoadSDNode>(Op.
getNode());
4822 if (
L->isVolatile() ||
L->isIndexed())
4825 unsigned NarrowBitWidth =
L->getMemoryVT().getSizeInBits();
4826 if (NarrowBitWidth % 8 != 0)
4828 uint64_t NarrowByteWidth = NarrowBitWidth / 8;
4830 if (Index >= NarrowByteWidth)
4874 "Can only match load combining against OR nodes");
4880 unsigned ByteWidth = VT.getSizeInBits() / 8;
4889 std::function<unsigned(unsigned, unsigned)> LittleEndianByteAt = [](
4890 unsigned BW,
unsigned i) {
return i; };
4891 std::function<unsigned(unsigned, unsigned)> BigEndianByteAt = [](
4892 unsigned BW,
unsigned i) {
return BW - i - 1; };
4894 bool IsBigEndianTarget = DAG.getDataLayout().isBigEndian();
4895 auto MemoryByteOffset = [&] (ByteProvider
P) {
4896 assert(
P.isMemory() &&
"Must be a memory byte provider");
4897 unsigned LoadBitWidth =
P.Load->getMemoryVT().getSizeInBits();
4898 assert(LoadBitWidth % 8 == 0 &&
4899 "can only analyze providers for individual bytes not bit");
4900 unsigned LoadByteWidth = LoadBitWidth / 8;
4901 return IsBigEndianTarget
4902 ? BigEndianByteAt(LoadByteWidth,
P.ByteOffset)
4903 : LittleEndianByteAt(LoadByteWidth,
P.ByteOffset);
4911 int64_t FirstOffset = INT64_MAX;
4916 for (
unsigned i = 0; i < ByteWidth; i++) {
4917 auto P = calculateByteProvider(
SDValue(N, 0), i, 0,
true);
4918 if (!
P || !
P->isMemory())
4923 "Must be enforced by calculateByteProvider");
4930 else if (Chain != LChain)
4935 int64_t ByteOffsetFromBase = 0;
4942 ByteOffsetFromBase += MemoryByteOffset(*
P);
4943 ByteOffsets[i] = ByteOffsetFromBase;
4946 if (ByteOffsetFromBase < FirstOffset) {
4947 FirstByteProvider =
P;
4948 FirstOffset = ByteOffsetFromBase;
4953 assert(Loads.
size() > 0 &&
"All the bytes of the value must be loaded from "
4954 "memory, so there must be at least one load which produces the value");
4955 assert(Base &&
"Base address of the accessed memory location must be set");
4956 assert(FirstOffset != INT64_MAX &&
"First byte offset must be set");
4960 bool BigEndian =
true, LittleEndian =
true;
4961 for (
unsigned i = 0; i < ByteWidth; i++) {
4962 int64_t CurrentByteOffset = ByteOffsets[i] - FirstOffset;
4963 LittleEndian &= CurrentByteOffset == LittleEndianByteAt(ByteWidth, i);
4964 BigEndian &= CurrentByteOffset == BigEndianByteAt(ByteWidth, i);
4965 if (!BigEndian && !LittleEndian)
4968 assert((BigEndian != LittleEndian) &&
"should be either or");
4969 assert(FirstByteProvider &&
"must be set");
4973 if (MemoryByteOffset(*FirstByteProvider) != 0)
4975 LoadSDNode *FirstLoad = FirstByteProvider->Load;
4981 bool NeedsBswap = IsBigEndianTarget != BigEndian;
4994 if (!Allowed || !Fast)
5005 return NeedsBswap ? DAG.getNode(
ISD::BSWAP,
SDLoc(N), VT, NewLoad) : NewLoad;
5015 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
5027 return DAG.getConstant(0,
SDLoc(N), VT);
5037 return DAG.FoldConstantArithmetic(
ISD::XOR,
SDLoc(N), VT, N0C, N1C);
5039 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
5040 !DAG.isConstantIntBuildVectorOrConstantInt(N1))
5046 if (
SDValue NewSel = foldBinOpIntoSelect(N))
5060 if (!LegalOperations ||
5066 return DAG.getSetCC(
SDLoc(N0), VT, LHS, RHS, NotCC);
5077 isSetCCEquivalent(N0.
getOperand(0), LHS, RHS, CC)){
5090 if (isOneUseSetCC(RHS) || isOneUseSetCC(LHS)) {
5094 AddToWorklist(LHS.
getNode()); AddToWorklist(RHS.getNode());
5095 return DAG.getNode(NewOpcode,
SDLoc(N), VT, LHS, RHS);
5102 if (isa<ConstantSDNode>(RHS) || isa<ConstantSDNode>(LHS)) {
5106 AddToWorklist(LHS.
getNode()); AddToWorklist(RHS.getNode());
5107 return DAG.getNode(NewOpcode,
SDLoc(N), VT, LHS, RHS);
5115 AddToWorklist(NotX.
getNode());
5124 N00C->getAPIntValue(),
DL, VT));
5140 if (
C->getAPIntValue() == (OpSizeInBits - 1))
5169 return DAG.getNode(
ISD::ROTL, DL, VT, DAG.getConstant(~1, DL, VT),
5175 if (
SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N))
5195 bool HighBitSet =
false;
5215 if (!BinOpCst)
return SDValue();
5226 if ((!isShift || !isa<ConstantSDNode>(BinOpLHSVal->
getOperand(1))) &&
5241 if (BinOpRHSSignSet != HighBitSet)
5252 assert(isa<ConstantSDNode>(NewRHS) &&
"Folding was not successful!");
5260 return DAG.getNode(LHS->
getOpcode(),
SDLoc(N), VT, NewShift, NewRHS);
5263 SDValue DAGCombiner::distributeTruncateThroughAnd(
SDNode *N) {
5276 AddToWorklist(Trunc00.
getNode());
5277 AddToWorklist(Trunc01.
getNode());
5278 return DAG.getNode(
ISD::AND, DL, TruncVT, Trunc00, Trunc01);
5298 if (Cst->getAPIntValue().uge(Bitsize)) {
5299 uint64_t RotAmt = Cst->getAPIntValue().urem(Bitsize);
5300 return DAG.getNode(N->
getOpcode(), dl, VT, N0,
5309 return DAG.getNode(N->
getOpcode(), dl, VT, N0, NewOp1);
5314 if (NextOp ==
ISD::ROTL || NextOp == ISD::ROTR) {
5315 SDNode *C1 = DAG.isConstantIntBuildVectorOrConstantInt(N1);
5319 bool SameSide = (N->
getOpcode() == NextOp);
5322 DAG.FoldConstantArithmetic(CombineOp, dl, ShiftVT, C1, C2)) {
5323 SDValue BitsizeC = DAG.getConstant(Bitsize, dl, ShiftVT);
5324 SDValue CombinedShiftNorm = DAG.FoldConstantArithmetic(
5325 ISD::SREM, dl, ShiftVT, CombinedShift.getNode(),
5343 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
5370 if (N0C && N1C && !N1C->
isOpaque())
5371 return DAG.FoldConstantArithmetic(
ISD::SHL,
SDLoc(N), VT, N0C, N1C);
5377 return DAG.getUNDEF(VT);
5383 return DAG.getConstant(0,
SDLoc(N), VT);
5385 if (
SDValue NewSel = foldBinOpIntoSelect(N))
5389 if (DAG.MaskedValueIsZero(
SDValue(N, 0),
5391 return DAG.getConstant(0,
SDLoc(N), VT);
5406 APInt c1 = N0C1->getAPIntValue();
5410 APInt Sum = c1 + c2;
5411 if (Sum.
uge(OpSizeInBits))
5412 return DAG.getConstant(0, DL, VT);
5431 APInt c1 = N0Op0C1->getAPIntValue();
5437 if (c2.
uge(OpSizeInBits - InnerShiftSize)) {
5439 APInt Sum = c1 + c2;
5440 if (Sum.
uge(OpSizeInBits))
5441 return DAG.getConstant(0, DL, VT);
5467 DAG.getConstant(c2, DL, CountVT));
5468 AddToWorklist(NewSHL.
getNode());
5480 uint64_t C1 = N0C1->getZExtValue();
5497 uint64_t c1 = N0C1->getZExtValue();
5498 if (c1 < OpSizeInBits) {
5514 return DAG.getNode(
ISD::AND, DL, VT, Shift,
5515 DAG.getConstant(Mask, DL, VT));
5524 SDValue AllBits = DAG.getAllOnesConstant(DL, VT);
5537 AddToWorklist(Shl0.
getNode());
5538 AddToWorklist(Shl1.
getNode());
5552 if (
SDValue NewSHL = visitShiftByConstant(N, N1C))
5567 if (DAG.ComputeNumSignBits(N0) == OpSizeInBits)
5572 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
5579 if (N0C && N1C && !N1C->
isOpaque())
5580 return DAG.FoldConstantArithmetic(
ISD::SRA,
SDLoc(N), VT, N0C, N1C);
5583 return DAG.getUNDEF(VT);
5588 if (
SDValue NewSel = foldBinOpIntoSelect(N))
5599 if ((!LegalOperations ||
5609 APInt c1 = N0C1->getAPIntValue();
5613 APInt Sum = c1 + c2;
5614 if (Sum.
uge(OpSizeInBits))
5615 Sum =
APInt(OpSizeInBits, OpSizeInBits - 1);
5646 if ((ShiftAmt > 0) &&
5652 SDValue Amt = DAG.getConstant(ShiftAmt, DL,
5666 N1.getOperand(0).getOpcode() ==
ISD::AND) {
5667 if (
SDValue NewOp1 = distributeTruncateThroughAnd(N1.getNode()))
5681 unsigned LargeShiftVal = LargeShift->getZExtValue();
5702 if (DAG.SignBitIsZero(N0))
5706 if (
SDValue NewSRA = visitShiftByConstant(N, N1C))
5720 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
5727 if (N0C && N1C && !N1C->
isOpaque())
5728 return DAG.FoldConstantArithmetic(
ISD::SRL,
SDLoc(N), VT, N0C, N1C);
5734 return DAG.getUNDEF(VT);
5739 if (
SDValue NewSel = foldBinOpIntoSelect(N))
5743 if (N1C && DAG.MaskedValueIsZero(
SDValue(N, 0),
5745 return DAG.getConstant(0,
SDLoc(N), VT);
5751 APInt c1 = N0C1->getAPIntValue();
5755 APInt Sum = c1 + c2;
5756 if (Sum.
uge(OpSizeInBits))
5757 return DAG.getConstant(0, DL, VT);
5775 if (c1 + OpSizeInBits == InnerShiftSize) {
5777 if (c1 + c2 >= InnerShiftSize)
5778 return DAG.getConstant(0, DL, VT);
5780 DAG.getNode(
ISD::SRL, DL, InnerShiftVT,
5782 DAG.getConstant(c1 + c2, DL,
5793 DAG.getNode(
ISD::SRL, DL, VT, DAG.getAllOnesConstant(DL, VT), N1);
5794 AddToWorklist(Mask.
getNode());
5804 return DAG.getUNDEF(VT);
5811 DAG.getConstant(ShiftAmt, DL0,
5813 AddToWorklist(SmallShift.
getNode());
5816 return DAG.getNode(
ISD::AND, DL, VT,
5818 DAG.getConstant(Mask, DL, VT));
5833 DAG.computeKnownBits(N0.
getOperand(0), Known);
5842 if (UnknownBits == 0)
return DAG.getConstant(1,
SDLoc(N0), VT);
5856 DAG.getConstant(ShAmt, DL,
5862 return DAG.getNode(
ISD::XOR, DL, VT,
5863 Op, DAG.getConstant(1, DL, VT));
5880 if (
SDValue NewSRL = visitShiftByConstant(N, N1C))
5884 if (
SDValue NarrowLoad = ReduceLoadWidth(N))
5924 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5930 if (DAG.SignBitIsZero(N0))
5940 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5953 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5966 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5976 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5986 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
5996 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
6006 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
6017 if (!(LHS == True && RHS == False) && !(LHS == False && RHS == True))
6029 return DAG.
getNode(Opcode, DL, VT, LHS, RHS);
6040 return DAG.
getNode(Opcode, DL, VT, LHS, RHS);
6068 if (CondVT ==
MVT::i1 && !LegalOperations) {
6069 if (C1->isNullValue() && C2->isOne()) {
6076 if (C1->isNullValue() && C2->isAllOnesValue()) {
6083 if (C1->isOne() && C2->isNullValue()) {
6089 if (C1->isAllOnesValue() && C2->isNullValue()) {
6100 if (C1->getAPIntValue() - 1 == C2->getAPIntValue()) {
6104 return DAG.getNode(
ISD::ADD, DL, VT, Cond, N2);
6106 if (C1->getAPIntValue() + 1 == C2->getAPIntValue()) {
6110 return DAG.getNode(
ISD::ADD, DL, VT, Cond, N2);
6131 C1->isNullValue() && C2->isOne()) {
6133 DAG.
getNode(
ISD::XOR, DL, CondVT, Cond, DAG.getConstant(1, DL, CondVT));
6136 return DAG.getZExtOrTrunc(NotCond, DL, VT);
6154 if (
const ConstantSDNode *N0C = dyn_cast<const ConstantSDNode>(N0)) {
6165 if (
SDValue V = foldSelectOfConstants(N))
6171 AddToWorklist(NOTNode.
getNode());
6177 AddToWorklist(NOTNode.
getNode());
6183 return DAG.getNode(
ISD::AND, DL, VT, N0, N1);
6186 if (SimplifySelectOps(N, N1, N2))
6198 bool normalizeToSequence =
6207 if (normalizeToSequence || !InnerSelect.
use_empty())
6208 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), Cond0,
6217 if (normalizeToSequence || !InnerSelect.
use_empty())
6218 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), Cond0, N1,
6223 if (N1->getOpcode() ==
ISD::SELECT && N1->hasOneUse()) {
6229 if (!normalizeToSequence) {
6231 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), And, N1_1, N2);
6234 if (
SDValue Combined = visitANDLike(N0, N1_0, N))
6235 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), Combined, N1_1,
6246 if (!normalizeToSequence) {
6248 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), Or, N1, N2_2);
6251 if (
SDValue Combined = visitORLike(N0, N2_0, N))
6252 return DAG.getNode(
ISD::SELECT, DL, N1.getValueType(), Combined, N1,
6261 if (
auto *
C = dyn_cast<ConstantSDNode>(N0->
getOperand(1))) {
6282 DAG.isKnownNeverNaN(N1) && DAG.isKnownNeverNaN(N2)) {
6290 if ((!LegalOperations &&
6295 return SimplifySelect(DL, N0, N1, N2);
6315 return std::make_pair(Lo, Hi);
6342 for (
int i = 0; i < NumElems / 2; ++i) {
6346 if (BottomHalf ==
nullptr)
6347 BottomHalf = cast<ConstantSDNode>(Cond.
getOperand(i));
6354 for (
int i = NumElems / 2; i < NumElems; ++i) {
6358 if (TopHalf ==
nullptr)
6359 TopHalf = cast<ConstantSDNode>(Cond.
getOperand(i));
6364 assert(TopHalf && BottomHalf &&
6365 "One half of the selector was all UNDEFs and the other was all the "
6366 "same value. This should have been addressed before this function.");
6395 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
6398 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(MSC->
getValueType(0));
6405 EVT LoMemVT, HiMemVT;
6406 std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemoryVT);
6409 std::tie(DataLo, DataHi) = DAG.SplitVector(Data, DL);
6413 std::tie(IndexLo, IndexHi) = DAG.SplitVector(MSC->
getIndex(),
DL);
6420 SDValue OpsLo[] = { Chain, DataLo, MaskLo, BasePtr, IndexLo };
6424 SDValue OpsHi[] = {Chain, DataHi, MaskHi, BasePtr, IndexHi};
6457 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
6467 unsigned SecondHalfAlignment =
6468 (Alignment == VT.
getSizeInBits() / 8) ? Alignment / 2 : Alignment;
6470 EVT LoMemVT, HiMemVT;
6471 std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemoryVT);
6474 std::tie(DataLo, DataHi) = DAG.SplitVector(Data, DL);
6481 Lo = DAG.getMaskedStore(Chain, DL, DataLo, Ptr, MaskLo, LoMemVT, MMO,
6488 MMO = DAG.getMachineFunction().
6494 Hi = DAG.getMaskedStore(Chain, DL, DataHi, Ptr, MaskHi, HiMemVT, MMO,
6498 AddToWorklist(Lo.getNode());
6499 AddToWorklist(Hi.getNode());
6531 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
6535 std::tie(Src0Lo, Src0Hi) = DAG.SplitVector(Src0, DL);
6538 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(VT);
6544 EVT LoMemVT, HiMemVT;
6545 std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemoryVT);
6550 std::tie(IndexLo, IndexHi) = DAG.SplitVector(Index, DL);
6557 SDValue OpsLo[] = { Chain, Src0Lo, MaskLo, BasePtr, IndexLo };
6558 Lo = DAG.getMaskedGather(DAG.getVTList(LoVT,
MVT::Other), LoVT,
DL, OpsLo,
6561 SDValue OpsHi[] = {Chain, Src0Hi, MaskHi, BasePtr, IndexHi};
6562 Hi = DAG.getMaskedGather(DAG.getVTList(HiVT,
MVT::Other), HiVT,
DL, OpsHi,
6575 DAG.ReplaceAllUsesOfValueWith(
SDValue(MGT, 1), Chain);
6579 SDValue RetOps[] = { GatherRes, Chain };
6580 return DAG.getMergeValues(RetOps, DL);
6606 std::tie(MaskLo, MaskHi) =
SplitVSETCC(Mask.getNode(), DAG);
6610 std::tie(Src0Lo, Src0Hi) = DAG.SplitVector(Src0, DL);
6613 std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(MLD->
getValueType(0));
6622 unsigned SecondHalfAlignment =
6624 Alignment/2 : Alignment;
6626 EVT LoMemVT, HiMemVT;
6627 std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemoryVT);
6634 Lo = DAG.getMaskedLoad(LoVT, DL, Chain, Ptr, MaskLo, Src0Lo, LoMemVT, MMO,
6640 MMO = DAG.getMachineFunction().
6645 Hi = DAG.getMaskedLoad(HiVT, DL, Chain, Ptr, MaskHi, Src0Hi, HiMemVT, MMO,
6648 AddToWorklist(Lo.getNode());
6649 AddToWorklist(Hi.getNode());
6658 DAG.ReplaceAllUsesOfValueWith(
SDValue(MLD, 1), Chain);
6662 SDValue RetOps[] = { LoadRes, Chain };
6663 return DAG.getMergeValues(RetOps, DL);
6700 return DAG.getNode(
ISD::ABS, DL, VT, LHS);
6706 AddToWorklist(Shift.
getNode());
6708 return DAG.getNode(
ISD::XOR, DL, VT, Add, Shift);
6712 if (SimplifySelectOps(N, N1, N2))
6749 CC,
SDLoc(N),
false)) {
6750 AddToWorklist(SCC.getNode());
6752 if (
ConstantSDNode *SCCC = dyn_cast<ConstantSDNode>(SCC.getNode())) {
6753 if (!SCCC->isNullValue())
6757 }
else if (SCC->isUndef()) {
6764 SCC.getOperand(0), SCC.getOperand(1), N2, N3,
6770 if (SimplifySelectOps(N, N2, N3))
6774 return SimplifySelectCC(
SDLoc(N), N0, N1, N2, N3, CC);
6779 cast<CondCodeSDNode>(N->
getOperand(2))->
get(),
6817 bool LegalOperations) {
6825 &&
"Expected EXTEND dag node in input!");
6830 if (isa<ConstantSDNode>(N0))
6838 (!LegalTypes || (!LegalOperations && TLI.
isTypeLegal(SVT))) &&
6849 for (
unsigned i=0; i != NumElts; ++i) {
6859 APInt C = cast<ConstantSDNode>(
Op)->getAPIntValue().zextOrTrunc(EVTBits);
6877 bool HasCopyToRegUses =
false;
6885 if (UI.getUse().getResNo() != N0.
getResNo())
6894 for (
unsigned i = 0; i != 2; ++i) {
6898 if (!isa<ConstantSDNode>(UseOp))
6912 HasCopyToRegUses =
true;
6915 if (HasCopyToRegUses) {
6916 bool BothLiveOut =
false;
6919 SDUse &Use = UI.getUse();
6928 return ExtendNodes.
size();
6937 for (
unsigned i = 0, e = SetCCs.
size(); i != e; ++i) {
6938 SDNode *SetCC = SetCCs[i];
6941 for (
unsigned j = 0; j != 2; ++j) {
6962 "Unexpected node type (not an extend)!");
6999 EVT SplitSrcVT = SrcVT;
7000 EVT SplitDstVT = DstVT;
7003 SplitDstVT = DAG.GetSplitDestVTs(SplitDstVT).first;
7004 SplitSrcVT = DAG.GetSplitDestVTs(SplitSrcVT).first;
7011 const unsigned NumSplits =
7018 for (
unsigned Idx = 0; Idx < NumSplits; Idx++) {
7019 const unsigned Offset = Idx * Stride;
7022 SDValue SplitLoad = DAG.getExtLoad(
7023 ExtType, DL, SplitDstVT, LN0->
getChain(), BasePtr,
7031 Chains.
push_back(SplitLoad.getValue(1));
7038 AddToWorklist(NewChain.
getNode());
7040 CombineTo(N, NewValue);
7046 CombineTo(N0.
getNode(), Trunc, NewChain);
7047 ExtendSetCCUses(SetCCs, Trunc, NewValue, DL,
7056 SDValue DAGCombiner::matchVSelectOpSizesWithSetCC(
SDNode *Cast) {
7057 unsigned CastOpcode = Cast->
getOpcode();
7061 "Unexpected opcode for vector select narrowing/widening");
7091 CastA = DAG.
getNode(CastOpcode, DL, VT, A);
7092 CastB = DAG.
getNode(CastOpcode, DL, VT, B);
7094 return DAG.getNode(
ISD::VSELECT, DL, VT, SetCC, CastA, CastB);
7116 if (NarrowLoad.getNode() != N0.
getNode()) {
7117 CombineTo(N0.
getNode(), NarrowLoad);
7130 unsigned NumSignBits = DAG.ComputeNumSignBits(Op);
7132 if (OpBits == DestBits) {
7135 if (NumSignBits > DestBits-MidBits)
7137 }
else if (OpBits < DestBits) {
7140 if (NumSignBits > OpBits-MidBits)
7145 if (NumSignBits > OpBits-MidBits)
7152 if (OpBits < DestBits)
7154 else if (OpBits > DestBits)
7165 ((!LegalOperations && !VT.
isVector() &&
7168 bool DoXform =
true;
7184 CombineTo(N, ExtLoad);
7188 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
7195 if (
SDValue ExtLoad = CombineExtLoad(N))
7204 if ((!LegalOperations && !LN0->
isVolatile()) ||
7209 CombineTo(N, ExtLoad);
7228 bool DoXform =
true;
7241 ExtLoad, DAG.getConstant(Mask, DL, VT));
7251 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
7265 if (VT.isVector() && !LegalOperations &&
7279 return DAG.getSetCC(DL, VT, N00, N01, CC);
7285 if (SVT == MatchingVecType) {
7286 SDValue VsetCC = DAG.getSetCC(DL, MatchingVecType, N00, N01, CC);
7287 return DAG.getSExtOrTrunc(VsetCC, DL, VT);
7303 SDValue ExtTrueVal = (SetCCWidth == 1) ? DAG.getAllOnesConstant(DL, VT)
7305 SDValue Zero = DAG.getConstant(0, DL, VT);
7307 SimplifySelectCC(DL, N00, N01, ExtTrueVal, Zero, CC,
true))
7310 if (!VT.isVector()) {
7318 SDValue SetCC = DAG.getSetCC(DL, SetCCVT, N00, N01, CC);
7319 return DAG.getSelect(DL, VT, SetCC, ExtTrueVal, Zero);
7326 DAG.SignBitIsZero(N0))
7329 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
7364 if (!(Known.
Zero | 1).isAllOnesValue())
7391 APInt TruncatedBits =
7399 return DAG.getZExtOrTrunc(Op,
SDLoc(N), VT);
7407 if (NarrowLoad.getNode() != N0.
getNode()) {
7408 CombineTo(N0.
getNode(), NarrowLoad);
7422 if (NarrowLoad.getNode() != N0.
getNode()) {
7423 CombineTo(N0.
getNode(), NarrowLoad);
7441 return DAG.getZExtOrTrunc(Op,
SDLoc(N), VT);
7461 X = DAG.getAnyExtOrTrunc(X,
SDLoc(X), VT);
7465 return DAG.getNode(
ISD::AND, DL, VT,
7466 X, DAG.getConstant(Mask, DL, VT));
7473 ((!LegalOperations && !VT.
isVector() &&
7476 bool DoXform =
true;
7494 CombineTo(N, ExtLoad);
7498 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
7505 if (
SDValue ExtLoad = CombineExtLoad(N))
7520 bool DoXform =
true;
7524 auto *AndC = cast<ConstantSDNode>(N0.
getOperand(1));
7525 auto NarrowLoad =
false;
7527 EVT ExtVT, LoadedVT;
7528 if (isAndLoadExtLoad(AndC, LN0, LoadResultTy, ExtVT, LoadedVT,
7545 ExtLoad, DAG.getConstant(Mask, DL, VT));
7555 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
7567 if ((!LegalOperations && !LN0->
isVolatile()) ||
7573 CombineTo(N, ExtLoad);
7584 if (!LegalOperations && VT.isVector() &&
7596 SDValue VecOnes = DAG.getConstant(1, DL, VT);
7601 return DAG.getNode(
ISD::AND, DL, VT, VSetCC, VecOnes);
7614 return DAG.getNode(
ISD::AND, DL, VT, DAG.getSExtOrTrunc(VsetCC, DL, VT),
7620 if (
SDValue SCC = SimplifySelectCC(
7622 DAG.getConstant(0, DL, VT),
7623 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true))
7633 unsigned ShAmtVal = cast<ConstantSDNode>(ShAmt)->getZExtValue();
7640 if (ShAmtVal > KnownZeroBits)
7647 if (VT.getSizeInBits() >= 256)
7655 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
7682 if (NarrowLoad.getNode() != N0.
getNode()) {
7683 CombineTo(N0.
getNode(), NarrowLoad);
7704 X = DAG.getAnyExtOrTrunc(X, DL, VT);
7707 return DAG.getNode(
ISD::AND, DL, VT,
7708 X, DAG.getConstant(Mask, DL, VT));
7718 bool DoXform =
true;
7730 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
7734 CombineTo(N, ExtLoad);
7738 CombineTo(LN0, Trunc, ExtLoad.
getValue(1));
7752 if (!LegalOperations || TLI.
isLoadExtLegal(ExtType, VT, MemVT)) {
7756 CombineTo(N, ExtLoad);
7771 if (VT.
isVector() && !LegalOperations) {
7781 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
7790 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
7791 return DAG.getAnyExtOrTrunc(VsetCC,
SDLoc(N), VT);
7797 if (
SDValue SCC = SimplifySelectCC(
7799 DAG.getConstant(0, DL, VT),
7800 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true))
7810 EVT EVT = cast<VTSDNode>(N1)->getVT();
7814 EVT == cast<VTSDNode>(N0.
getOperand(1))->getVT())
7831 assert(CV &&
"Const value should be ConstSDNode.");
7852 unsigned Amt = RHSC->getZExtValue();
7855 if (Amt >= Mask.getBitWidth())
break;
7856 APInt NewMask = Mask << Amt;
7894 ExtVT = cast<VTSDNode>(N->
getOperand(1))->getVT();
7919 if ((ShAmt & (EVTBits-1)) == 0) {
7927 if (!isa<LoadSDNode>(N0))
return SDValue();
7932 if (cast<LoadSDNode>(N0)->getExtensionType() ==
ISD::SEXTLOAD)
7938 if (ShAmt >= cast<LoadSDNode>(N0)->getMemoryVT().getSizeInBits())
7945 unsigned ShLeftAmt = 0;
7956 if (!isa<LoadSDNode>(N0) || !N0.
hasOneUse())
7994 if (DAG.getDataLayout().isBigEndian()) {
7997 ShAmt = LVTStoreBits - EVTStoreBits - ShAmt;
8000 uint64_t PtrOff = ShAmt / 8;
8008 DAG.getConstant(PtrOff, DL, PtrType),
8010 AddToWorklist(NewPtr.
getNode());
8018 Load = DAG.getExtLoad(ExtType,
SDLoc(N0), VT, LN0->
getChain(), NewPtr,
8024 WorklistRemover DeadNodes(*
this);
8029 if (ShLeftAmt != 0) {
8039 Result = DAG.getConstant(0, DL, VT);
8042 Result, DAG.getConstant(ShLeftAmt, DL, ShImmTy));
8053 EVT EVT = cast<VTSDNode>(N1)->getVT();
8058 return DAG.getUNDEF(VT);
8061 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
8065 if (DAG.ComputeNumSignBits(N0) >= VTBits-EVTBits+1)
8089 if (!LegalOperations ||
8114 if (
SDValue NarrowLoad = ReduceLoadWidth(N))
8122 if (ShAmt->getZExtValue()+EVTBits <= VTBits) {
8125 unsigned InSignBits = DAG.ComputeNumSignBits(N0.
getOperand(0));
8126 if (VTBits-(ShAmt->getZExtValue()+EVTBits) < InSignBits)
8135 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
8136 ((!LegalOperations && !cast<LoadSDNode>(N0)->
isVolatile()) ||
8143 CombineTo(N, ExtLoad);
8144 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
8145 AddToWorklist(ExtLoad.getNode());
8151 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
8152 ((!LegalOperations && !cast<LoadSDNode>(N0)->
isVolatile()) ||
8159 CombineTo(N, ExtLoad);
8160 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
8175 SDValue DAGCombiner::visitSIGN_EXTEND_VECTOR_INREG(
SDNode *N) {
8180 return DAG.getUNDEF(VT);
8189 SDValue DAGCombiner::visitZERO_EXTEND_VECTOR_INREG(
SDNode *N) {
8194 return DAG.getUNDEF(VT);
8206 bool isLE = DAG.getDataLayout().isLittleEndian();
8212 if (DAG.isConstantIntBuildVectorOrConstantInt(N0))
8260 if (isa<ConstantSDNode>(EltNo) &&
isTypeLegal(NVT)) {
8261 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
8263 int Index = isLE ? (Elt*SizeRatio) : (Elt*SizeRatio + (SizeRatio-1));
8268 DAG.getConstant(Index, DL, IndexTy));
8291 DAG.computeKnownBits(Amt, Known);
8299 Amt = DAG.getZExtOrTrunc(Amt, SL, AmtVT);
8320 if (BuildVectEltTy == TruncVecEltTy) {
8324 unsigned TruncEltOffset = BuildVecNumElts / TruncVecNumElts;
8326 assert((BuildVecNumElts % TruncVecNumElts) == 0 &&
8327 "Invalid number of elements");
8330 for (
unsigned i = 0, e = BuildVecNumElts; i != e; i += TruncEltOffset)
8333 return DAG.getBuildVector(VT,
SDLoc(N), Opnds);
8352 if (
SDValue Reduced = ReduceLoadWidth(N))
8377 unsigned NumDefs = 0;
8395 return DAG.getUNDEF(VT);
8398 assert(V.
getNode() &&
"The single defined operand is empty!");
8400 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
8407 Opnds.push_back(NV);
8421 (!LegalOperations ||
8427 VecSrc, DAG.getConstant(0, SL, IdxVT));
8449 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
8464 SDValue DAGCombiner::CombineConsecutiveLoads(
SDNode *N, EVT VT) {
8470 LD1->getAddressSpace() != LD2->getAddressSpace())
8472 EVT LD1VT = LD1->getValueType(0);
8475 DAG.areNonVolatileConsecutiveLoads(LD2, LD1, LD1Bytes, 1)) {
8476 unsigned Align = LD1->getAlignment();
8477 unsigned NewAlign = DAG.getDataLayout().getABITypeAlignment(
8480 if (NewAlign <= Align &&
8482 return DAG.getLoad(VT,
SDLoc(N), LD1->getChain(), LD1->getBasePtr(),
8483 LD1->getPointerInfo(),
Align);
8543 return DAG.getUNDEF(VT);
8556 "Element type of vector ValueType must not be vector!");
8558 return ConstantFoldBITCASTofBUILD_VECTOR(N0.
getNode(), DestEltVT);
8562 if (isa<ConstantSDNode>(N0) || isa<ConstantFPSDNode>(N0)) {
8566 if (!LegalOperations ||
8571 return DAG.getBitcast(VT, N0);
8624 AddToWorklist(NewConv.
getNode());
8629 SDValue SignBit = DAG.getConstant(
8634 AddToWorklist(FlipBit.
getNode());
8641 AddToWorklist(Hi.getNode());
8643 AddToWorklist(FlipBit.getNode());
8647 AddToWorklist(FlipBits.
getNode());
8648 return DAG.getNode(
ISD::XOR, DL, VT, NewConv, FlipBits);
8652 return DAG.getNode(
ISD::XOR, DL, VT,
8653 NewConv, DAG.getConstant(SignBit, DL, VT));
8655 return DAG.getNode(
ISD::AND, DL, VT,
8656 NewConv, DAG.getConstant(~SignBit, DL, VT));
8681 if (OrigXWidth < VTWidth) {
8684 }
else if (OrigXWidth > VTWidth) {
8690 DAG.getConstant(OrigXWidth-VTWidth, DL,
8694 AddToWorklist(X.getNode());
8700 AddToWorklist(Cst.getNode());
8702 AddToWorklist(X.getNode());
8704 AddToWorklist(XorResult.getNode());
8709 AddToWorklist(XorResult64.getNode());
8713 AddToWorklist(FlipBit.getNode());
8716 AddToWorklist(FlipBits.getNode());
8721 X, DAG.getConstant(SignBit,
SDLoc(X), VT));
8722 AddToWorklist(X.getNode());
8726 Cst, DAG.getConstant(~SignBit,
SDLoc(Cst), VT));
8727 AddToWorklist(Cst.getNode());
8735 if (
SDValue CombineLD = CombineConsecutiveLoads(N0.
getNode(), VT))
8750 auto PeekThroughBitcast = [&](
SDValue Op) {
8756 return DAG.getBitcast(VT, Op);
8769 for (
int i = 0; i != MaskScale; ++i)
8770 NewMask.
push_back(M < 0 ? -1 : M * MaskScale + i);
8780 return DAG.getVectorShuffle(VT,
SDLoc(N), SV0, SV1, NewMask);
8788 return CombineConsecutiveLoads(N, VT);
8794 ConstantFoldBITCASTofBUILD_VECTOR(
SDNode *BV, EVT DstEltVT) {
8798 if (SrcEltVT == DstEltVT)
return SDValue(BV, 0);
8805 if (SrcBitSize == DstBitSize) {
8813 DAG.getBitcast(DstEltVT, BV->
getOperand(0)));
8821 Ops.
push_back(DAG.getBitcast(DstEltVT, Op));
8824 return DAG.getBuildVector(VT,
SDLoc(BV), Ops);
8834 BV = ConstantFoldBITCASTofBUILD_VECTOR(BV, IntVT).getNode();
8842 SDNode *Tmp = ConstantFoldBITCASTofBUILD_VECTOR(BV, TmpVT).getNode();
8845 return ConstantFoldBITCASTofBUILD_VECTOR(Tmp, DstEltVT);
8853 if (SrcBitSize < DstBitSize) {
8854 unsigned NumInputsPerOutput = DstBitSize/SrcBitSize;
8857 for (
unsigned i = 0, e = BV->getNumOperands(); i != e;
8858 i += NumInputsPerOutput) {
8859 bool isLE = DAG.getDataLayout().isLittleEndian();
8861 bool EltIsUndef =
true;
8862 for (
unsigned j = 0; j != NumInputsPerOutput; ++j) {
8864 NewBits <<= SrcBitSize;
8869 NewBits |= cast<ConstantSDNode>(
Op)->getAPIntValue().
8870 zextOrTrunc(SrcBitSize).
zext(DstBitSize);
8876 Ops.
push_back(DAG.getConstant(NewBits, DL, DstEltVT));
8880 return DAG.getBuildVector(VT, DL, Ops);
8885 unsigned NumOutputsPerInput = SrcBitSize/DstBitSize;
8887 NumOutputsPerInput*BV->getNumOperands());
8892 Ops.
append(NumOutputsPerInput, DAG.getUNDEF(DstEltVT));
8896 APInt OpVal = cast<ConstantSDNode>(
Op)->
8899 for (
unsigned j = 0; j != NumOutputsPerInput; ++j) {
8901 Ops.push_back(DAG.getConstant(ThisVal, DL, DstEltVT));
8906 if (DAG.getDataLayout().isBigEndian())
8910 return DAG.getBuildVector(VT, DL, Ops);
8936 if (!HasFMAD && !HasFMA)
8956 auto isContractableFMUL = [AllowFusionGlobally](
SDValue N) {
8963 if (Aggressive && isContractableFMUL(N0) && isContractableFMUL(N1)) {
8969 if (isContractableFMUL(N0) && (Aggressive || N0->
hasOneUse())) {
8970 return DAG.getNode(PreferredFusedOpcode, SL, VT,
8976 if (isContractableFMUL(N1) && (Aggressive || N1->
hasOneUse())) {
8977 return DAG.getNode(PreferredFusedOpcode, SL, VT,
8982 if (LookThroughFPExt) {
8986 if (isContractableFMUL(N00))
8987 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
8998 if (isContractableFMUL(N10))
8999 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9013 N0.
getOpcode() == PreferredFusedOpcode &&
9016 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9018 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9028 N1->
getOpcode() == PreferredFusedOpcode &&
9031 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9033 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9039 if (LookThroughFPExt) {
9042 auto FoldFAddFMAFPExtFMul = [&] (
9044 return DAG.getNode(PreferredFusedOpcode, SL, VT, X, Y,
9045 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9050 if (N0.
getOpcode() == PreferredFusedOpcode) {
9054 if (isContractableFMUL(N020))
9066 auto FoldFAddFPExtFMAFMul = [&] (
9068 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9071 DAG.getNode(PreferredFusedOpcode, SL, VT,
9078 if (N00.
getOpcode() == PreferredFusedOpcode) {
9080 if (isContractableFMUL(N002))
9089 if (N1.
getOpcode() == PreferredFusedOpcode) {
9093 if (isContractableFMUL(N120))
9107 if (N10.
getOpcode() == PreferredFusedOpcode) {
9109 if (isContractableFMUL(N102))
9138 if (!HasFMAD && !HasFMA)
9158 auto isContractableFMUL = [AllowFusionGlobally](
SDValue N) {
9165 if (isContractableFMUL(N0) && (Aggressive || N0->
hasOneUse())) {
9166 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9173 if (isContractableFMUL(N1) && (Aggressive || N1->
hasOneUse()))
9174 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9184 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9185 DAG.getNode(
ISD::FNEG, SL, VT, N00), N01,
9190 if (LookThroughFPExt) {
9195 if (isContractableFMUL(N00))
9196 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9209 if (isContractableFMUL(N10))
9210 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9229 if (isContractableFMUL(N000)) {
9231 DAG.getNode(PreferredFusedOpcode, SL, VT,
9251 if (isContractableFMUL(N000)) {
9253 DAG.getNode(PreferredFusedOpcode, SL, VT,
9274 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9276 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9291 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9295 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9301 if (LookThroughFPExt) {
9304 if (N0.
getOpcode() == PreferredFusedOpcode) {
9308 if (isContractableFMUL(N020))
9309 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9311 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9329 if (N00.
getOpcode() == PreferredFusedOpcode) {
9331 if (isContractableFMUL(N002))
9332 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9337 DAG.getNode(PreferredFusedOpcode, SL, VT,
9349 if (N1.
getOpcode() == PreferredFusedOpcode &&
9352 if (isContractableFMUL(N120)) {
9355 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9358 DAG.
getNode(PreferredFusedOpcode, SL, VT,
9379 if (isContractableFMUL(N102)) {
9382 return DAG.
getNode(PreferredFusedOpcode, SL, VT,
9387 DAG.getNode(PreferredFusedOpcode, SL, VT,
9405 SDValue DAGCombiner::visitFMULForFMADistributiveCombine(
SDNode *N) {
9417 if (!Options.NoInfsFPMath)
9428 bool HasFMAD = Options.UnsafeFPMath &&
9432 if (!HasFMAD && !HasFMA)
9444 if (XC1 && XC1->isExactlyValue(+1.0))
9445 return DAG.getNode(PreferredFusedOpcode, SL, VT, X.
getOperand(0),
Y,
Y);
9446 if (XC1 && XC1->isExactlyValue(-1.0))
9447 return DAG.getNode(PreferredFusedOpcode, SL, VT, X.
getOperand(0),
Y,
9465 if (XC0 && XC0->isExactlyValue(+1.0))
9466 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9469 if (XC0 && XC0->isExactlyValue(-1.0))
9470 return DAG.getNode(PreferredFusedOpcode, SL, VT,
9475 if (XC1 && XC1->isExactlyValue(+1.0))
9476 return DAG.getNode(PreferredFusedOpcode, SL, VT, X.
getOperand(0),
Y,
9478 if (XC1 && XC1->isExactlyValue(-1.0))
9479 return DAG.getNode(PreferredFusedOpcode, SL, VT, X.
getOperand(0),
Y,
Y);
9496 return CFP->isExactlyValue(-2.0);
9512 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
9517 return DAG.getNode(
ISD::FADD, DL, VT, N0, N1, Flags);
9520 if (N0CFP && !N1CFP)
9521 return DAG.getNode(
ISD::FADD, DL, VT, N1, N0, Flags);
9523 if (
SDValue NewSel = foldBinOpIntoSelect(N))
9529 return DAG.getNode(
ISD::FSUB, DL, VT, N0,
9535 return DAG.getNode(
ISD::FSUB, DL, VT, N1,
9545 return DAG.getNode(
ISD::FSUB, DL, VT, N1IsFMul ? N0 : N1, Add, Flags);
9572 return DAG.getConstantFP(0.0, DL, VT);
9576 return DAG.getConstantFP(0.0, DL, VT);
9587 if (CFP01 && !CFP00 && N0.
getOperand(0) == N1) {
9589 DAG.getConstantFP(1.0, DL, VT),
Flags);
9590 return DAG.getNode(
ISD::FMUL, DL, VT, N1, NewCFP, Flags);
9598 DAG.getConstantFP(2.0, DL, VT),
Flags);
9608 if (CFP11 && !CFP10 && N1.
getOperand(0) == N0) {
9610 DAG.getConstantFP(1.0, DL, VT),
Flags);
9611 return DAG.getNode(
ISD::FMUL, DL, VT, N0, NewCFP, Flags);
9619 DAG.getConstantFP(2.0, DL, VT),
Flags);
9630 N1, DAG.getConstantFP(3.0, DL, VT),
Flags);
9640 N0, DAG.getConstantFP(3.0, DL, VT),
Flags);
9645 if (AllowNewConst &&
9651 DAG.getConstantFP(4.0, DL, VT),
Flags);
9657 if (
SDValue Fused = visitFADDForFMACombine(N)) {
9658 AddToWorklist(Fused.getNode());
9676 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
9681 return DAG.getNode(
ISD::FSUB, DL, VT, N0, N1, Flags);
9683 if (
SDValue NewSel = foldBinOpIntoSelect(N))
9688 return DAG.getNode(
ISD::FADD, DL, VT, N0,
9694 if (N0CFP && N0CFP->
isZero()) {
9705 if (N1CFP && N1CFP->
isZero())
9710 return DAG.getConstantFP(0.0f, DL, VT);
9727 if (
SDValue Fused = visitFSUBForFMACombine(N)) {
9728 AddToWorklist(Fused.getNode());
9748 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
9754 return DAG.getNode(
ISD::FMUL, DL, VT, N0, N1, Flags);
9759 return DAG.getNode(
ISD::FMUL, DL, VT, N1, N0, Flags);
9765 if (
SDValue NewSel = foldBinOpIntoSelect(N))
9770 if (N1CFP && N1CFP->
isZero())
9790 (BV1 && BV01 && BV1->isConstant() && BV01->isConstant())) {
9792 return DAG.getNode(
ISD::FMUL, DL, VT, N00, MulConsts, Flags);
9804 const SDValue Two = DAG.getConstantFP(2.0, DL, VT);
9812 return DAG.getNode(
ISD::FADD, DL, VT, N0, N0, Flags);
9817 return DAG.getNode(
ISD::FNEG, DL, VT, N0);
9824 if (LHSNeg == 2 || RHSNeg == 2)
9845 if (TrueOpnd && FalseOpnd &&
9848 cast<ConstantFPSDNode>(Cond.
getOperand(1))->isExactlyValue(0.0)) {
9866 if (TrueOpnd->isExactlyValue(-1.0) && FalseOpnd->isExactlyValue(1.0) &&
9870 if (TrueOpnd->isExactlyValue(1.0) && FalseOpnd->isExactlyValue(-1.0))
9871 return DAG.getNode(
ISD::FABS, DL, VT, X);
9879 if (
SDValue Fused = visitFMULForFMADistributiveCombine(N)) {
9880 AddToWorklist(Fused.getNode());
9898 if (isa<ConstantFPSDNode>(N0) &&
9899 isa<ConstantFPSDNode>(N1) &&
9900 isa<ConstantFPSDNode>(N2)) {
9901 return DAG.getNode(
ISD::FMA, DL, VT, N0, N1, N2);
9905 if (N0CFP && N0CFP->
isZero())
9907 if (N1CFP && N1CFP->isZero())
9913 if (N1CFP && N1CFP->isExactlyValue(1.0))
9931 return DAG.getNode(
ISD::FMUL, DL, VT, N0,
9940 return DAG.getNode(
ISD::FMA, DL, VT,
9951 if (N1CFP->isExactlyValue(1.0))
9953 return DAG.getNode(
ISD::FADD, DL, VT, N0, N2);
9955 if (N1CFP->isExactlyValue(-1.0) &&
9958 AddToWorklist(RHSNeg.
getNode());
9960 return DAG.getNode(
ISD::FADD, DL, VT, N2, RHSNeg);
9966 if (N1CFP && N0 == N2) {
9967 return DAG.getNode(
ISD::FMUL, DL, VT, N0,
9969 DAG.getConstantFP(1.0, DL, VT),
Flags),
9975 return DAG.getNode(
ISD::FMUL, DL, VT, N0,
9977 DAG.getConstantFP(-1.0, DL, VT),
Flags),
9993 bool UnsafeMath = DAG.getTarget().Options.UnsafeFPMath;
10008 if (!MinUses || N1->
use_size() < MinUses)
10014 for (
auto *U : N1->
uses()) {
10015 if (U->getOpcode() ==
ISD::FDIV && U->getOperand(1) == N1) {
10018 if (UnsafeMath || U->getFlags().hasAllowReciprocal())
10025 if (Users.
size() < MinUses)
10030 SDValue FPOne = DAG.getConstantFP(1.0, DL, VT);
10034 for (
auto *U : Users) {
10036 if (Dividend != FPOne) {
10038 Reciprocal, Flags);
10039 CombineTo(U, NewNode);
10040 }
else if (U != Reciprocal.
getNode()) {
10043 CombineTo(U, Reciprocal);
10061 if (
SDValue FoldedVOp = SimplifyVBinOp(N))
10065 if (N0CFP && N1CFP)
10068 if (
SDValue NewSel = foldBinOpIntoSelect(N))
10075 const APFloat &N1APF = N1CFP->getValueAPF();
10081 (!LegalOperations ||
10087 return DAG.getNode(
ISD::FMUL, DL, VT, N0,
10088 DAG.getConstantFP(Recip, DL, VT),
Flags);
10095 return DAG.getNode(
ISD::FMUL, DL, VT, N0, RV, Flags);
10103 return DAG.getNode(
ISD::FMUL, DL, VT, N0, RV, Flags);
10111 return DAG.getNode(
ISD::FMUL, DL, VT, N0, RV, Flags);
10131 return DAG.getNode(
ISD::FMUL, DL, VT, N0, RV, Flags);
10137 if (
SDValue RV = BuildReciprocalEstimate(N1, Flags)) {
10139 return DAG.getNode(
ISD::FMUL, DL, VT, N0, RV, Flags);
10148 if (LHSNeg == 2 || RHSNeg == 2)
10157 return CombineRepeatedDivisors;
10170 if (N0CFP && N1CFP)
10173 if (
SDValue NewSel = foldBinOpIntoSelect(N))
10180 if (!DAG.getTarget().Options.UnsafeFPMath)
10191 return buildSqrtEstimate(N0, Flags);
10206 return (N1VT == N1Op0VT || N1Op0VT !=
MVT::f128);
10218 if (N0CFP && N1CFP)
10222 const APFloat &V = N1CFP->getValueAPF();
10264 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
10266 (!LegalOperations ||
10275 if (DAG.SignBitIsZero(N0))
10284 (!LegalOperations ||
10289 DAG.getConstantFP(-1.0, DL, VT), DAG.getConstantFP(0.0, DL, VT),
10298 (!LegalOperations ||
10303 DAG.getConstantFP(1.0, DL, VT), DAG.getConstantFP(0.0, DL, VT),
10318 if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
10320 (!LegalOperations ||
10329 if (DAG.SignBitIsZero(N0))
10338 (!LegalOperations ||
10343 DAG.getConstantFP(1.0, DL, VT), DAG.getConstantFP(0.0, DL, VT),
10376 unsigned ActualSize =
std::min(InputSize, OutputSize);
10450 if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc) {
10453 DAG.getIntPtrConstant(NIsTrunc && N0IsTrunc, DL));
10461 AddToWorklist(Tmp.
getNode());
10466 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
10475 EVT EVT = cast<VTSDNode>(N->
getOperand(1))->getVT();
10526 CombineTo(N, ExtLoad);
10530 DAG.getIntPtrConstant(1,
SDLoc(N0))),
10531 ExtLoad.getValue(1));
10535 if (
SDValue NewVSel = matchVSelectOpSizesWithSetCC(N))
10584 &DAG.getTarget().Options))
10607 DAG.getConstant(SignMask, DL0, IntVT));
10608 AddToWorklist(Int.
getNode());
10609 return DAG.getBitcast(VT, Int);
10623 return DAG.getNode(
10640 if (N0CFP && N1CFP) {
10643 return DAG.getConstantFP(
minnum(C0, C1),
SDLoc(N), VT);
10661 if (N0CFP && N1CFP) {
10664 return DAG.getConstantFP(
maxnum(C0, C1),
SDLoc(N), VT);
10712 DAG.getConstant(SignMask, DL, IntVT));
10713 AddToWorklist(Int.
getNode());
10746 SDNode *Trunc =
nullptr;
10778 const APInt &AndConst = cast<ConstantSDNode>(AndOp1)->getAPIntValue();
10781 cast<ConstantSDNode>(Op1)->getAPIntValue()==AndConst.
logBase2()) {
10793 CombineTo(N, NewBRCond,
false);
10796 deleteAndRecombine(Trunc);
10798 WorklistRemover DeadNodes(*
this);
10799 DAG.ReplaceAllUsesOfValueWith(N1, SetCC);
10800 deleteAndRecombine(N1.
getNode());
10819 if (
SDValue Tmp = visitXOR(TheXor)) {
10820 if (Tmp.
getNode() != TheXor) {
10822 TheXor->
dump(&DAG);
10823 dbgs() <<
"\nWith: ";
10826 WorklistRemover DeadNodes(*
this);
10827 DAG.ReplaceAllUsesOfValueWith(N1, Tmp);
10828 deleteAndRecombine(TheXor);
10840 bool Equal =
false;
10855 WorklistRemover DeadNodes(*
this);
10856 DAG.ReplaceAllUsesOfValueWith(N1, SetCC);
10857 deleteAndRecombine(N1.
getNode());
10880 CondLHS, CondRHS, CC->
get(),
SDLoc(N),
10902 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(Use)) {
10908 if (
ST->isIndexed() ||
ST->getBasePtr().getNode() !=
N)
10910 VT =
ST->getMemoryVT();
10911 AS =
ST->getAddressSpace();
10944 bool DAGCombiner::CombineToPreIndexedLoadStore(
SDNode *N) {
10948 bool isLoad =
true;
10951 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
10960 if (
ST->isIndexed())
10962 VT =
ST->getMemoryVT();
10966 Ptr =
ST->getBasePtr();
10988 bool Swapped =
false;
10989 if (isa<ConstantSDNode>(BasePtr)) {
11008 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
11013 SDValue Val = cast<StoreSDNode>(
N)->getValue();
11027 if (isa<ConstantSDNode>(Offset))
11031 SDUse &Use = UI.getUse();
11047 if (!isa<ConstantSDNode>(Op1)) {
11065 bool RealUse =
false;
11085 BasePtr, Offset, AM);
11088 BasePtr, Offset, AM);
11093 dbgs() <<
"\nWith: ";
11096 WorklistRemover DeadNodes(*
this);
11105 deleteAndRecombine(N);
11111 for (
unsigned i = 0, e = OtherUses.
size(); i != e; ++i) {
11112 unsigned OffsetIdx = 1;
11113 if (OtherUses[i]->getOperand(OffsetIdx).getNode() == BasePtr.
getNode())
11115 assert(OtherUses[i]->getOperand(!OffsetIdx).getNode() ==
11116 BasePtr.
getNode() &&
"Expected BasePtr operand");
11130 cast<ConstantSDNode>(OtherUses[i]->getOperand(OffsetIdx));
11131 int X0, X1, Y0, Y1;
11132 const APInt &Offset0 = CN->getAPIntValue();
11133 APInt Offset1 = cast<ConstantSDNode>(
Offset)->getAPIntValue();
11135 X0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 1) ? -1 : 1;
11136 Y0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 0) ? -1 : 1;
11142 APInt CNV = Offset0;
11143 if (X0 < 0) CNV = -CNV;
11144 if (X1 * Y0 * Y1 < 0) CNV = CNV + Offset1;
11145 else CNV = CNV - Offset1;
11150 SDValue NewOp1 = DAG.getConstant(CNV, DL, CN->getValueType(0));
11156 DAG.ReplaceAllUsesOfValueWith(
SDValue(OtherUses[i], 0), NewUse);
11157 deleteAndRecombine(OtherUses[i]);
11161 DAG.ReplaceAllUsesOfValueWith(Ptr, Result.
getValue(isLoad ? 1 : 0));
11162 deleteAndRecombine(Ptr.
getNode());
11171 bool DAGCombiner::CombineToPostIndexedLoadStore(
SDNode *N) {
11175 bool isLoad =
true;
11178 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
11187 if (
ST->isIndexed())
11189 VT =
ST->getMemoryVT();
11193 Ptr =
ST->getBasePtr();
11222 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
11226 bool TryNext =
false;
11234 bool RealUse =
false;
11235 for (
SDNode *UseUse : Use->uses()) {
11254 BasePtr, Offset, AM)
11256 BasePtr, Offset, AM);
11257 ++PostIndexedNodes;
11261 dbgs() <<
"\nWith: ";
11264 WorklistRemover DeadNodes(*
this);
11273 deleteAndRecombine(N);
11276 DAG.ReplaceAllUsesOfValueWith(
SDValue(Op, 0),
11278 deleteAndRecombine(Op);
11298 !cast<ConstantSDNode>(Inc)->isOpaque()) &&
11299 "Cannot split out indexing using opaque target constants");
11331 dbgs() <<
"\nWith chain: ";
11332 Chain.getNode()->dump(&DAG);
11334 WorklistRemover DeadNodes(*
this);
11335 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1), Chain);
11336 AddUsersToWorklist(Chain.getNode());
11338 deleteAndRecombine(N);
11351 cast<ConstantSDNode>(LD->
getOperand(2))->isOpaque();
11358 Index = SplitIndexingFromLoad(LD);
11361 AddUsersToWorklist(N);
11366 dbgs() <<
"\nWith: ";
11368 dbgs() <<
" and 2 other values\n");
11369 WorklistRemover DeadNodes(*
this);
11370 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 0), Undef);
11371 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1), Index);
11372 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 2), Chain);
11373 deleteAndRecombine(N);
11389 return CombineTo(N, PrevST->
getOperand(1), Chain);
11395 if (
unsigned Align = DAG.InferPtrAlignment(Ptr)) {
11397 SDValue NewLoad = DAG.getExtLoad(
11402 return CombineTo(N, NewLoad,
SDValue(NewLoad.
getNode(), 1),
true);
11409 SDValue BetterChain = FindBetterChain(N, Chain);
11412 if (Chain != BetterChain) {
11431 return CombineTo(N, ReplLoad.
getValue(0), Token);
11436 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
11441 if (SliceUpLoad(N))
11460 struct LoadedSlice {
11467 unsigned Truncates;
11468 unsigned CrossRegisterBanksCopies;
11472 Cost(
bool ForCodeSize =
false)
11473 : ForCodeSize(ForCodeSize), Loads(0), Truncates(0),
11474 CrossRegisterBanksCopies(0), ZExts(0), Shift(0) {}
11477 Cost(
const LoadedSlice &
LS,
bool ForCodeSize =
false)
11478 : ForCodeSize(ForCodeSize), Loads(1), Truncates(0),
11479 CrossRegisterBanksCopies(0), ZExts(0), Shift(0) {
11480 EVT TruncType = LS.Inst->getValueType(0);
11481 EVT LoadedType = LS.getLoadedType();
11482 if (TruncType != LoadedType &&
11483 !LS.DAG->getTargetLoweringInfo().isZExtFree(LoadedType, TruncType))
11491 void addSliceGain(
const LoadedSlice &LS) {
11495 LS.Inst->getValueType(0)))
11501 if (LS.canMergeExpensiveCrossRegisterBankCopy())
11502 ++CrossRegisterBanksCopies;
11506 Loads += RHS.Loads;
11507 Truncates += RHS.Truncates;
11508 CrossRegisterBanksCopies += RHS.CrossRegisterBanksCopies;
11509 ZExts += RHS.ZExts;
11510 Shift += RHS.Shift;
11515 return Loads == RHS.Loads && Truncates == RHS.Truncates &&
11516 CrossRegisterBanksCopies == RHS.CrossRegisterBanksCopies &&
11517 ZExts == RHS.ZExts && Shift == RHS.Shift;
11520 bool operator!=(
const Cost &RHS)
const {
return !(*
this == RHS); }
11522 bool operator<(
const Cost &RHS)
const {
11525 unsigned ExpensiveOpsLHS = Loads + CrossRegisterBanksCopies;
11526 unsigned ExpensiveOpsRHS = RHS.Loads + RHS.CrossRegisterBanksCopies;
11529 if (!ForCodeSize && ExpensiveOpsLHS != ExpensiveOpsRHS)
11530 return ExpensiveOpsLHS < ExpensiveOpsRHS;
11531 return (Truncates + ZExts + Shift + ExpensiveOpsLHS) <
11532 (RHS.Truncates + RHS.ZExts + RHS.Shift + ExpensiveOpsRHS);
11535 bool operator>(
const Cost &RHS)
const {
return RHS < *
this; }
11537 bool operator<=(
const Cost &RHS)
const {
return !(RHS < *
this); }
11539 bool operator>=(
const Cost &RHS)
const {
return !(*
this < RHS); }
11554 : Inst(Inst), Origin(Origin), Shift(Shift), DAG(DAG) {}
11559 APInt getUsedBits()
const {
11564 assert(Origin &&
"No original load to compare against.");
11565 unsigned BitWidth = Origin->getValueSizeInBits(0);
11566 assert(Inst &&
"This slice is not bound to an instruction");
11567 assert(Inst->getValueSizeInBits(0) <= BitWidth &&
11568 "Extracted slice is bigger than the whole type!");
11569 APInt UsedBits(Inst->getValueSizeInBits(0), 0);
11571 UsedBits = UsedBits.zext(BitWidth);
11572 UsedBits <<= Shift;
11577 unsigned getLoadedSize()
const {
11578 unsigned SliceSize = getUsedBits().countPopulation();
11579 assert(!(SliceSize & 0x7) &&
"Size is not a multiple of a byte.");
11580 return SliceSize / 8;
11585 EVT getLoadedType()
const {
11586 assert(DAG &&
"Missing context");
11593 unsigned Alignment = Origin->getAlignment();
11594 unsigned Offset = getOffsetFromBase();
11596 Alignment =
MinAlign(Alignment, Alignment + Offset);
11601 bool isLegal()
const {
11603 if (!Origin || !Inst || !DAG)
11607 if (!Origin->getOffset().isUndef())
11613 EVT SliceType = getLoadedType();
11623 EVT PtrType = Origin->getBasePtr().getValueType();
11636 EVT TruncateType = Inst->getValueType(0);
11637 if (TruncateType != SliceType &&
11647 uint64_t getOffsetFromBase()
const {
11648 assert(DAG &&
"Missing context.");
11649 bool IsBigEndian = DAG->getDataLayout().isBigEndian();
11650 assert(!(Shift & 0x7) &&
"Shifts not aligned on Bytes are not supported.");
11651 uint64_t Offset = Shift / 8;
11653 assert(!(Origin->getValueSizeInBits(0) & 0x7) &&
11654 "The size of the original loaded type is not a multiple of a"
11658 assert(TySizeInBytes > Offset &&
11659 "Invalid shift amount for given loaded size");
11661 Offset = TySizeInBytes - Offset - getLoadedSize();
11672 assert(Inst && Origin &&
"Unable to replace a non-existing slice.");
11673 const SDValue &OldBaseAddr = Origin->getBasePtr();
11674 SDValue BaseAddr = OldBaseAddr;
11676 int64_t Offset =
static_cast<int64_t
>(getOffsetFromBase());
11677 assert(Offset >= 0 &&
"Offset too big to fit in int64_t!");
11682 BaseAddr = DAG->getNode(
ISD::ADD, DL, ArithType, BaseAddr,
11683 DAG->getConstant(Offset, DL, ArithType));
11687 EVT SliceType = getLoadedType();
11691 DAG->getLoad(SliceType,
SDLoc(Origin), Origin->getChain(), BaseAddr,
11692 Origin->getPointerInfo().getWithOffset(Offset),
11696 EVT FinalType = Inst->getValueType(0);
11697 if (SliceType != FinalType)
11707 bool canMergeExpensiveCrossRegisterBankCopy()
const {
11708 if (!Inst || !Inst->hasOneUse())
11710 SDNode *Use = *Inst->use_begin();
11713 assert(DAG &&
"Missing context");
11732 unsigned RequiredAlignment = DAG->getDataLayout().getABITypeAlignment(
11743 if (Inst->getValueType(0) != getLoadedType())
11771 const LoadedSlice &Second) {
11772 assert(First.Origin == Second.Origin && First.Origin &&
11773 "Unable to match different memory origins.");
11774 APInt UsedBits = First.getUsedBits();
11775 assert((UsedBits & Second.getUsedBits()) == 0 &&
11776 "Slices are not supposed to overlap.");
11777 UsedBits |= Second.getUsedBits();
11786 LoadedSlice::Cost &GlobalLSCost) {
11787 unsigned NumberOfSlices = LoadedSlices.
size();
11789 if (NumberOfSlices < 2)
11795 [](
const LoadedSlice &LHS,
const LoadedSlice &RHS) {
11796 assert(LHS.Origin == RHS.Origin &&
"Different bases not implemented.");
11797 return LHS.getOffsetFromBase() < RHS.getOffsetFromBase();
11799 const TargetLowering &TLI = LoadedSlices[0].DAG->getTargetLoweringInfo();
11802 const LoadedSlice *First =
nullptr;
11803 const LoadedSlice *Second =
nullptr;
11804 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice,
11808 Second = &LoadedSlices[CurrSlice];
11815 EVT LoadedType = First->getLoadedType();
11818 if (LoadedType != Second->getLoadedType())
11822 unsigned RequiredAlignment = 0;
11823 if (!TLI.hasPairedLoad(LoadedType, RequiredAlignment)) {
11829 if (RequiredAlignment > First->getAlignment())
11836 assert(GlobalLSCost.Loads > 0 &&
"We save more loads than we created!");
11837 --GlobalLSCost.Loads;
11854 const APInt &UsedBits,
bool ForCodeSize) {
11855 unsigned NumberOfSlices = LoadedSlices.
size();
11856 if (StressLoadSlicing)
11857 return NumberOfSlices > 1;
11860 if (NumberOfSlices != 2)
11868 LoadedSlice::Cost OrigCost(ForCodeSize), GlobalSlicingCost(ForCodeSize);
11870 OrigCost.Loads = 1;
11871 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice) {
11872 const LoadedSlice &LS = LoadedSlices[CurrSlice];
11874 LoadedSlice::Cost SliceCost(LS, ForCodeSize);
11875 GlobalSlicingCost += SliceCost;
11879 OrigCost.addSliceGain(LS);
11884 return OrigCost > GlobalSlicingCost;
11893 bool DAGCombiner::SliceUpLoad(
SDNode *N) {
11912 UI != UIEnd; ++UI) {
11914 if (UI.getUse().getResNo() != 0)
11918 unsigned Shift = 0;
11941 LoadedSlice
LS(User, LD, Shift, &DAG);
11942 APInt CurrentUsedBits = LS.getUsedBits();
11945 if ((CurrentUsedBits & UsedBits) != 0)
11948 UsedBits |= CurrentUsedBits;
11955 LoadedSlices.push_back(LS);
11970 LSIt = LoadedSlices.begin(),
11971 LSItEnd = LoadedSlices.end();
11972 LSIt != LSItEnd; ++LSIt) {
11973 SDValue SliceInst = LSIt->loadSlice();
11974 CombineTo(LSIt->Inst, SliceInst,
true);
11978 "It takes more than a zext to get to the loaded slice!!");
11984 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1), Chain);
11985 AddToWorklist(Chain.
getNode());
11992 static std::pair<unsigned, unsigned>
11994 std::pair<unsigned, unsigned> Result(0, 0);
12015 if (ChainOp.getNode() ==
LD) {
12019 if (!isOk)
return Result;
12031 uint64_t NotMask = ~cast<ConstantSDNode>(V->
getOperand(1))->getSExtValue();
12033 if (NotMaskLZ & 7)
return Result;
12035 if (NotMaskTZ & 7)
return Result;
12036 if (NotMaskLZ == 64)
return Result;
12047 switch (MaskedBytes) {
12051 default:
return Result;
12056 if (NotMaskTZ && NotMaskTZ/8 % MaskedBytes)
return Result;
12058 Result.first = MaskedBytes;
12059 Result.second = NotMaskTZ/8;
12071 unsigned NumBytes = MaskInfo.first;
12072 unsigned ByteShift = MaskInfo.second;
12078 ByteShift*8, (ByteShift+NumBytes)*8);
12085 if (!DC->isTypeLegal(VT))
12102 StOffset = ByteShift;
12111 NewAlign =
MinAlign(NewAlign, StOffset);
12150 std::pair<unsigned, unsigned> MaskedLoad;
12152 if (MaskedLoad.first)
12159 if (MaskedLoad.first)
12181 APInt Imm = cast<ConstantSDNode>(N1)->getAPIntValue();
12192 while (NewBW < BitWidth &&
12199 if (NewBW >= BitWidth)
12205 ShAmt = (((ShAmt + NewBW - 1) / NewBW) * NewBW) - NewBW;
12207 std::min(BitWidth, ShAmt + NewBW));
12208 if ((Imm & Mask) == Imm) {
12212 uint64_t PtrOff = ShAmt / 8;
12215 if (DAG.getDataLayout().isBigEndian())
12216 PtrOff = (BitWidth + 7 - NewBW) / 8 - PtrOff;
12220 if (NewAlign < DAG.getDataLayout().getABITypeAlignment(NewVTTy))
12225 DAG.getConstant(PtrOff,
SDLoc(LD),
12231 SDValue NewVal = DAG.getNode(Opc,
SDLoc(Value), NewVT, NewLD,
12232 DAG.getConstant(NewImm,
SDLoc(Value),
12235 DAG.getStore(Chain,
SDLoc(N), NewVal, NewPtr,
12238 AddToWorklist(NewPtr.
getNode());
12239 AddToWorklist(NewLD.
getNode());
12240 AddToWorklist(NewVal.
getNode());
12241 WorklistRemover DeadNodes(*
this);
12263 if (!VT.isFloatingPoint() ||
12281 unsigned ABIAlign = DAG.getDataLayout().getABITypeAlignment(IntVTTy);
12282 if (LDAlign < ABIAlign || STAlign < ABIAlign)
12293 AddToWorklist(NewLD.
getNode());
12294 AddToWorklist(NewST.
getNode());
12295 WorklistRemover DeadNodes(*
this);
12317 bool DAGCombiner::isMulAddWithConstProfitable(
SDNode *MulNode,
12329 if (Use == MulNode)
12352 if (OtherOp == MulVar)
12369 DAG.isConstantIntBuildVectorOrConstantInt(OtherOp->
getOperand(1)) &&
12380 unsigned NumStores) {
12383 SDLoc StoreDL(StoreNodes[0].MemNode);
12385 for (
unsigned i = 0; i < NumStores; ++i) {
12386 Visited.
insert(StoreNodes[i].MemNode);
12390 for (
unsigned i = 0; i < NumStores; ++i) {
12391 if (Visited.
count(StoreNodes[i].MemNode->getChain().getNode()) == 0)
12392 Chains.
push_back(StoreNodes[i].MemNode->getChain());
12395 assert(Chains.
size() > 0 &&
"Chain should have generated a chain");
12399 bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
12401 bool IsConstantSrc,
bool UseVector,
bool UseTrunc) {
12409 SDLoc DL(StoreNodes[0].MemNode);
12414 unsigned Elts = NumStores;
12423 if (IsConstantSrc) {
12426 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[
I].MemNode);
12429 if (
auto *CFP = dyn_cast<ConstantFPSDNode>(St->
getValue()))
12430 Val = DAG.getConstant(
12431 (
uint32_t)CFP->getValueAPF().bitcastToAPInt().getZExtValue(),
12432 SDLoc(CFP), MemVT);
12435 StoredVal = DAG.getBuildVector(Ty, DL, BuildVector);
12438 for (
unsigned i = 0; i < NumStores; ++i) {
12439 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
12442 if (Val.getValueType() != MemVT)
12453 assert(IsConstantSrc &&
"Merged vector elements should use vector store");
12455 unsigned SizeInBits = NumStores * ElementSizeBytes * 8;
12456 APInt StoreInt(SizeInBits, 0);
12460 bool IsLE = DAG.getDataLayout().isLittleEndian();
12461 for (
unsigned i = 0; i < NumStores; ++i) {
12462 unsigned Idx = IsLE ? (NumStores - 1 - i) : i;
12463 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[Idx].MemNode);
12465 SDValue Val = St->getValue();
12466 StoreInt <<= ElementSizeBytes * 8;
12468 StoreInt |=
C->getAPIntValue().zextOrTrunc(SizeInBits);
12470 StoreInt |=
C->getValueAPF().bitcastToAPInt().zextOrTrunc(SizeInBits);
12478 StoredVal = DAG.getConstant(StoreInt, DL, StoreTy);
12482 SDValue NewChain = getMergeStoreChains(StoreNodes, NumStores);
12486 if (UseVector || !UseTrunc) {
12487 NewStore = DAG.getStore(NewChain, DL, StoredVal, FirstInChain->
getBasePtr(),
12491 EVT LegalizedStoredValueTy =
12493 unsigned LegalizedStoreSize = LegalizedStoredValueTy.
getSizeInBits();
12497 LegalizedStoredValueTy);
12498 NewStore = DAG.getTruncStore(
12499 NewChain, DL, ExtendedStoreVal, FirstInChain->
getBasePtr(),
12506 for (
unsigned i = 0; i < NumStores; ++i)
12507 CombineTo(StoreNodes[i].MemNode, NewStore);
12509 AddToWorklist(NewChain.
getNode());
12513 void DAGCombiner::getStoreMergeCandidates(
12528 bool IsConstantSrc = isa<ConstantSDNode>(St->
getValue()) ||
12529 isa<ConstantFPSDNode>(St->
getValue());
12530 bool IsExtractVecSrc =
12533 bool IsLoadSrc = isa<LoadSDNode>(St->
getValue());
12538 cast<LoadSDNode>(St->
getValue())->getBasePtr(), DAG);
12541 int64_t &
Offset) ->
bool {
12546 if (!(MemVT.isInteger() && MemVT.bitsEq(Other->
getMemoryVT()) &&
12547 isa<ConstantFPSDNode>(Other->
getValue())))
12553 if (!(LBasePtr.equalBaseIndex(LPtr, DAG)))
12559 if (!(isa<ConstantSDNode>(Other->
getValue()) ||
12560 isa<ConstantFPSDNode>(Other->
getValue())))
12562 if (IsExtractVecSrc)
12587 if (
LoadSDNode *Ldn = dyn_cast<LoadSDNode>(RootNode)) {
12588 RootNode = Ldn->getChain().getNode();
12590 if (
I.getOperandNo() == 0 && isa<LoadSDNode>(*I))
12591 for (
auto I2 = (*I)->use_begin(), E2 = (*I)->use_end(); I2 != E2; ++I2)
12592 if (I2.getOperandNo() == 0)
12593 if (
StoreSDNode *OtherST = dyn_cast<StoreSDNode>(*I2)) {
12596 if (CandidateMatch(OtherST, Ptr, PtrDiff))
12597 StoreNodes.
push_back(MemOpLink(OtherST, PtrDiff));
12601 if (
I.getOperandNo() == 0)
12602 if (
StoreSDNode *OtherST = dyn_cast<StoreSDNode>(*
I)) {
12605 if (CandidateMatch(OtherST, Ptr, PtrDiff))
12606 StoreNodes.
push_back(MemOpLink(OtherST, PtrDiff));
12616 bool DAGCombiner::checkMergeStoreCandidatesForDependencies(
12626 unsigned int Max = 8192;
12628 for (
unsigned i = 0; i < NumStores; ++i) {
12629 SDNode *n = StoreNodes[i].MemNode;
12635 for (
unsigned i = 0; i < NumStores; ++i) {
12640 if (Visited.
size() >= Max)
12646 bool DAGCombiner::MergeConsecutiveStores(
StoreSDNode *St) {
12656 bool NoVectors = DAG.getMachineFunction().getFunction()->hasFnAttribute(
12657 Attribute::NoImplicitFloat);
12669 bool IsLoadSrc = isa<LoadSDNode>(StoredVal);
12670 bool IsConstantSrc = isa<ConstantSDNode>(StoredVal) ||
12671 isa<ConstantFPSDNode>(StoredVal);
12675 if (!IsConstantSrc && !IsLoadSrc && !IsExtractVecSrc)
12681 if (MemVT.
isVector() && IsLoadSrc)
12686 getStoreMergeCandidates(St, StoreNodes);
12689 if (StoreNodes.
size() < 2)
12695 [](MemOpLink LHS, MemOpLink RHS) {
12696 return LHS.OffsetFromBase < RHS.OffsetFromBase;
12708 while (StoreNodes.
size() > 1) {
12709 unsigned StartIdx = 0;
12710 while ((StartIdx + 1 < StoreNodes.
size()) &&
12711 StoreNodes[StartIdx].OffsetFromBase + ElementSizeBytes !=
12712 StoreNodes[StartIdx + 1].OffsetFromBase)
12716 if (StartIdx + 1 >= StoreNodes.
size())
12724 unsigned NumConsecutiveStores = 1;
12725 int64_t StartAddress = StoreNodes[0].OffsetFromBase;
12728 for (
unsigned i = 1, e = StoreNodes.
size(); i < e; ++i) {
12729 int64_t CurrAddress = StoreNodes[i].OffsetFromBase;
12730 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
12732 NumConsecutiveStores = i + 1;
12735 if (NumConsecutiveStores < 2) {
12737 StoreNodes.
begin() + NumConsecutiveStores);
12742 if (!checkMergeStoreCandidatesForDependencies(StoreNodes,
12743 NumConsecutiveStores)) {
12745 StoreNodes.
begin() + NumConsecutiveStores);
12754 if (IsConstantSrc) {
12757 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
12758 unsigned LastLegalType = 1;
12759 unsigned LastLegalVectorType = 1;
12760 bool LastIntegerTrunc =
false;
12761 bool NonZero =
false;
12762 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
12763 StoreSDNode *ST = cast<StoreSDNode>(StoreNodes[i].MemNode);
12769 dyn_cast<ConstantFPSDNode>(StoredVal)) {
12770 NonZero |= !C->getConstantFPValue()->
isNullValue();
12777 unsigned SizeInBits = (i + 1) * ElementSizeBytes * 8;
12779 bool IsFast =
false;
12783 FirstStoreAlign, &IsFast) &&
12785 LastIntegerTrunc =
false;
12786 LastLegalType = i + 1;
12790 EVT LegalizedStoredValueTy =
12795 FirstStoreAS, FirstStoreAlign, &IsFast) &&
12797 LastIntegerTrunc =
true;
12798 LastLegalType = i + 1;
12809 unsigned Elts = i + 1;
12818 FirstStoreAlign, &IsFast) &&
12820 LastLegalVectorType = i + 1;
12825 if (LastLegalType < 2 && LastLegalVectorType < 2) {
12830 bool UseVector = (LastLegalVectorType > LastLegalType) && !NoVectors;
12831 unsigned NumElem = (UseVector) ? LastLegalVectorType : LastLegalType;
12833 bool Merged = MergeStoresOfConstantsOrVecElts(
12834 StoreNodes, MemVT, NumElem,
true, UseVector, LastIntegerTrunc);
12847 if (IsExtractVecSrc) {
12850 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
12851 unsigned NumStoresToMerge = 1;
12853 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
12854 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
12866 unsigned Elts = i + 1;
12877 FirstStoreAlign, &IsFast) &&
12879 NumStoresToMerge = i + 1;
12882 bool Merged = MergeStoresOfConstantsOrVecElts(
12883 StoreNodes, MemVT, NumStoresToMerge,
false,
true,
false);
12886 StoreNodes.
begin() + NumStoresToMerge);
12891 StoreNodes.
begin() + NumStoresToMerge);
12906 for (
unsigned i = 0; i < NumConsecutiveStores; ++i) {
12907 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
12913 if (!Ld->hasNUsesOfValue(1, 0))
12917 if (Ld->isVolatile() || Ld->isIndexed())
12925 if (Ld->getMemoryVT() != MemVT)
12930 int64_t LdOffset = 0;
12941 LoadNodes.
push_back(MemOpLink(Ld, LdOffset));
12944 if (LoadNodes.
size() < 2) {
12951 unsigned RequiredAlignment;
12953 StoreNodes[0].MemNode->getAlignment() >= RequiredAlignment) {
12959 unsigned FirstStoreAlign = FirstInChain->
getAlignment();
12960 LoadSDNode *FirstLoad = cast<LoadSDNode>(LoadNodes[0].MemNode);
12967 unsigned LastConsecutiveLoad = 1;
12969 unsigned LastLegalVectorType = 1;
12970 unsigned LastLegalIntegerType = 1;
12971 bool isDereferenceable =
true;
12972 bool DoIntegerTruncate =
false;
12973 StartAddress = LoadNodes[0].OffsetFromBase;
12975 for (
unsigned i = 1; i < LoadNodes.
size(); ++i) {
12977 if (LoadNodes[i].MemNode->getChain() != FirstChain)
12980 int64_t CurrAddress = LoadNodes[i].OffsetFromBase;
12981 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
12983 LastConsecutiveLoad = i;
12985 if (isDereferenceable && !LoadNodes[i].MemNode->isDereferenceable())
12986 isDereferenceable =
false;
12990 bool IsFastSt, IsFastLd;
12994 FirstStoreAlign, &IsFastSt) &&
12997 FirstLoadAlign, &IsFastLd) &&
12999 LastLegalVectorType = i + 1;
13003 unsigned SizeInBits = (i + 1) * ElementSizeBytes * 8;
13008 FirstStoreAlign, &IsFastSt) &&
13011 FirstLoadAlign, &IsFastLd) &&
13013 LastLegalIntegerType = i + 1;
13014 DoIntegerTruncate =
false;
13027 FirstStoreAS, FirstStoreAlign, &IsFastSt) &&
13030 FirstLoadAlign, &IsFastLd) &&
13032 LastLegalIntegerType = i + 1;
13033 DoIntegerTruncate =
true;
13040 bool UseVectorTy = LastLegalVectorType > LastLegalIntegerType && !NoVectors;
13041 unsigned LastLegalType =
13042 std::max(LastLegalVectorType, LastLegalIntegerType);
13046 unsigned NumElem =
std::min(NumConsecutiveStores, LastConsecutiveLoad + 1);
13047 NumElem =
std::min(LastLegalType, NumElem);
13060 unsigned SizeInBits = NumElem * ElementSizeBytes * 8;
13064 SDLoc LoadDL(LoadNodes[0].MemNode);
13065 SDLoc StoreDL(StoreNodes[0].MemNode);
13070 SDValue NewStoreChain = getMergeStoreChains(StoreNodes, NumElem);
13071 AddToWorklist(NewStoreChain.
getNode());
13078 if (UseVectorTy || !DoIntegerTruncate) {
13079 NewLoad = DAG.getLoad(JointMemOpVT, LoadDL, FirstLoad->
getChain(),
13083 NewStore = DAG.getStore(NewStoreChain, StoreDL, NewLoad,
13092 JointMemOpVT, FirstLoadAlign, MMOFlags);
13093 NewStore = DAG.getTruncStore(NewStoreChain, StoreDL, NewLoad,
13101 for (
unsigned i = 0; i < NumElem; ++i) {
13102 LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[i].MemNode);
13103 DAG.ReplaceAllUsesOfValueWith(
SDValue(Ld, 1),
13108 for (
unsigned i = 0; i < NumElem; ++i)
13109 CombineTo(StoreNodes[i].MemNode, NewStore);
13123 ReplStore = DAG.getTruncStore(BetterChain, SL, ST->
getValue(),
13136 AddToWorklist(Token.
getNode());
13139 return CombineTo(ST, Token,
false);
13173 bitcastToAPInt().getZExtValue(),
SDLoc(CFP),
13175 return DAG.getStore(Chain, DL, Tmp, Ptr, ST->
getMemOperand());
13186 return DAG.getStore(Chain, DL, Tmp,
13198 if (DAG.getDataLayout().isBigEndian())
13209 Alignment =
MinAlign(Alignment, 4U);
13210 SDValue St1 = DAG.getStore(Chain, DL, Hi, Ptr,
13212 Alignment, MMOFlags, AAInfo);
13232 if (((!LegalOperations && !ST->
isVolatile()) ||
13253 if (
unsigned Align = DAG.InferPtrAlignment(Ptr)) {
13260 return CombineTo(ST, NewStore,
true);
13267 if (
SDValue NewST = TransformFPLoadStorePair(N))
13273 if (findBetterNeighborChains(ST)) {
13287 SDValue Shorter = GetDemandedBits(
13290 AddToWorklist(Value.
getNode());
13292 return DAG.getTruncStore(Chain,
SDLoc(N), Shorter,
13313 if (
LoadSDNode *Ld = dyn_cast<LoadSDNode>(Value)) {
13318 Chain.reachesChainWithoutSideEffects(
SDValue(Ld, 1))) {
13324 if (
StoreSDNode *ST1 = dyn_cast<StoreSDNode>(Chain)) {
13326 !ST1->isVolatile() && ST1->getBasePtr() == Ptr &&
13330 if (ST1->getValue() == Value) {
13340 !ST1->getBasePtr().isUndef()) {
13343 CombineTo(ST1, ST1->getChain());
13367 bool Changed = MergeConsecutiveStores(ST);
13368 if (!Changed)
break;
13377 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
13385 if (isa<ConstantFPSDNode>(ST->
getValue())) {
13386 if (
SDValue NewSt = replaceStoreOfFPConstant(ST))
13393 return ReduceLoadOpStoreWidth(N);
13493 DAG.getConstant(HalfValBitSize / 8, DL, Ptr.
getValueType()));
13496 DAG.getStore(St0, DL, Hi, Ptr,
13498 Alignment / 2, MMOFlags, AAInfo);
13515 if (!isa<ConstantSDNode>(EltNo))
13517 unsigned Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
13527 && isa<ConstantSDNode>(InVec.
getOperand(2))) {
13529 if (Elt < OtherElt) {
13533 AddToWorklist(NewOp.
getNode());
13552 }
else if (InVec.
isUndef()) {
13560 if (Elt < Ops.
size()) {
13563 EVT OpVT = Ops[0].getValueType();
13564 Ops[Elt] = OpVT.
isInteger() ? DAG.getAnyExtOrTrunc(InVal, DL, OpVT) : InVal;
13568 return DAG.getBuildVector(VT, DL, Ops);
13571 SDValue DAGCombiner::ReplaceExtractVectorEltOfLoadWithNarrowedLoad(
13578 unsigned NewAlign = DAG.getDataLayout().getABITypeAlignment(
13596 if (
auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo)) {
13597 int Elt = ConstEltNo->getZExtValue();
13599 Offset = DAG.getConstant(PtrOff, DL, PtrType);
13602 Offset = DAG.getZExtOrTrunc(EltNo, DL, PtrType);
13618 if (ResultVT.bitsGT(VecEltVT)) {
13625 Load = DAG.getExtLoad(ExtType,
SDLoc(EVE), ResultVT,
13626 OriginalLoad->
getChain(), NewPtr, MPI, VecEltVT,
13631 Load = DAG.getLoad(VecEltVT,
SDLoc(EVE), OriginalLoad->
getChain(), NewPtr,
13635 if (ResultVT.bitsLT(VecEltVT))
13638 Load = DAG.getBitcast(ResultVT, Load);
13640 WorklistRemover DeadNodes(*
this);
13643 DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
13646 AddToWorklist(Load.
getNode());
13647 AddUsersToWorklist(Load.
getNode());
13649 AddToWorklist(EVE);
13661 return DAG.getUNDEF(NVT);
13670 return DAG.getSExtOrTrunc(InOp,
SDLoc(InVec), NVT);
13688 if (NVT == InEltVT)
13710 return VT.
isInteger() ? DAG.getAnyExtOrTrunc(Elt,
SDLoc(N), NVT) : Elt;
13727 return DAG.getUNDEF(NVT);
13731 if (OrigElt < NumElem) {
13735 OrigElt -= NumElem;
13742 InOp = DAG.getSExtOrTrunc(InOp,
SDLoc(SVInVec), NVT);
13751 if (!LegalOperations) {
13754 DAG.getConstant(OrigElt,
SDLoc(SVOp), IndexTy));
13758 bool BCNumEltsChanged =
false;
13776 BCNumEltsChanged =
true;
13782 if (!LegalOperations && !ConstEltNo && InVec.
hasOneUse() &&
13786 if (
LoadSDNode *OrigLoad = dyn_cast<LoadSDNode>(InVec)) {
13787 if (!OrigLoad->isVolatile()) {
13788 return ReplaceExtractVectorEltOfLoadWithNarrowedLoad(N, VT, Index,
13796 if (!LegalOperations)
return SDValue();
13803 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
13808 LN0 = cast<LoadSDNode>(InVec);
13816 LN0 = cast<LoadSDNode>(InVec.
getOperand(0));
13817 }
else if ((SVN = dyn_cast<ShuffleVectorSDNode>(InVec))) {
13828 if (BCNumEltsChanged)
13833 int Idx = (Elt > (int)NumElems) ? -1 : SVN->
getMaskElt(Elt);
13844 LN0 = cast<LoadSDNode>(InVec);
13845 Elt = (Idx < (int)NumElems) ? Idx : Idx - (int)NumElems;
13846 EltNo = DAG.getConstant(Elt,
SDLoc(EltNo), EltNo.getValueType());
13857 return DAG.getUNDEF(LVT);
13859 return ReplaceExtractVectorEltOfLoadWithNarrowedLoad(N, VT, EltNo, LN0);
13866 SDValue DAGCombiner::reduceBuildVecExtToExtBuildVec(
SDNode *N) {
13886 bool AllAnyExt =
true;
13888 for (
unsigned i = 0; i != NumInScalars; ++i) {
13897 if (!ZeroExt && !AnyExt) {
13909 else if (InTy != SourceType) {
13916 AllAnyExt &= AnyExt;
13923 bool ValidTypes = SourceType !=
MVT::Other &&
13932 bool isLE = DAG.getDataLayout().isLittleEndian();
13934 assert(ElemRatio > 1 &&
"Invalid element size ratio");
13935 SDValue Filler = AllAnyExt ? DAG.getUNDEF(SourceType):
13936 DAG.getConstant(0, DL, SourceType);
13946 Cast.
isUndef()) &&
"Invalid cast opcode");
13949 In = DAG.getUNDEF(SourceType);
13952 unsigned Index = isLE ? (i * ElemRatio) :
13953 (i * ElemRatio + (ElemRatio - 1));
13955 assert(Index < Ops.
size() &&
"Invalid index");
13962 "Invalid vector size");
13967 SDValue BV = DAG.getBuildVector(VecVT, DL, Ops);
13972 return DAG.getBitcast(VT, BV);
13975 SDValue DAGCombiner::reduceBuildVecConvertToConvertBuildVec(
SDNode *N) {
13983 unsigned NumDefs = 0;
13985 for (
unsigned i = 0; i != NumInScalars; ++i) {
14018 &&
"Should only handle conversion from integer to float.");
14032 for (
unsigned i = 0; i != NumInScalars; ++i) {
14040 SDValue BV = DAG.getBuildVector(NVT, DL, Opnds);
14043 return DAG.
getNode(Opcode, DL, VT, BV);
14049 unsigned LeftIdx) {
14051 SDValue ZeroIdx = DAG.getConstant(0, DL, IdxTy);
14059 unsigned ShuffleNumElems = NumElems;
14063 if (InVT1 != VT || InVT2 != VT) {
14068 assert(NumConcats >= 2 &&
"Concat needs at least two inputs!");
14070 ConcatOps[0] = VecIn1;
14071 ConcatOps[1] = VecIn2 ? VecIn2 : DAG.getUNDEF(InVT1);
14082 DAG.getConstant(NumElems, DL, IdxTy));
14086 Vec2Offset = NumElems;
14092 if (LegalOperations &&
14099 if (InVT1 != InVT2) {
14103 DAG.getUNDEF(InVT1), VecIn2, ZeroIdx);
14105 ShuffleNumElems = NumElems * 2;
14115 ConcatOps[0] = VecIn2;
14132 for (
unsigned i = 0; i != NumElems; ++i) {
14133 if (VectorMask[i] <= 0)
14137 if (VectorMask[i] == (
int)LeftIdx) {
14138 Mask[i] = ExtIndex;
14139 }
else if (VectorMask[i] == (
int)LeftIdx + 1) {
14140 Mask[i] = Vec2Offset + ExtIndex;
14149 VecIn2 = VecIn2.
getNode() ? VecIn2 : DAG.getUNDEF(InVT1);
14152 SDValue Shuffle = DAG.getVectorShuffle(InVT1, DL, VecIn1, VecIn2, Mask);
14153 if (ShuffleNumElems > NumElems)
14174 bool UsesZeroVector =
false;
14187 for (
unsigned i = 0; i != NumElems; ++i) {
14197 UsesZeroVector =
true;
14218 unsigned Idx = std::distance(
14220 if (Idx == VecIn.
size())
14223 VectorMask[i] = Idx;
14227 if (VecIn.
size() < 2)
14250 for (
unsigned In = 0, Len = (VecIn.
size() / 2); In < Len; ++
In) {
14251 unsigned LeftIdx = 2 * In + 1;
14252 SDValue VecLeft = VecIn[LeftIdx];
14254 (LeftIdx + 1) < VecIn.
size() ? VecIn[LeftIdx + 1] :
SDValue();
14256 if (
SDValue Shuffle = createBuildVecShuffle(DL, N, VectorMask, VecLeft,
14257 VecRight, LeftIdx))
14265 if (UsesZeroVector)
14267 : DAG.getConstantFP(0.0, DL, VT));
14270 if (Shuffles.
size() == 1)
14271 return Shuffles[0];
14274 for (
int &Vec : VectorMask)
14276 Vec = Shuffles.
size() - 1;
14278 Vec = (Vec - 1) / 2;
14292 if (Shuffles.
size() % 2)
14295 for (
unsigned CurSize = Shuffles.
size(); CurSize > 1; CurSize /= 2) {
14297 Shuffles[CurSize] = DAG.getUNDEF(VT);
14300 for (
unsigned In = 0, Len = CurSize / 2; In < Len; ++
In) {
14302 int Right = 2 * In + 1;
14304 for (
unsigned i = 0; i != NumElems; ++i) {
14305 if (VectorMask[i] == Left) {
14307 VectorMask[i] =
In;
14308 }
else if (VectorMask[i] == Right) {
14309 Mask[i] = i + NumElems;
14310 VectorMask[i] =
In;
14315 DAG.getVectorShuffle(VT, DL, Shuffles[Left], Shuffles[Right], Mask);
14319 return Shuffles[0];
14326 if (DAG.getDataLayout().isBigEndian())
14348 auto GetExtractIdx = [](
SDValue Extract) {
14349 return cast<ConstantSDNode>(Extract.getOperand(1))->getSExtValue();
14358 int Stride = GetExtractIdx(N->
getOperand(1));
14363 (ExtractedFromVec.getValueType().getVectorNumElements() !=
14364 Stride * NumElems) ||
14369 for (
unsigned i = 1; i != NumElems; ++i) {
14372 if ((Op.
getOperand(0) != ExtractedFromVec) ||
14373 (GetExtractIdx(Op) != Stride * i))
14384 SDValue Res = DAG.getBitcast(NewVT, ExtractedFromVec);
14386 return DAG.getBitcast(VT, Res);
14394 return DAG.getUNDEF(VT);
14399 auto checkElem = [&](
SDValue Op) -> uint64_t {
14402 if (
auto CNode = dyn_cast<ConstantSDNode>(Op.
getOperand(1)))
14403 return CNode->getZExtValue();
14407 int Offset = checkElem(Op0);
14409 if (Offset + i != checkElem(N->
getOperand(i))) {
14415 if ((Offset == 0) &&
14418 if ((Offset != -1) &&
14425 if (
SDValue V = reduceBuildVecExtToExtBuildVec(N))
14428 if (
SDValue V = reduceBuildVecConvertToConvertBuildVec(N))
14432 if (
SDValue V = reduceBuildVecToTrunc(N))
14435 if (
SDValue V = reduceBuildVecToShuffle(N))
14457 bool AnyInteger =
false;
14458 bool AnyFP =
false;
14522 Mask.
append((
unsigned)NumOpElts, -1);
14542 Mask.
append((
unsigned)NumOpElts, -1);
14557 if (0 == (NumExtElts % NumElts))
14558 ExtIdx /= (NumExtElts / NumElts);
14559 else if (0 == (NumElts % NumExtElts))
14560 ExtIdx *= (NumElts / NumExtElts);
14565 if (SV0.
isUndef() || SV0 == ExtVec) {
14567 for (
int i = 0; i != NumOpElts; ++i)
14569 }
else if (SV1.isUndef() || SV1 == ExtVec) {
14571 for (
int i = 0; i != NumOpElts; ++i)
14593 return DAG.getUNDEF(VT);
14621 if (VNTNumElms < 2)
14629 return DAG.getBitcast(VT, Res);
14637 auto IsBuildVectorOrUndef = [](
const SDValue &
Op) {
14648 bool FoundMinVT =
false;
14652 MinVT = (!FoundMinVT || OpSVT.
bitsLE(MinVT)) ? OpSVT : MinVT;
14655 assert(FoundMinVT &&
"Concat vector type mismatch");
14663 Opnds.
append(NumElts, DAG.getUNDEF(MinVT));
14670 for (
unsigned i = 0; i != NumElts; ++i)
14678 "Concat vector type mismatch");
14679 return DAG.getBuildVector(VT,
SDLoc(N), Opnds);
14709 if (SingleSource.
getNode()) {
14722 unsigned IdentityIndex = i * PartNumElem;
14734 return SingleSource;
14756 assert((ExtractIndex->getZExtValue() % NumElems) == 0 &&
14757 "Extract index is not a multiple of the vector length.");
14785 if (!TLI.isOperationLegalOrCustomOrPromote(BOpcode, NarrowBVT))
14804 if (!ConcatL && !ConcatR)
14810 unsigned ConcatOpNum = ExtractIndex->getZExtValue() / NumElems;
14828 SDValue NarrowBinOp = DAG.
getNode(BOpcode, DL, NarrowBVT, X, Y);
14871 return DAG.getUNDEF(NVT);
14888 assert((Idx % NumElems) == 0 &&
14889 "IDX in concat is not a multiple of the result vector length.");
14901 if (!NVT.
bitsEq(SmallVT))
14908 if (InsIdx && ExtIdx) {
14916 return DAG.getBitcast(NVT, V->
getOperand(1));
14917 return DAG.getNode(
14943 bool FoundSimplification =
false;
14946 for (
int i = 0, NumOps = V->
getNumOperands(); i < NumOps; ++i) {
14948 bool OpUsed =
false;
14949 for (
int j = 0; j < OpSize; ++j)
14950 if (UsedElements[i * OpSize + j]) {
14951 OpUsedElements[j] =
true;
14957 FoundSimplification |= Op == NewOps.
back();
14958 OpUsedElements.
reset();
14960 if (FoundSimplification)
14973 int Idx = IdxN->getZExtValue();
14974 bool SubVectorUsed =
false;
14976 for (
int i = 0; i < SubSize; ++i)
14977 if (UsedElements[i + Idx]) {
14978 SubVectorUsed =
true;
14979 SubUsedElements[i] =
true;
14980 UsedElements[i + Idx] =
false;
14989 if (SimplifiedSubV != SubV || SimplifiedBaseV != BaseV)
14991 SimplifiedBaseV, SimplifiedSubV, V->
getOperand(2));
15001 SmallBitVector N0UsedElements(NumElts,
false), N1UsedElements(NumElts,
false);
15003 if (M >= 0 && M < NumElts)
15004 N0UsedElements[M] =
true;
15005 else if (M >= NumElts)
15006 N1UsedElements[M - NumElts] =
true;
15010 if (S0 == N0 && S1 == N1)
15029 unsigned NumConcats = NumElts / NumElemsPerConcat;
15034 if (NumElemsPerConcat * 2 == NumElts && N1.
isUndef() &&
15036 SVN->
getMask().end(), [](
int i) {
return i == -1; })) {
15045 for (
unsigned I = 0;
I != NumConcats; ++
I) {
15047 unsigned Begin =
I * NumElemsPerConcat;
15048 bool AllUndef =
true, NoUndef =
true;
15049 for (
unsigned J = Begin; J != Begin + NumElemsPerConcat; ++J) {
15057 if (SVN->
getMaskElt(Begin) % NumElemsPerConcat != 0)
15060 for (
unsigned J = 1; J != NumElemsPerConcat; ++J)
15064 unsigned FirstElt = SVN->
getMaskElt(Begin) / NumElemsPerConcat;
15070 }
else if (AllUndef) {
15119 for (
int M : SVN->
getMask()) {
15122 int Idx = M < (int)NumElts ? M : M - NumElts;
15123 SDValue &S = (M < (int)NumElts ? N0 : N1);
15138 if (!Op.
isUndef() && !isa<ConstantSDNode>(
Op) && !isa<ConstantFPSDNode>(Op))
15139 if (!DuplicateOps.
insert(Op).second)
15165 bool LegalOperations) {
15179 auto isAnyExtend = [&
Mask, &NumElts](
unsigned Scale) {
15180 for (
unsigned i = 0; i != NumElts; ++i) {
15183 if ((i % Scale) == 0 && Mask[i] == (int)(i / Scale))
15192 for (
unsigned Scale = 2; Scale < NumElts; Scale *= 2) {
15193 if (!isAnyExtend(Scale))
15198 if (!LegalOperations ||
15238 if (ExtDstSizeInBits % ExtSrcSizeInBits != 0)
15240 unsigned ExtScale = ExtDstSizeInBits / ExtSrcSizeInBits;
15245 auto isTruncate = [&
Mask, &NumElts](
unsigned Scale) {
15246 for (
unsigned i = 0; i != NumElts; ++i) {
15249 if ((i * Scale) < NumElts && Mask[i] == (int)(i * Scale))
15259 if (EltSizeInBits != ExtSrcSizeInBits)
15264 if (isTruncate(ExtScale))
15279 assert(UserMask.
size() == SplatMask.
size() &&
"Mask length mismatch");
15297 auto CanSimplifyToExistingSplat = [](
ArrayRef<int> UserMask,
15299 for (
unsigned i = 0, e = UserMask.
size(); i != e; ++i)
15300 if (UserMask[i] != -1 && SplatMask[i] == -1 &&
15301 SplatMask[UserMask[i]] != -1)
15305 if (CanSimplifyToExistingSplat(UserMask, SplatMask))
15311 for (
int Idx : UserMask)
15312 NewMask.
push_back(Idx == -1 ? -1 : SplatMask[Idx]);
15330 return DAG.getUNDEF(VT);
15337 for (
unsigned i = 0; i != NumElts; ++i) {
15339 if (Idx >= (
int)NumElts) Idx -= NumElts;
15342 return DAG.getVectorShuffle(VT,
SDLoc(N), N0, DAG.getUNDEF(VT), NewMask);
15347 return DAG.getCommutedVectorShuffle(*SVN);
15351 bool Changed =
false;
15353 for (
unsigned i = 0; i != NumElts; ++i) {
15355 if (Idx >= (
int)NumElts) {
15362 return DAG.getVectorShuffle(VT,
SDLoc(N), N0, N1, NewMask);
15366 if (
auto *N0Shuf = dyn_cast<ShuffleVectorSDNode>(N0))
15367 if (N1->
isUndef() && N0Shuf->isSplat())
15387 "BUILD_VECTOR has wrong number of operands");
15389 bool AllSame =
true;
15390 for (
unsigned i = 0; i != NumElts; ++i) {
15397 if (!Base.getNode())
15399 for (
unsigned i = 0; i != NumElts; ++i) {
15417 NewBV = DAG.getBitcast(VT, NewBV);
15472 for (
int s = 0; s != Scale; ++s)
15473 NewMask.
push_back(M < 0 ? -1 : Scale * M + s);
15483 EVT ScaleVT = SVT.
bitsLT(InnerSVT) ? VT : InnerVT;
15496 ScaleShuffleMask(InnerSVN->
getMask(), InnerScale);
15498 ScaleShuffleMask(SVN->
getMask(), OuterScale);
15502 for (
int M : OuterMask)
15503 NewMask.
push_back(M < 0 ? -1 : InnerMask[M]);
15516 SV0 = DAG.getBitcast(ScaleVT, SV0);
15517 SV1 = DAG.getBitcast(ScaleVT, SV1);
15518 return DAG.getBitcast(
15519 VT, DAG.getVectorShuffle(ScaleVT,
SDLoc(N), SV0, SV1, NewMask));
15535 "Shuffle types don't match");
15539 bool HasSameOp0 = N0 == SV0;
15540 bool IsSV1Undef = SV1.
isUndef();
15541 if (HasSameOp0 || IsSV1Undef || N0 == SV1)
15544 return DAG.getCommutedVectorShuffle(*SVN);
15565 "Shuffle types don't match");
15571 for (
unsigned i = 0; i != NumElts; ++i) {
15580 if (Idx < (
int)NumElts) {
15590 CurrentVec = (Idx < (int) NumElts) ? OtherSV->
getOperand(0)
15605 Idx = Idx % NumElts;
15606 if (!SV0.getNode() || SV0 == CurrentVec) {
15615 if (SV1.getNode() && SV1 != CurrentVec)
15625 bool isUndefMask =
true;
15626 for (
unsigned i = 0; i != NumElts && isUndefMask; ++i)
15627 isUndefMask &= Mask[i] < 0;
15630 return DAG.getUNDEF(VT);
15632 if (!SV0.getNode())
15633 SV0 = DAG.getUNDEF(VT);
15634 if (!SV1.getNode())
15635 SV1 = DAG.getUNDEF(VT);
15653 return DAG.getVectorShuffle(VT,
SDLoc(N), SV0, SV1, Mask);
15679 return DAG.getVectorShuffle(VT,
SDLoc(N), InVec, DAG.getUNDEF(VT),
15712 if (!isa<ConstantSDNode>(N2))
15715 unsigned InsIdx = cast<ConstantSDNode>(N2)->getZExtValue();
15725 if (InsIdx < OtherIdx) {
15729 AddToWorklist(NewOp.
getNode());
15742 Ops[cast<ConstantSDNode>(N2)->getZExtValue() / Factor] = N1;
15787 if (LegalOperations)
15805 auto BuildClearMask = [&](
int Split) {
15806 int NumSubElts = NumElts *
Split;
15810 for (
int i = 0; i != NumSubElts; ++i) {
15811 int EltIdx = i /
Split;
15812 int SubIdx = i %
Split;
15820 if (isa<ConstantSDNode>(Elt))
15821 Bits = cast<ConstantSDNode>(Elt)->getAPIntValue();
15822 else if (isa<ConstantFPSDNode>(Elt))
15823 Bits = cast<ConstantFPSDNode>(Elt)->getValueAPF().bitcastToAPInt();
15828 if (DAG.getDataLayout().isBigEndian()) {
15829 Bits.
lshrInPlace((Split - SubIdx - 1) * NumSubBits);
15835 Bits = Bits.
trunc(NumSubBits);
15839 else if (Bits == 0)
15851 SDValue Zero = DAG.getConstant(0, DL, ClearVT);
15852 return DAG.getBitcast(VT, DAG.getVectorShuffle(ClearVT, DL,
15853 DAG.getBitcast(ClearVT, LHS),
15862 for (
int Split = 1; Split <= MaxSplit; ++
Split)
15864 if (
SDValue S = BuildClearMask(Split))
15873 "SimplifyVBinOp only works on vectors!");
15880 if (
SDValue Fold = DAG.FoldConstantVectorArithmetic(
15885 if (
SDValue Shuffle = XformToShuffleWithZero(N))
15891 if (LegalTypes && isa<ShuffleVectorSDNode>(LHS) &&
15892 isa<ShuffleVectorSDNode>(RHS) && LHS.hasOneUse() && RHS.
hasOneUse() &&
15893 LHS.getOperand(1).isUndef() &&
15898 if (SVN0->
getMask().equals(SVN1->getMask())) {
15904 AddUsersToWorklist(N);
15905 return DAG.getVectorShuffle(VT,
SDLoc(N), NewBinOp, UndefVector,
15918 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
15923 if (SCC.getNode()) {
15929 SCC.getOperand(0), SCC.getOperand(1),
15930 SCC.getOperand(4));
15931 AddToWorklist(SETCC.
getNode());
15932 return DAG.getSelect(
SDLoc(SCC), SCC.getValueType(),
SETCC,
15933 SCC.getOperand(2), SCC.getOperand(3));
15946 bool DAGCombiner::SimplifySelectOps(
SDNode *TheSelect,
SDValue LHS,
15972 if (Zero && Zero->
isZero() &&
15976 CombineTo(TheSelect, Sqrt);
16004 LLD->
isIndexed() || RLD->isIndexed() ||
16018 RLD->getPointerInfo().getAddrSpace() != 0 ||
16030 (RLD->hasAnyUseOfValue(1) && RLD->isPredecessorOf(CondNode)))
16034 RLD->isPredecessorOf(LLD))
16036 Addr = DAG.getSelect(
SDLoc(TheSelect),
16039 RLD->getBasePtr());
16046 (RLD->hasAnyUseOfValue(1) &&
16047 (RLD->isPredecessorOf(CondLHS) || RLD->isPredecessorOf(CondRHS))))
16064 if (!RLD->isInvariant())
16066 if (!RLD->isDereferenceable())
16075 Load = DAG.getExtLoad(
16083 CombineTo(TheSelect, Load);
16130 if (N2C && ((N2C->getAPIntValue() & (N2C->getAPIntValue() - 1)) == 0)) {
16131 unsigned ShCt = XType.
getSizeInBits() - N2C->getAPIntValue().logBase2() - 1;
16132 SDValue ShiftAmt = DAG.getConstant(ShCt, DL, ShiftAmtTy);
16134 AddToWorklist(Shift.
getNode());
16136 if (XType.
bitsGT(AType)) {
16138 AddToWorklist(Shift.
getNode());
16142 Shift = DAG.getNOT(DL, Shift, AType);
16149 AddToWorklist(Shift.
getNode());
16151 if (XType.
bitsGT(AType)) {
16153 AddToWorklist(Shift.
getNode());
16157 Shift = DAG.getNOT(DL, Shift, AType);
16166 bool NotExtCompare) {
16168 if (N2 == N3)
return N2;
16176 N0, N1, CC, DL,
false);
16177 if (SCC.getNode()) AddToWorklist(SCC.getNode());
16179 if (
ConstantSDNode *SCCC = dyn_cast_or_null<ConstantSDNode>(SCC.getNode())) {
16182 return !SCCC->isNullValue() ? N2 : N3;
16198 N2.getOperand(0) == N3)
16199 return DAG.getNode(
ISD::FABS, DL, VT, N3);
16216 !TLI.
isFPImmLegal(TV->getValueAPF(), TV->getValueType(0)) &&
16217 !TLI.
isFPImmLegal(FV->getValueAPF(), FV->getValueType(0))) &&
16220 (TV->hasOneUse() || FV->hasOneUse())) {
16221 Constant *Elts[] = {
16222 const_cast<ConstantFP*
>(FV->getConstantFPValue()),
16223 const_cast<ConstantFP*>(TV->getConstantFPValue())
16231 DAG.getConstantPool(CA, TLI.
getPointerTy(DAG.getDataLayout()),
16233 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->
getAlignment();
16237 SDValue Zero = DAG.getIntPtrConstant(0, DL);
16239 SDValue One = DAG.getIntPtrConstant(EltSize,
SDLoc(FV));
16241 SDValue Cond = DAG.getSetCC(DL,
16244 AddToWorklist(Cond.
getNode());
16247 AddToWorklist(CstOffset.getNode());
16250 AddToWorklist(CPIdx.getNode());
16251 return DAG.getLoad(
16252 TV->getValueType(0),
DL, DAG.getEntryNode(), CPIdx,
16258 if (
SDValue V = foldSelectCCToShiftAnd(DL, N0, N1, N2, N3, CC))
16286 return DAG.getNode(
ISD::AND, DL, VT, Shr, N3);
16291 if (N2C &&
isNullConstant(N3) && N2C->getAPIntValue().isPowerOf2() &&
16297 if (NotExtCompare && N2C->isOne())
16302 if (!LegalOperations ||
16310 Temp = DAG.getZeroExtendInReg(SCC,
SDLoc(N2),
16311 N2.getValueType());
16314 N2.getValueType(), SCC);
16318 N2.getValueType(), SCC);
16321 AddToWorklist(SCC.
getNode());
16322 AddToWorklist(Temp.
getNode());
16329 ISD::SHL, DL, N2.getValueType(), Temp,
16330 DAG.getConstant(N2C->getAPIntValue().logBase2(),
SDLoc(Temp),
16346 SubC = dyn_cast<ConstantSDNode>(N3.
getOperand(0));
16350 SubC = dyn_cast<ConstantSDNode>(N2.getOperand(0));
16352 EVT XType = N0.getValueType();
16361 AddToWorklist(Shift.
getNode());
16362 AddToWorklist(Add.
getNode());
16363 return DAG.getNode(
ISD::XOR, DL, XType, Add, Shift);
16379 if (CC == ISD::SETNE)
16382 if (
auto *ValueOnZeroC = dyn_cast<ConstantSDNode>(ValueOnZero)) {
16390 return DAG.getNode(
ISD::CTTZ, DL, VT, N0);
16397 return DAG.getNode(
ISD::CTLZ, DL, VT, N0);
16408 bool foldBooleans) {
16410 DagCombineInfo(DAG,
Level,
false,
this);
16411 return TLI.
SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL);
16421 if (DAG.getMachineFunction().getFunction()->optForMinSize())
16432 std::vector<SDNode*> Built;
16452 std::vector<SDNode *> Built;
16467 if (DAG.getMachineFunction().getFunction()->optForMinSize())
16478 std::vector<SDNode*> Built;
16493 SDValue Base = DAG.getConstant(EltBits - 1, DL, VT);
16516 if (Enabled == TLI.ReciprocalEstimate::Disabled)
16523 AddToWorklist(Est.getNode());
16528 SDValue FPOne = DAG.getConstantFP(1.0, DL, VT);
16531 for (
int i = 0; i < Iterations; ++i) {
16533 AddToWorklist(NewEst.
getNode());
16536 AddToWorklist(NewEst.getNode());
16538 NewEst = DAG.getNode(
ISD::FMUL, DL, VT, Est, NewEst, Flags);
16539 AddToWorklist(NewEst.getNode());
16541 Est = DAG.getNode(
ISD::FADD, DL, VT, Est, NewEst, Flags);
16542 AddToWorklist(Est.getNode());
16558 unsigned Iterations,
16562 SDValue ThreeHalves = DAG.getConstantFP(1.5, DL, VT);
16567 AddToWorklist(HalfArg.
getNode());
16570 AddToWorklist(HalfArg.getNode());
16573 for (
unsigned i = 0; i < Iterations; ++i) {
16575 AddToWorklist(NewEst.
getNode());
16578 AddToWorklist(NewEst.getNode());
16580 NewEst = DAG.getNode(
ISD::FSUB, DL, VT, ThreeHalves, NewEst, Flags);
16581 AddToWorklist(NewEst.getNode());
16584 AddToWorklist(Est.getNode());
16589 Est = DAG.getNode(
ISD::FMUL, DL, VT, Est, Arg, Flags);
16590 AddToWorklist(Est.getNode());
16602 unsigned Iterations,
16606 SDValue MinusThree = DAG.getConstantFP(-3.0, DL, VT);
16607 SDValue MinusHalf = DAG.getConstantFP(-0.5, DL, VT);
16615 for (
unsigned i = 0; i < Iterations; ++i) {
16620 AddToWorklist(AEE.getNode());
16623 AddToWorklist(RHS.getNode());
16629 if (Reciprocal || (i + 1) < Iterations) {
16634 LHS = DAG.getNode(
ISD::FMUL, DL, VT, AE, MinusHalf, Flags);
16636 AddToWorklist(LHS.getNode());
16639 AddToWorklist(Est.getNode());
16661 if (Enabled == TLI.ReciprocalEstimate::Disabled)
16668 bool UseOneConstNR =
false;
16672 AddToWorklist(Est.getNode());
16675 Est = UseOneConstNR
16676 ? buildSqrtNROneConst(Op, Est, Iterations, Flags, Reciprocal)
16677 : buildSqrtNRTwoConst(Op, Est, Iterations, Flags, Reciprocal);
16685 SDValue FPZero = DAG.getConstantFP(0.0, DL, VT);
16688 AddToWorklist(ZeroCmp.
getNode());
16691 ZeroCmp, FPZero, Est);
16692 AddToWorklist(Est.getNode());
16702 return buildSqrtEstimateImpl(Op, Flags,
true);
16706 return buildSqrtEstimateImpl(Op, Flags,
false);
16714 Base =
Ptr; Offset = 0; GV =
nullptr; CV =
nullptr;
16728 GV =
G->getGlobal();
16729 Offset +=
G->getOffset();
16737 CV = C->isMachineConstantPoolEntry() ? (
const void *)C->getMachineCPVal()
16738 : (
const void *)C->getConstVal();
16739 Offset += C->getOffset();
16743 return isa<FrameIndexSDNode>(Base);
16771 return !((NumBytes0 <= PtrDiff) || (PtrDiff + NumBytes1 <= 0));
16777 if (
auto *A = dyn_cast<FrameIndexSDNode>(BasePtr0.
getBase()))
16778 if (
auto *B = dyn_cast<FrameIndexSDNode>(BasePtr1.getBase())) {
16792 int64_t Offset0, Offset1;
16794 const void *CV0, *CV1;
16796 Base0, Offset0, GV0, CV0);
16798 Base1, Offset1, GV1, CV1);
16801 if (Base0 == Base1 || (GV0 && (GV0 == GV1)) || (CV0 && (CV0 == CV1)))
16802 return !((Offset0 + NumBytes0) <= Offset1 ||
16803 (Offset1 + NumBytes1) <= Offset0);
16809 if (IsFrameIndex0 && IsFrameIndex1) {
16811 Offset0 += MFI.
getObjectOffset(cast<FrameIndexSDNode>(Base0)->getIndex());
16812 Offset1 += MFI.
getObjectOffset(cast<FrameIndexSDNode>(Base1)->getIndex());
16813 return !((Offset0 + NumBytes0) <= Offset1 ||
16814 (Offset1 + NumBytes1) <= Offset0);
16819 if ((IsFrameIndex0 || CV0 || GV0) && (IsFrameIndex1 || CV1 || GV1))
16830 if (OrigAlignment0 == OrigAlignment1 && SrcValOffset0 != SrcValOffset1 &&
16831 NumBytes0 == NumBytes1 && OrigAlignment0 > NumBytes0) {
16832 int64_t OffAlign0 = SrcValOffset0 % OrigAlignment0;
16833 int64_t OffAlign1 = SrcValOffset1 % OrigAlignment1;
16837 if ((OffAlign0 + NumBytes0) <= OffAlign1 ||
16838 (OffAlign1 + NumBytes1) <= OffAlign0)
16842 bool UseAA = CombinerGlobalAA.getNumOccurrences() > 0
16844 : DAG.getSubtarget().useAA();
16846 if (CombinerAAOnlyFunc.getNumOccurrences() &&
16847 CombinerAAOnlyFunc != DAG.getMachineFunction().getName())
16854 int64_t MinOffset =
std::min(SrcValOffset0, SrcValOffset1);
16855 int64_t Overlap0 = NumBytes0 + SrcValOffset0 - MinOffset;
16856 int64_t Overlap1 = NumBytes1 + SrcValOffset1 - MinOffset;
16872 void DAGCombiner::GatherAllAliases(
SDNode *N,
SDValue OriginalChain,
16878 bool IsLoad = isa<LoadSDNode>(
N) && !cast<LSBaseSDNode>(N)->isVolatile();
16882 unsigned Depth = 0;
16887 while (!Chains.
empty()) {
16914 bool IsOpLoad = isa<LoadSDNode>(Chain.
getNode()) &&
16918 if (!(IsLoad && IsOpLoad) &&
16919 isAlias(cast<LSBaseSDNode>(N), cast<LSBaseSDNode>(Chain.
getNode()))) {
16963 GatherAllAliases(N, OldChain, Aliases);
16966 if (Aliases.
size() == 0)
16967 return DAG.getEntryNode();
16970 if (Aliases.
size() == 1)
16989 bool DAGCombiner::findBetterNeighborChains(
StoreSDNode *St) {
17011 if (Index != St && !
SDValue(Index, 0)->hasOneUse())
17028 if (
StoreSDNode *STn = dyn_cast<StoreSDNode>(NextInChain)) {
17030 if (STn->isVolatile() || STn->isIndexed()) {
17037 }
else if (
LoadSDNode *Ldn = dyn_cast<LoadSDNode>(NextInChain)) {
17038 NextInChain = Ldn->getChain().getNode();
17052 bool MadeChangeToSt =
false;
17055 for (
StoreSDNode *ChainedStore : ChainedStores) {
17056 SDValue Chain = ChainedStore->getChain();
17057 SDValue BetterChain = FindBetterChain(ChainedStore, Chain);
17059 if (Chain != BetterChain) {
17060 if (ChainedStore == St)
17061 MadeChangeToSt =
true;
17062 BetterChains.
push_back(std::make_pair(ChainedStore, BetterChain));
17068 for (
auto Replacement : BetterChains)
17069 replaceStoreChain(Replacement.first, Replacement.second);
17071 return MadeChangeToSt;
17078 DAGCombiner(*
this, AA, OptLevel).Run(Level);
virtual bool enableAggressiveFMAFusion(EVT VT) const
Return true if target always beneficiates from combining into FMA for a given value type...
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
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.
virtual bool hasBitPreservingFPLogic(EVT VT) const
Return true if it is safe to transform an integer-domain bitwise operation into the equivalent floati...
bool hasNoUnsignedWrap() const
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 ...
unsigned getValueSizeInBits(unsigned ResNo) const
Returns MVT::getSizeInBits(getValueType(ResNo)).
bool use_empty() const
Return true if there are no uses of this node.
static MVT getIntegerVT(unsigned BitWidth)
std::string & operator+=(std::string &buffer, StringRef string)
void push_back(const T &Elt)
BUILTIN_OP_END - This must be the last enum value in this list.
bool hasAllowContract() const
A parsed version of the target data layout string in and methods for querying it. ...
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
SDValue getValue(unsigned R) const
const SDValue & getValue() const
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 bool findBaseOffset(SDValue Ptr, SDValue &Base, int64_t &Offset, const GlobalValue *&GV, const void *&CV)
Return true if base is a frame index, which is known not to alias with anything but itself...
bool isTruncatingStore() const
Return true if the op does a truncation before store.
static bool isConstant(const MachineInstr &MI)
bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
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...
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
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.
bool hasNoSignedZeros() const
static bool areSlicesNextToEachOther(const LoadedSlice &First, const LoadedSlice &Second)
Check whether or not First and Second are next to each other in memory.
Flags getFlags() const
Return the raw flags of the source value,.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVMContext * getContext() const
bool isBuildVectorOfConstantSDNodes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR node of all ConstantSDNode or undef...
uint64_t getZExtValue() const
Get zero extended value.
DiagnosticInfoOptimizationBase::Argument NV
typename SuperClass::const_iterator const_iterator
SDValue CombineTo(SDNode *N, ArrayRef< SDValue > To, bool AddTo=true)
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
DELETED_NODE - This is an illegal value that is used to catch errors.
STATISTIC(NumFunctions,"Total number of functions")
LLVM_NODISCARD T pop_back_val()
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
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 ...
BR_CC - Conditional branch.
bool isNON_TRUNCStore(const SDNode *N)
Returns true if the specified node is a non-truncating store.
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...
bool hasOneUse() const
Return true if there is exactly one use of this node.
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 hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
bool isOneValue() const
Determine if this is a value of 1.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
SDVTList getVTList() const
static SDValue simplifyDivRem(SDNode *N, SelectionDAG &DAG)
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static uint64_t * getMemory(unsigned numWords)
A utility function for allocating memory and checking for allocation failure.
int getSplatIndex() const
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode * > &Visited, SmallVectorImpl< const SDNode * > &Worklist, unsigned int MaxSteps=0)
Returns true if N is a predecessor of any node in Worklist.
Carry-setting nodes for multiple precision addition and subtraction.
bool isConstTrueVal(const SDNode *N) const
Return if the N is a constant or constant vector equal to the true value from getBooleanContents().
static bool isTruncateOf(SelectionDAG &DAG, SDValue N, SDValue &Op, KnownBits &Known)
const TargetMachine & getTarget() const
static SDValue combineShuffleOfScalars(ShuffleVectorSDNode *SVN, SelectionDAG &DAG, const TargetLowering &TLI)
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
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...
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...
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool operator>(int64_t V1, const APSInt &V2)
static SDValue simplifyShuffleOperandRecursively(SmallBitVector &UsedElements, SDValue V, SelectionDAG &DAG)
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...
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.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
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...
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
const SDValue & getSrc0() const
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...
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
unsigned getSizeInBits() const
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
static const fltSemantics & EVTToAPFloatSemantics(EVT VT)
Returns an APFloat semantics tag appropriate for the given type.
unsigned getNumOperands() const
Return the number of values used by this 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...
void setAllBits()
Set every bit to 1.
unsigned getNumOperands() const
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
The two locations do not alias at all.
const SDValue & getOperand(unsigned Num) const
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned EltSize)
virtual bool isStoreBitCastBeneficial(EVT StoreVT, EVT BitcastVT) const
Return true if the following transform is beneficial: (store (y (conv x)), y*)) -> (store x...
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 isFPExtFree(EVT VT) const
Return true if an fpext operation is free (for instance, because single-precision floating-point numb...
void reserve(size_type N)
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...
const SDValue & getBasePtr() const
static SDValue combineTruncationShuffle(ShuffleVectorSDNode *SVN, SelectionDAG &DAG)
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
SDValue BuildUDIV(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, bool IsAfterLegalization, std::vector< SDNode * > *Created) const
Given an ISD::UDIV node expressing a divide by constant, return a DAG expression to select that will ...
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 bool isFPImmLegal(const APFloat &, EVT) const
Returns true if the target can instruction select the specified FP immediate natively.
size_type size() const
Determine the number of elements in the SetVector.
EntryToken - This is the marker used to indicate the start of a region.
virtual bool canMergeStoresTo(unsigned AS, EVT MemVT, const SelectionDAG &DAG) const
Returns if it's reasonable to merge stores to MemVT size.
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...
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
SDValue getConstTrueVal(SelectionDAG &DAG, EVT VT, const SDLoc &DL) const
Return a constant of type VT that contains a true value that respects getBooleanContents() ...
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isUndef() const
Return true if the type of the node type undefined.
int64_t getSrcValueOffset() const
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
bool isAllOnesValue() const
bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
const APInt & getConstant() const
Returns the value when all bits have a known value.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
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...
bool operator<=(int64_t V1, const APSInt &V2)
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 isNegative() const
Determine sign of this APInt.
bool isVector() const
Return true if this is a vector value type.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
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)
static bool isContractable(SDNode *N)
A description of a memory reference used in the backend.
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.
bool isRound() const
Return true if the size is a power-of-two number of bytes.
static ManagedStatic< DebugCounter > DC
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.
bool equalBaseIndex(BaseIndexOffset &Other, const SelectionDAG &DAG)
Shift and rotation operations.
virtual bool isLegalAddImmediate(int64_t) const
Return true if the specified immediate is legal add immediate, that is the target has add instruction...
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
virtual SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps) const
Return a reciprocal estimate value for the input operand.
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)
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...
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
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.
MachineFunction & getMachineFunction() const
bool HonorSignDependentRoundingFPMath() const
HonorSignDependentRoundingFPMath - Return true if the codegen must assume that the rounding mode of t...
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...
CopyToReg - This node has three operands: a chain, a register number to set to this value...
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
MachinePointerInfo getWithOffset(int64_t O) const
APInt bitcastToAPInt() const
The memory access is dereferenceable (i.e., doesn't trap).
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
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...
bool isMask(unsigned numBits) const
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
int getMaskElt(unsigned Idx) const
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...
zlib-gnu style compression
bool isInteger() const
Return true if this is an integer or a vector integer type.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
LLVM_NODISCARD bool empty() const
bool getBoolValue() const
Convert APInt to a boolean value.
This class is used to represent an MSTORE node.
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 getVectorElementType() const
Given a vector type, return the type of each element.
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 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...
static bool isSimple(Instruction *I)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
bool isConstantSplatVector(const SDNode *N, APInt &SplatValue, bool AllowShrink=true)
Node predicates.
virtual bool isDesirableToCombineBuildVectorToTruncate() 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.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
static bool isAnyConstantBuildVector(const SDNode *N)
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.
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Simple integer binary arithmetic operators.
bool empty() const
Determine if the SetVector is empty or not.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool isLittleEndian() const
Layout endianness...
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
const SDValue & getBasePtr() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
const APInt & getAPIntValue() const
virtual bool generateFMAsInMachineCombiner(CodeGenOpt::Level OptLevel) const
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
virtual bool isDesirableToTransformToIntegerOp(unsigned, EVT) const
Return true if it is profitable for dag combiner to transform a floating point op of specified opcode...
EVT getMemoryVT() const
Return the type of the in-memory value.
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
unsigned getBitWidth() const
Get the bit width of this value.
const ConstantInt * getConstantIntValue() const
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal or custom on this target.
virtual bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT) const
size_t size() const
size - Get the array size.
const DataLayout & getDataLayout() const
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
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.
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.
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...
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
static bool isFMulNegTwo(SDValue &N)
SDNode * getNode() const
get the SDNode which holds the desired result
virtual bool mergeStoresAfterLegalization() const
Should we merge stores after Legalization (generally better quality) or before (simpler) ...
bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const
Return true if the specified store with truncation is legal on this target.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Function Alias Analysis false
bool hasPredecessor(const SDNode *N) const
Return true if N is a predecessor of this node.
virtual SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, std::vector< SDNode * > *Created) const
Targets may override this function to provide custom SDIV lowering for power-of-2 denominators...
unsigned getScalarSizeInBits() const
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
static bool ExtendUsesToFormExtLoad(SDNode *N, SDValue N0, unsigned ExtOpc, SmallVectorImpl< SDNode * > &ExtendNodes, const TargetLowering &TLI)
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
initializer< Ty > init(const Ty &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 ...
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
virtual bool isShuffleMaskLegal(const SmallVectorImpl< int > &, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
const SDValue & getBasePtr() const
bool isZero() const
Return true if the value is positive or negative zero.
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...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
APInt trunc(unsigned width) const
Truncate to new width.
size_t use_size() const
Return the number of uses of this node.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static SDValue combineConcatVectorOfExtracts(SDNode *N, SelectionDAG &DAG)
static SDValue ConvertSelectToConcatVector(SDNode *N, SelectionDAG &DAG)
const SDValue & getOperand(unsigned i) const
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.
bool isCompressingStore() const
Returns true if the op does a compression to the vector before storing.
Simple binary floating point operators.
bool isNonTemporal() const
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...
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
This is an important base class in LLVM.
const SDNodeFlags getFlags() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
int64_t getSExtValue() const
Get sign extended value.
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...
Carry-using nodes for multiple precision addition and subtraction.
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
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.
virtual bool isDesirableToCommuteWithShift(const SDNode *N) const
Return true if it is profitable to move a following shift through this.
unsigned getScalarValueSizeInBits() const
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
Split the node's operand with EXTRACT_SUBVECTOR and return the low/high part.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
void AddToWorklist(SDNode *N)
APInt sext(unsigned width) const
Sign extend to a new width.
AliasResult
The possible results of an alias query.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
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 class provides iterator support for SDUse operands that use a specific SDNode.
unsigned getOriginalAlignment() const
Returns alignment and volatility of the memory access.
bool hasAllowReciprocal() const
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
virtual bool isFMAFasterThanFMulAndFAdd(EVT) const
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
virtual bool aggressivelyPreferBuildVectorSources(EVT VecVT) const
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
unsigned getOpcode() const
static bool sumMatchConstant(SDValue Left, SDValue Right, unsigned Sum, SelectionDAG &DAG, const SDLoc &DL)
const SDValue & getBasePtr() const
virtual bool isNarrowingProfitable(EVT, EVT) const
Return true if it's profitable to narrow operations of type VT1 to VT2.
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
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...
CondCode getSetCCSwappedOperands(CondCode Operation)
Return the operation corresponding to (Y op X) when given the operation for (X op Y)...
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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.
const SDValue & getValue() const
ConstantSDNode * isConstOrConstSplat(SDValue V)
Returns the SDNode if it is a constant splat BuildVector or constant int.
Bit counting operators with an undefined result for zero inputs.
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
SDValue BuildSDIV(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, bool IsAfterLegalization, std::vector< SDNode * > *Created) const
Given an ISD::SDIV node expressing a divide by constant, return a DAG expression to select that will ...
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
iterator erase(const_iterator CI)
const SDValue & getMask() const
const APFloat & getValueAPF() const
const ConstantFP * getConstantFPValue() const
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
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...
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...
virtual bool isVectorLoadExtDesirable(SDValue ExtVal) const
Return true if folding a vector load into ExtVal (a sign, zero, or any extend node) is profitable...
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return true if the specified load with extension is legal on this target.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
This class contains a discriminated union of information about pointers in memory operands...
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
HANDLENODE node - Used as a handle for various purposes.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
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...
static SDValue getAsCarry(const TargetLowering &TLI, SDValue V)
bool isEXTLoad(const SDNode *N)
Returns true if the specified node is a EXTLOAD.
const MachinePointerInfo & getPointerInfo() const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
bool isUNINDEXEDLoad(const SDNode *N)
Returns true if the specified node is an unindexed load.
The memory access writes data.
const SDValue & getOffset() const
static SDValue combineShuffleOfSplat(ArrayRef< int > UserMask, ShuffleVectorSDNode *Splat, SelectionDAG &DAG)
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
ArrayRef< int > getMask() const
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type...
Representation for a specific memory location.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
TokenFactor - This node takes multiple tokens as input and produces a single token result...
bool isBuildVectorAllOnes(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are ~0 or undef...
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...
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...
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.
void setNoUnsignedWrap(bool b)
static SDValue combineShuffleToVectorExtend(ShuffleVectorSDNode *SVN, SelectionDAG &DAG, const TargetLowering &TLI, bool LegalOperations)
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)
void dump() const
Dump this node, for debugging.
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
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.
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
virtual bool isVectorClearMaskLegal(const SmallVectorImpl< int > &, EVT) const
Similar to isShuffleMaskLegal.
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...
unsigned logBase2() const
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
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.
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
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...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
BRCOND - Conditional branch.
const SDValue & getChain() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Byte Swap and Counting operators.
APFloat neg(APFloat X)
Returns the negated value of the argument.
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
LLVM_NODISCARD T pop_back_val()
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
bool hasNoSignedWrap() const
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.
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
static BaseIndexOffset match(SDValue Ptr, const SelectionDAG &DAG)
Parses tree in Ptr for base, index, offset addresses.
static unsigned int semanticsPrecision(const fltSemantics &)
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...
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
static bool isOneConstantOrOneSplatConstant(SDValue N)
static std::pair< SDValue, SDValue > SplitVSETCC(const SDNode *N, SelectionDAG &DAG)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
const SDValue & getValue() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
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...
Class for arbitrary precision integers.
const Value * getValue() const
Return the base address of the memory access.
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.
iterator_range< use_iterator > uses()
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).
int64_t getSExtValue() const
op_iterator op_begin() const
static SDValue simplifyShuffleOperands(ShuffleVectorSDNode *SVN, SDValue N0, SDValue N1, SelectionDAG &DAG)
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
Return the register class that should be used for the specified value type.
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 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 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.
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.
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.
iterator_range< value_op_iterator > op_values() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
llvm_unreachable("Unknown RegBank!")
unsigned getAddressSpace() const
Return the address space for the associated pointer.
const SDValue & getMask() const
The memory access reads data.
virtual bool isLoadBitCastBeneficial(EVT LoadVT, EVT BitcastVT) const
Return true if the following transform is beneficial: fold (conv (load x)) -> (load (conv*)x) On archi...
static std::vector< std::string > Flags
bool operator!=(uint64_t V1, const APInt &V2)
static mvt_range all_valuetypes()
SimpleValueType Iteration.
bool isAllOnesValue() const
Determine if all bits are set.
ConstantFPSDNode * isConstOrConstSplatFP(SDValue V)
Returns the SDNode if it is a constant splat BuildVector or constant float.
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()
uint64_t getConstantOperandVal(unsigned i) const
Bitwise operators - logical and, logical or, logical xor.
static cl::opt< bool > UseTBAA("use-tbaa-in-sched-mi", cl::Hidden, cl::init(true), cl::desc("Enable use of TBAA during MI DAG construction"))
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
virtual bool isFsqrtCheap(SDValue X, SelectionDAG &DAG) const
Return true if SQRT(X) shouldn't be replaced with X*RSQRT(X).
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
virtual bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AddrSpace) const
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
static SDValue tryFoldToZero(const SDLoc &DL, const TargetLowering &TLI, EVT VT, SelectionDAG &DAG, bool LegalOperations, bool LegalTypes)
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
ArrayRef< SDUse > ops() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
The memory access always returns the same value (or traps).
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.
op_iterator op_end() const
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)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
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...
bool isExpandingLoad() const
static SDValue getInputChainForNode(SDNode *N)
Given a node, return its input chain if it has one, otherwise return a null sd operand.
bool hasUnsafeAlgebra() const
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
virtual bool isExtractSubvectorCheap(EVT ResVT, unsigned Index) const
Return true if EXTRACT_SUBVECTOR is cheap for this result type with this index.
This class is used to represent an MSCATTER node.
const SDValue & getIndex() const
static MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
Like SetCC, ops #0 and #1 are the LHS and RHS operands to compare, and op #2 is a carry value...
virtual bool convertSelectOfConstantsToMath() const
Return true if a select of constants (select Cond, C1, C2) should be transformed into simple math ops...
void setUnsafeAlgebra(bool b)
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
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...
bool isByteSized() const
Return true if the bit size is a multiple of 8.
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
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())
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
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 represent an MLOAD node.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
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...
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...
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
LLVM Value Representation.
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.
const SDValue & getBasePtr() const
A vector that has set insertion semantics.
static bool isShift(MachineInstr *MI, unsigned Opcode, int64_t Imm)
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.
bool isTruncatingStore() const
Return true if the op does a truncation before store.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This class is used to represent an MGATHER node.
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.
const TargetLowering & getTargetLoweringInfo() const
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
unsigned NoSignedZerosFPMath
NoSignedZerosFPMath - This flag is enabled when the -enable-no-signed-zeros-fp-math is specified on t...
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations...
APInt zext(unsigned width) const
Zero extend to a new width.
SetCC operator - This evaluates to a true value iff the condition is true.
bool isNullValue() const
Determine if all bits are clear.
static SDNode * isConstantFPBuildVectorOrConstantFP(SDValue N)
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
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)
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
static bool isVolatile(Instruction *Inst)
static APInt getNullValue(unsigned numBits)
Get the '0' value.
SDNode * getUser()
This returns the SDNode that contains this Use.
TRUNCATE - Completely drop the high bits.
EVT getShiftAmountTy(EVT LHSTy, const DataLayout &DL) const
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
unsigned getAlignment() const
bool isCondCodeLegal(ISD::CondCode CC, MVT VT) const
Return true if the specified condition code is legal on this target.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
virtual unsigned combineRepeatedFPDivisors() const
Indicate whether this target prefers to combine FDIVs with the same divisor.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
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...
unsigned getGatherAllAliasesMaxDepth() const
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.
const fltSemantics & getSemantics() const
virtual bool hasPairedLoad(EVT, unsigned &) const
Return true if the target supplies and combines to a paired load two loaded values of type LoadedType...
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
unsigned getResNo() const
Convenience function for get().getResNo().
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Carry-using nodes for multiple precision addition and subtraction.
CARRY_FALSE - This node is used when folding other nodes, like ADDC/SUBC, which indicate the carry re...
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...
This file describes how to lower LLVM code to machine code.
void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO)
uint64_t getBaseAlignment() const
Return the minimum known alignment in bytes of the base address, without the offset.
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...
ISD::CondCode get() const
uint64_t getZExtValue() const
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...
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
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.