84#define DEBUG_TYPE "dagcombine"
86STATISTIC(NodesCombined ,
"Number of dag nodes combined");
87STATISTIC(PreIndexedNodes ,
"Number of pre-indexed nodes created");
88STATISTIC(PostIndexedNodes,
"Number of post-indexed nodes created");
89STATISTIC(OpsNarrowed ,
"Number of load/op/store narrowed");
90STATISTIC(LdStFP2Int ,
"Number of fp load/store pairs transformed to int");
92STATISTIC(NumFPLogicOpsConv,
"Number of logic ops converted to fp ops");
95 "Controls whether a DAG combine is performed for a node");
99 cl::desc(
"Enable DAG combiner's use of IR alias analysis"));
103 cl::desc(
"Enable DAG combiner's use of TBAA"));
108 cl::desc(
"Only use DAG-combiner alias analysis in this"
116 cl::desc(
"Bypass the profitability model of load slicing"),
121 cl::desc(
"DAG combiner may split indexing from loads"));
125 cl::desc(
"DAG combiner enable merging multiple stores "
126 "into a wider store"));
130 cl::desc(
"Limit the number of operands to inline for Token Factors"));
134 cl::desc(
"Limit the number of times for the same StoreNode and RootNode "
135 "to bail out in store merging dependence check"));
139 cl::desc(
"DAG combiner enable reducing the width of load/op/store "
142 "combiner-reduce-load-op-store-width-force-narrowing-profitable",
144 cl::desc(
"DAG combiner force override the narrowing profitable check when"
145 "reducing the width of load/op/store sequences"));
149 cl::desc(
"DAG combiner enable load/<replace bytes>/store with "
150 "a narrower store"));
155 "Enable merging extends and rounds into FCOPYSIGN on vector types"));
164 bool LegalDAG =
false;
165 bool LegalOperations =
false;
166 bool LegalTypes =
false;
168 bool DisableGenericCombines;
204 void AddUsersToWorklist(
SDNode *
N) {
210 void AddToWorklistWithUsers(
SDNode *
N) {
211 AddUsersToWorklist(
N);
218 void clearAddedDanglingWorklistEntries() {
220 while (!PruningList.
empty()) {
223 recursivelyDeleteUnusedNodes(
N);
227 SDNode *getNextWorklistEntry() {
229 clearAddedDanglingWorklistEntries();
233 while (!
N && !Worklist.
empty()) {
238 assert(
N->getCombinerWorklistIndex() >= 0 &&
239 "Found a worklist entry without a corresponding map entry!");
241 N->setCombinerWorklistIndex(-2);
251 : DAG(
D), TLI(
D.getTargetLoweringInfo()),
252 STI(
D.getSubtarget().getSelectionDAGInfo()), OptLevel(OL), AA(AA) {
256 MaximumLegalStoreInBits = 0;
262 VT.getSizeInBits().getKnownMinValue() >= MaximumLegalStoreInBits)
263 MaximumLegalStoreInBits = VT.getSizeInBits().getKnownMinValue();
266 void ConsiderForPruning(
SDNode *
N) {
273 void AddToWorklist(
SDNode *
N,
bool IsCandidateForPruning =
true,
274 bool SkipIfCombinedBefore =
false) {
276 "Deleted Node added to Worklist");
283 if (SkipIfCombinedBefore &&
N->getCombinerWorklistIndex() == -2)
286 if (IsCandidateForPruning)
287 ConsiderForPruning(
N);
289 if (
N->getCombinerWorklistIndex() < 0) {
290 N->setCombinerWorklistIndex(Worklist.
size());
296 void removeFromWorklist(
SDNode *
N) {
298 StoreRootCountMap.
erase(
N);
300 int WorklistIndex =
N->getCombinerWorklistIndex();
304 if (WorklistIndex < 0)
308 Worklist[WorklistIndex] =
nullptr;
309 N->setCombinerWorklistIndex(-1);
312 void deleteAndRecombine(
SDNode *
N);
313 bool recursivelyDeleteUnusedNodes(
SDNode *
N);
321 return CombineTo(
N, &Res, 1, AddTo);
328 return CombineTo(
N, To, 2, AddTo);
334 unsigned MaximumLegalStoreInBits;
340 unsigned BitWidth =
Op.getScalarValueSizeInBits();
346 EVT VT =
Op.getValueType();
350 return SimplifyDemandedBits(
Op,
DemandedBits, DemandedElts,
false);
356 bool SimplifyDemandedVectorElts(
SDValue Op) {
358 if (
Op.getValueType().isScalableVector())
361 unsigned NumElts =
Op.getValueType().getVectorNumElements();
363 return SimplifyDemandedVectorElts(
Op, DemandedElts);
367 const APInt &DemandedElts,
368 bool AssumeSingleUse =
false);
369 bool SimplifyDemandedVectorElts(
SDValue Op,
const APInt &DemandedElts,
370 bool AssumeSingleUse =
false);
372 bool CombineToPreIndexedLoadStore(
SDNode *
N);
373 bool CombineToPostIndexedLoadStore(
SDNode *
N);
398 void ReplaceLoadWithPromotedLoad(
SDNode *Load,
SDNode *ExtLoad);
539 bool refineExtractVectorEltIntoMultipleNarrowExtractVectorElts(
SDNode *
N);
571 template <
class MatchContextClass>
573 template <
class MatchContextClass>
578 bool reassociationCanBreakAddressingModePattern(
unsigned Opc,
587 SDValue reassociateReduction(
unsigned RedOpc,
unsigned Opc,
const SDLoc &
DL,
601 bool NotExtCompare =
false);
602 SDValue convertSelectOfFPConstantsToLoadOffset(
619 const SDLoc &
DL,
bool foldBooleans);
623 SDValue &
CC,
bool MatchStrict =
false)
const;
624 bool isOneUseSetCC(
SDValue N)
const;
649 bool KnownNeverZero =
false,
650 bool InexpensiveOnly =
false,
651 std::optional<EVT> OutVT = std::nullopt);
661 bool DemandHighBits =
true);
665 unsigned PosOpcode,
unsigned NegOpcode,
669 unsigned PosOpcode,
unsigned NegOpcode,
685 SDValue VecIn2,
unsigned LeftIdx,
720 int64_t OffsetFromBase;
723 : MemNode(
N), OffsetFromBase(
Offset) {}
728 StoreSource getStoreSource(
SDValue StoreVal) {
732 return StoreSource::Constant;
736 return StoreSource::Constant;
737 return StoreSource::Unknown;
740 return StoreSource::Extract;
742 return StoreSource::Load;
744 return StoreSource::Unknown;
752 bool isMulAddWithConstProfitable(
SDNode *MulNode,
SDValue AddNode,
759 EVT LoadResultTy,
EVT &ExtVT);
764 EVT &MemVT,
unsigned ShAmt = 0);
772 bool BackwardsPropagateMask(
SDNode *
N);
789 EVT MemVT,
unsigned NumStores,
790 bool IsConstantSrc,
bool UseVector,
803 bool checkMergeStoreCandidatesForDependencies(
811 int64_t ElementSizeBytes)
const;
816 unsigned NumConsecutiveStores,
817 EVT MemVT,
SDNode *Root,
bool AllowVectors);
824 unsigned NumConsecutiveStores,
EVT MemVT,
830 unsigned NumConsecutiveStores,
EVT MemVT,
831 SDNode *Root,
bool AllowVectors,
832 bool IsNonTemporalStore,
bool IsNonTemporalLoad);
851 bool hasOperation(
unsigned Opcode,
EVT VT) {
862 EVT getShiftAmountTy(
EVT LHSTy) {
868 bool isTypeLegal(
const EVT &VT) {
869 if (!LegalTypes)
return true;
874 EVT getSetCCResultType(
EVT VT)
const {
889 explicit WorklistRemover(DAGCombiner &dc)
890 :
SelectionDAG::DAGUpdateListener(dc.getDAG()), DC(dc) {}
893 DC.removeFromWorklist(
N);
901 explicit WorklistInserter(DAGCombiner &dc)
902 :
SelectionDAG::DAGUpdateListener(dc.getDAG()), DC(dc) {}
916 ((DAGCombiner*)
DC)->AddToWorklist(
N);
921 return ((DAGCombiner*)DC)->CombineTo(
N, &To[0], To.
size(), AddTo);
926 return ((DAGCombiner*)DC)->CombineTo(
N, Res, AddTo);
931 return ((DAGCombiner*)DC)->CombineTo(
N, Res0, Res1, AddTo);
936 return ((DAGCombiner*)DC)->recursivelyDeleteUnusedNodes(
N);
941 return ((DAGCombiner*)DC)->CommitTargetLoweringOpt(TLO);
948void DAGCombiner::deleteAndRecombine(
SDNode *
N) {
949 removeFromWorklist(
N);
957 if (
Op->hasOneUse() ||
Op->getNumValues() > 1)
958 AddToWorklist(
Op.getNode());
967 unsigned Bits =
Offset + std::max(
LHS.getBitWidth(),
RHS.getBitWidth());
980 LHS =
N.getOperand(0);
981 RHS =
N.getOperand(1);
982 CC =
N.getOperand(2);
989 LHS =
N.getOperand(1);
990 RHS =
N.getOperand(2);
991 CC =
N.getOperand(3);
1003 LHS =
N.getOperand(0);
1004 RHS =
N.getOperand(1);
1005 CC =
N.getOperand(4);
1012bool DAGCombiner::isOneUseSetCC(
SDValue N)
const {
1014 if (isSetCCEquivalent(
N, N0, N1, N2) &&
N->hasOneUse())
1026 MaskForTy = 0xFFULL;
1029 MaskForTy = 0xFFFFULL;
1032 MaskForTy = 0xFFFFFFFFULL;
1051 return !(Const->isOpaque() && NoOpaques);
1054 unsigned BitWidth =
N.getScalarValueSizeInBits();
1059 if (!Const || Const->getAPIntValue().getBitWidth() !=
BitWidth ||
1060 (Const->isOpaque() && NoOpaques))
1079 !cast<ConstantSDNode>(LD->getOperand(2))->isOpaque());
1082bool DAGCombiner::reassociationCanBreakAddressingModePattern(
unsigned Opc,
1115 ScalableOffset = -ScalableOffset;
1117 if (
auto *LoadStore = dyn_cast<MemSDNode>(
Node);
1123 unsigned AS =
LoadStore->getAddressSpace();
1136 auto *C2 = dyn_cast<ConstantSDNode>(N1);
1140 const APInt &C2APIntVal = C2->getAPIntValue();
1144 if (
auto *C1 = dyn_cast<ConstantSDNode>(N0.
getOperand(1))) {
1148 const APInt &C1APIntVal = C1->getAPIntValue();
1149 const APInt CombinedValueIntVal = C1APIntVal + C2APIntVal;
1152 const int64_t CombinedValue = CombinedValueIntVal.
getSExtValue();
1155 if (
auto *LoadStore = dyn_cast<MemSDNode>(
Node)) {
1161 AM.
BaseOffs = C2APIntVal.getSExtValue();
1163 unsigned AS =
LoadStore->getAddressSpace();
1175 if (
auto *GA = dyn_cast<GlobalAddressSDNode>(N0.
getOperand(1)))
1188 AM.
BaseOffs = C2APIntVal.getSExtValue();
1190 unsigned AS =
LoadStore->getAddressSpace();
1203SDValue DAGCombiner::reassociateOpsCommutative(
unsigned Opc,
const SDLoc &
DL,
1217 Flags.hasNoUnsignedWrap())
1225 return DAG.
getNode(Opc,
DL, VT, N00, OpNode, NewFlags);
1233 return DAG.
getNode(Opc,
DL, VT, OpNode, N01, NewFlags);
1243 if (N1 == N00 || N1 == N01)
1289 if (CC1 == CC00 && CC1 != CC01) {
1291 return DAG.
getNode(Opc,
DL, VT, OpNode, N01, Flags);
1293 if (CC1 == CC01 && CC1 != CC00) {
1295 return DAG.
getNode(Opc,
DL, VT, OpNode, N00, Flags);
1313 if (!
Flags.hasAllowReassociation() || !
Flags.hasNoSignedZeros())
1316 if (
SDValue Combined = reassociateOpsCommutative(Opc,
DL, N0, N1, Flags))
1318 if (
SDValue Combined = reassociateOpsCommutative(Opc,
DL, N1, N0, Flags))
1326SDValue DAGCombiner::reassociateReduction(
unsigned RedOpc,
unsigned Opc,
1344 assert(
N->getNumValues() == NumTo &&
"Broken CombineTo call!");
1348 dbgs() <<
" and " << NumTo - 1 <<
" other values\n");
1349 for (
unsigned i = 0, e = NumTo; i !=
e; ++i)
1351 N->getValueType(i) == To[i].getValueType()) &&
1352 "Cannot combine value to value of different type!");
1354 WorklistRemover DeadNodes(*
this);
1358 for (
unsigned i = 0, e = NumTo; i !=
e; ++i) {
1360 AddToWorklistWithUsers(To[i].
getNode());
1368 deleteAndRecombine(
N);
1386 recursivelyDeleteUnusedNodes(TLO.
Old.
getNode());
1392 const APInt &DemandedElts,
1393 bool AssumeSingleUse) {
1401 AddToWorklist(
Op.getNode());
1403 CommitTargetLoweringOpt(TLO);
1410bool DAGCombiner::SimplifyDemandedVectorElts(
SDValue Op,
1411 const APInt &DemandedElts,
1412 bool AssumeSingleUse) {
1414 APInt KnownUndef, KnownZero;
1416 TLO, 0, AssumeSingleUse))
1420 AddToWorklist(
Op.getNode());
1422 CommitTargetLoweringOpt(TLO);
1426void DAGCombiner::ReplaceLoadWithPromotedLoad(
SDNode *Load,
SDNode *ExtLoad) {
1428 EVT VT =
Load->getValueType(0);
1437 AddToWorklist(Trunc.
getNode());
1438 recursivelyDeleteUnusedNodes(Load);
1446 EVT MemVT =
LD->getMemoryVT();
1448 :
LD->getExtensionType();
1451 LD->getChain(),
LD->getBasePtr(),
1452 MemVT,
LD->getMemOperand());
1455 unsigned Opc =
Op.getOpcode();
1459 if (
SDValue Op0 = SExtPromoteOperand(
Op.getOperand(0), PVT))
1463 if (
SDValue Op0 = ZExtPromoteOperand(
Op.getOperand(0), PVT))
1481 EVT OldVT =
Op.getValueType();
1483 bool Replace =
false;
1484 SDValue NewOp = PromoteOperand(
Op, PVT, Replace);
1487 AddToWorklist(NewOp.
getNode());
1490 ReplaceLoadWithPromotedLoad(
Op.getNode(), NewOp.
getNode());
1496 EVT OldVT =
Op.getValueType();
1498 bool Replace =
false;
1499 SDValue NewOp = PromoteOperand(
Op, PVT, Replace);
1502 AddToWorklist(NewOp.
getNode());
1505 ReplaceLoadWithPromotedLoad(
Op.getNode(), NewOp.
getNode());
1513 if (!LegalOperations)
1516 EVT VT =
Op.getValueType();
1522 unsigned Opc =
Op.getOpcode();
1530 assert(PVT != VT &&
"Don't know what type to promote to!");
1534 bool Replace0 =
false;
1536 SDValue NN0 = PromoteOperand(N0, PVT, Replace0);
1538 bool Replace1 =
false;
1540 SDValue NN1 = PromoteOperand(N1, PVT, Replace1);
1552 Replace1 &= (N0 != N1) && !N1->
hasOneUse();
1555 CombineTo(
Op.getNode(), RV);
1581 if (!LegalOperations)
1584 EVT VT =
Op.getValueType();
1590 unsigned Opc =
Op.getOpcode();
1598 assert(PVT != VT &&
"Don't know what type to promote to!");
1602 bool Replace =
false;
1605 N0 = SExtPromoteOperand(N0, PVT);
1607 N0 = ZExtPromoteOperand(N0, PVT);
1609 N0 = PromoteOperand(N0, PVT, Replace);
1620 ReplaceLoadWithPromotedLoad(
Op.getOperand(0).getNode(), N0.
getNode());
1630 if (!LegalOperations)
1633 EVT VT =
Op.getValueType();
1639 unsigned Opc =
Op.getOpcode();
1647 assert(PVT != VT &&
"Don't know what type to promote to!");
1657bool DAGCombiner::PromoteLoad(
SDValue Op) {
1658 if (!LegalOperations)
1664 EVT VT =
Op.getValueType();
1670 unsigned Opc =
Op.getOpcode();
1678 assert(PVT != VT &&
"Don't know what type to promote to!");
1683 EVT MemVT =
LD->getMemoryVT();
1685 :
LD->getExtensionType();
1687 LD->getChain(),
LD->getBasePtr(),
1688 MemVT,
LD->getMemOperand());
1697 AddToWorklist(
Result.getNode());
1698 recursivelyDeleteUnusedNodes(
N);
1711bool DAGCombiner::recursivelyDeleteUnusedNodes(
SDNode *
N) {
1712 if (!
N->use_empty())
1722 if (
N->use_empty()) {
1723 for (
const SDValue &ChildN :
N->op_values())
1724 Nodes.
insert(ChildN.getNode());
1726 removeFromWorklist(
N);
1731 }
while (!Nodes.
empty());
1746 WorklistInserter AddNodes(*
this);
1755 AddToWorklist(&
Node,
Node.use_empty());
1763 while (
SDNode *
N = getNextWorklistEntry()) {
1767 if (recursivelyDeleteUnusedNodes(
N))
1770 WorklistRemover DeadNodes(*
this);
1778 for (
SDNode *LN : UpdatedNodes)
1779 AddToWorklistWithUsers(LN);
1791 for (
const SDValue &ChildN :
N->op_values())
1792 AddToWorklist(ChildN.getNode(),
true,
1803 ChainsWithoutMergeableStores.
clear();
1814 "Node was deleted but visit returned new node!");
1822 N->getNumValues() == 1 &&
"Type mismatch");
1832 AddToWorklistWithUsers(RV.
getNode());
1838 recursivelyDeleteUnusedNodes(
N);
1848 switch (
N->getOpcode()) {
1874 case ISD::MUL:
return visitMUL<EmptyMatchContext>(
N);
1938 case ISD::FMA:
return visitFMA<EmptyMatchContext>(
N);
2010#define BEGIN_REGISTER_VP_SDNODE(SDOPC, ...) case ISD::SDOPC:
2011#include "llvm/IR/VPIntrinsics.def"
2012 return visitVPOp(
N);
2023 if (!DisableGenericCombines)
2029 "Node was deleted but visit returned NULL!");
2036 DagCombineInfo(DAG, Level,
false,
this);
2044 switch (
N->getOpcode()) {
2052 RV = PromoteIntBinOp(
SDValue(
N, 0));
2057 RV = PromoteIntShiftOp(
SDValue(
N, 0));
2078 if (N0 != N1 && (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1))) {
2093 if (
unsigned NumOps =
N->getNumOperands()) {
2094 if (
N->getOperand(0).getValueType() == MVT::Other)
2095 return N->getOperand(0);
2096 if (
N->getOperand(NumOps-1).getValueType() == MVT::Other)
2097 return N->getOperand(NumOps-1);
2098 for (
unsigned i = 1; i < NumOps-1; ++i)
2099 if (
N->getOperand(i).getValueType() == MVT::Other)
2100 return N->getOperand(i);
2106 SDValue Operand =
N->getOperand(0);
2121 if (
N->getNumOperands() == 2) {
2123 return N->getOperand(0);
2125 return N->getOperand(1);
2140 AddToWorklist(*(
N->user_begin()));
2145 bool Changed =
false;
2152 for (
unsigned i = 0; i < TFs.
size(); ++i) {
2157 for (
unsigned j = i;
j < TFs.
size();
j++)
2168 switch (
Op.getOpcode()) {
2186 if (SeenOps.
insert(
Op.getNode()).second)
2197 for (
unsigned i = 1, e = TFs.
size(); i < e; i++)
2198 AddToWorklist(TFs[i]);
2210 bool DidPruneOps =
false;
2212 unsigned NumLeftToConsider = 0;
2214 Worklist.
push_back(std::make_pair(
Op.getNode(), NumLeftToConsider++));
2218 auto AddToWorklist = [&](
unsigned CurIdx,
SDNode *
Op,
unsigned OpNumber) {
2224 unsigned OrigOpNumber = 0;
2225 while (OrigOpNumber < Ops.size() && Ops[OrigOpNumber].getNode() !=
Op)
2227 assert((OrigOpNumber != Ops.size()) &&
2228 "expected to find TokenFactor Operand");
2230 for (
unsigned i = CurIdx + 1; i < Worklist.
size(); ++i) {
2231 if (Worklist[i].second == OrigOpNumber) {
2232 Worklist[i].second = OpNumber;
2235 OpWorkCount[OpNumber] += OpWorkCount[OrigOpNumber];
2236 OpWorkCount[OrigOpNumber] = 0;
2237 NumLeftToConsider--;
2240 if (SeenChains.
insert(
Op).second) {
2241 OpWorkCount[OpNumber]++;
2246 for (
unsigned i = 0; i < Worklist.
size() && i < 1024; ++i) {
2248 if (NumLeftToConsider <= 1)
2250 auto CurNode = Worklist[i].first;
2251 auto CurOpNumber = Worklist[i].second;
2252 assert((OpWorkCount[CurOpNumber] > 0) &&
2253 "Node should not appear in worklist");
2254 switch (CurNode->getOpcode()) {
2260 NumLeftToConsider++;
2263 for (
const SDValue &
Op : CurNode->op_values())
2264 AddToWorklist(i,
Op.getNode(), CurOpNumber);
2270 AddToWorklist(i, CurNode->getOperand(0).getNode(), CurOpNumber);
2273 if (
auto *MemNode = dyn_cast<MemSDNode>(CurNode))
2274 AddToWorklist(i, MemNode->getChain().getNode(), CurOpNumber);
2277 OpWorkCount[CurOpNumber]--;
2278 if (OpWorkCount[CurOpNumber] == 0)
2279 NumLeftToConsider--;
2293 if (SeenChains.
count(
Op.getNode()) == 0)
2308 WorklistRemover DeadNodes(*
this);
2314 AddUsersToWorklist(
N);
2319 }
while (!
N->use_empty());
2320 deleteAndRecombine(
N);
2328 return Const !=
nullptr && !Const->isOpaque() ? Const :
nullptr;
2338 Op =
N->getOperand(0);
2340 if (
N->getFlags().hasNoUnsignedWrap())
2345 if (
N.getValueType().getScalarType() != MVT::i1 ||
2362 if (LD->isIndexed() || LD->getBasePtr().getNode() !=
N)
2364 VT = LD->getMemoryVT();
2365 AS = LD->getAddressSpace();
2367 if (ST->isIndexed() || ST->getBasePtr().getNode() !=
N)
2369 VT = ST->getMemoryVT();
2370 AS = ST->getAddressSpace();
2372 if (LD->isIndexed() || LD->getBasePtr().getNode() !=
N)
2374 VT = LD->getMemoryVT();
2375 AS = LD->getAddressSpace();
2377 if (ST->isIndexed() || ST->getBasePtr().getNode() !=
N)
2379 VT = ST->getMemoryVT();
2380 AS = ST->getAddressSpace();
2395 }
else if (
N->getOpcode() ==
ISD::SUB) {
2417 bool ShouldCommuteOperands) {
2422 if (ShouldCommuteOperands)
2434 unsigned Opcode =
N->getOpcode();
2435 EVT VT =
N->getValueType(0);
2442 unsigned OpNo = ShouldCommuteOperands ? 0 : 1;
2460 "Unexpected binary operator");
2477 unsigned SelOpNo = 0;
2513 bool CanFoldNonConst =
2519 if (!CanFoldNonConst &&
2527 if (CanFoldNonConst) {
2564 "Expecting add or sub");
2569 bool IsAdd =
N->getOpcode() ==
ISD::ADD;
2570 SDValue C = IsAdd ?
N->getOperand(1) :
N->getOperand(0);
2571 SDValue Z = IsAdd ?
N->getOperand(0) :
N->getOperand(1);
2572 auto *CN = dyn_cast<ConstantSDNode>(
C);
2577 if (Z.getOperand(0).getValueType() != MVT::i1)
2589 EVT VT =
C.getValueType();
2602 if ((!LegalOperations || hasOperation(
ISD::AVGCEILU, VT)) &&
2607 if ((!LegalOperations || hasOperation(
ISD::AVGCEILS, VT)) &&
2620 "Expecting add or sub");
2624 bool IsAdd =
N->getOpcode() ==
ISD::ADD;
2625 SDValue ConstantOp = IsAdd ?
N->getOperand(1) :
N->getOperand(0);
2626 SDValue ShiftOp = IsAdd ?
N->getOperand(0) :
N->getOperand(1);
2648 {ConstantOp, DAG.getConstant(1, DL, VT)})) {
2650 Not.getOperand(0), ShAmt);
2692 if (
SDValue FoldedVOp = SimplifyVBinOp(
N,
DL))
2724 if ((!LegalOperations ||
2727 X.getScalarValueSizeInBits() == 1) {
2743 if (
SDValue NewSel = foldBinOpIntoSelect(
N))
2747 if (!reassociationCanBreakAddressingModePattern(
ISD::ADD,
DL,
N, N0, N1)) {
2835 return (!Max && !
Op) ||
2836 (
Max &&
Op &&
Max->getAPIntValue() == (-
Op->getAPIntValue()));
2877 !
N->getFlags().hasNoSignedWrap()))) {
2898 (CA * CM + CB->getAPIntValue()).getSExtValue())) {
2902 if (
N->getFlags().hasNoUnsignedWrap() &&
2906 if (
N->getFlags().hasNoSignedWrap() &&
2915 DAG.
getConstant(CA * CM + CB->getAPIntValue(),
DL, VT), Flags);
2923 (CA * CM + CB->getAPIntValue()).getSExtValue())) {
2929 if (
N->getFlags().hasNoUnsignedWrap() &&
2934 if (
N->getFlags().hasNoSignedWrap() &&
2945 DAG.
getConstant(CA * CM + CB->getAPIntValue(),
DL, VT), Flags);
2950 if (
SDValue Combined = visitADDLikeCommutative(N0, N1,
N))
2953 if (
SDValue Combined = visitADDLikeCommutative(N1, N0,
N))
2985 if (
SDValue Combined = visitADDLike(
N))
3025 APInt NewStep = C0 + C1;
3035 APInt NewStep = SV0 + SV1;
3044 unsigned Opcode =
N->getOpcode();
3062 return DAG.
getNode(Opcode,
DL, VT, N1, N0);
3066 if (
SDValue FoldedVOp = SimplifyVBinOp(
N,
DL))
3086 bool ForceCarryReconstruction =
false) {
3092 V = V.getOperand(0);
3097 if (ForceCarryReconstruction)
3101 V = V.getOperand(0);
3105 if (ForceCarryReconstruction && V.getValueType() == MVT::i1)
3112 if (V.getResNo() != 1)
3119 EVT VT = V->getValueType(0);
3227 if (TN->
getVT() == MVT::i1) {
3244 DAG.
getVTList(VT, Carry.getValueType()), N0,
3257 if (!
N->hasAnyUseOfValue(1))
3290 if (Force && isa<ConstantSDNode>(V))
3297 return V.getOperand(0);
3309 EVT CarryVT =
N->getValueType(1);
3313 if (!
N->hasAnyUseOfValue(1))
3320 return DAG.
getNode(
N->getOpcode(),
DL,
N->getVTList(), N1, N0);
3345 if (
SDValue Combined = visitUADDOLike(N0, N1,
N))
3348 if (
SDValue Combined = visitUADDOLike(N1, N0,
N))
3382 SDValue CarryIn =
N->getOperand(2);
3401 SDValue CarryIn =
N->getOperand(2);
3412 if (!LegalOperations ||
3422 AddToWorklist(CarryExt.
getNode());
3428 if (
SDValue Combined = visitUADDO_CARRYLike(N0, N1, CarryIn,
N))
3431 if (
SDValue Combined = visitUADDO_CARRYLike(N1, N0, CarryIn,
N))
3439 SDValue Ops[] = {N1, N0, CarryIn};
3578 EVT CarryOutType =
N->getValueType(0);
3594 unsigned CarryInOperandNum =
3596 if (Opcode ==
ISD::USUBO && CarryInOperandNum != 1)
3690 SDValue CarryIn =
N->getOperand(2);
3701 if (!LegalOperations ||
3706 if (
SDValue Combined = visitSADDO_CARRYLike(N0, N1, CarryIn,
N))
3709 if (
SDValue Combined = visitSADDO_CARRYLike(N1, N0, CarryIn,
N))
3721 "Illegal truncation");
3747 !(!LegalOperations || hasOperation(
ISD::USUBSAT, DstVT)))
3750 EVT SubVT =
N->getValueType(0);
3818template <
class MatchContextClass>
3841 if ((
BitWidth - Src.getValueType().getScalarSizeInBits()) != BitWidthDiff)
3851 if (!(AndMask.
isMask(AndMaskWidth) && XorMask.
countr_one() >= AndMaskWidth))
3882 auto PeekThroughFreeze = [](
SDValue N) {
3884 return N->getOperand(0);
3888 if (
SDValue V = foldSubCtlzNot<EmptyMatchContext>(
N, DAG))
3893 if (PeekThroughFreeze(N0) == PeekThroughFreeze(N1))
3902 if (
SDValue FoldedVOp = SimplifyVBinOp(
N,
DL))
3910 if (
SDValue NewSel = foldBinOpIntoSelect(
N))
3933 if (
N->getFlags().hasNoUnsignedWrap())
3939 if (
N->getFlags().hasNoSignedWrap())
3965 if (hasOperation(NewOpc, VT))