19 #define DEBUG_TYPE "dagcombine"
43 STATISTIC(NodesCombined ,
"Number of dag nodes combined");
44 STATISTIC(PreIndexedNodes ,
"Number of pre-indexed nodes created");
45 STATISTIC(PostIndexedNodes,
"Number of post-indexed nodes created");
46 STATISTIC(OpsNarrowed ,
"Number of load/op/store narrowed");
47 STATISTIC(LdStFP2Int ,
"Number of fp load/store pairs transformed to int");
48 STATISTIC(SlicedLoads,
"Number of load sliced");
52 CombinerAA(
"combiner-alias-analysis",
cl::Hidden,
53 cl::desc(
"Turn on alias analysis during testing"));
56 CombinerGlobalAA(
"combiner-global-alias-analysis",
cl::Hidden,
57 cl::desc(
"Include global information in alias analysis"));
62 StressLoadSlicing(
"combiner-stress-load-slicing",
cl::Hidden,
63 cl::desc(
"Bypass the profitability model of load "
105 void AddUsersToWorkList(
SDNode *
N) {
118 void AddToWorkList(
SDNode *N) {
119 WorkListContents.insert(N);
120 WorkListOrder.push_back(N);
125 void removeFromWorkList(
SDNode *N) {
126 WorkListContents.erase(N);
133 return CombineTo(N, &Res, 1, AddTo);
139 return CombineTo(N, To, 2, AddTo);
149 bool SimplifyDemandedBits(
SDValue Op) {
152 return SimplifyDemandedBits(Op, Demanded);
155 bool SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded);
157 bool CombineToPreIndexedLoadStore(
SDNode *N);
158 bool CombineToPostIndexedLoadStore(
SDNode *N);
159 bool SliceUpLoad(
SDNode *N);
271 bool NotExtCompare =
false);
273 SDLoc DL,
bool foldBooleans =
true);
281 bool DemandHighBits =
true);
299 bool isAlias(
SDValue Ptr1, int64_t Size1,
bool IsVolatile1,
300 const Value *SrcValue1,
int SrcValueOffset1,
301 unsigned SrcValueAlign1,
303 SDValue Ptr2, int64_t Size2,
bool IsVolatile2,
304 const Value *SrcValue2,
int SrcValueOffset2,
305 unsigned SrcValueAlign2,
306 const MDNode *TBAAInfo2)
const;
314 bool FindAliasInfo(
SDNode *N,
315 SDValue &Ptr, int64_t &Size,
bool &IsVolatile,
316 const Value *&SrcValue,
int &SrcValueOffset,
317 unsigned &SrcValueAlignment,
318 const MDNode *&TBAAInfo)
const;
332 OptLevel(OL), LegalOperations(
false), LegalTypes(
false), AA(A) {
334 DAG.getMachineFunction().getFunction()->getAttributes();
348 EVT getShiftAmountTy(
EVT LHSTy) {
349 assert(LHSTy.
isInteger() &&
"Shift amount is not an integer type!");
352 return LegalTypes ? TLI.getScalarShiftAmountTy(LHSTy)
353 : TLI.getPointerTy();
358 bool isTypeLegal(
const EVT &VT) {
359 if (!LegalTypes)
return true;
360 return TLI.isTypeLegal(VT);
365 EVT getSetCCResultType(
EVT VT)
const {
366 return TLI.getSetCCResultType(*DAG.getContext(), VT);
378 explicit WorkListRemover(DAGCombiner &dc)
382 DC.removeFromWorkList(N);
392 ((DAGCombiner*)
DC)->AddToWorkList(N);
396 ((DAGCombiner*)
DC)->removeFromWorkList(N);
401 return ((DAGCombiner*)
DC)->CombineTo(N, &To[0], To.size(), AddTo);
406 return ((DAGCombiner*)
DC)->CombineTo(N, Res, AddTo);
412 return ((DAGCombiner*)
DC)->CombineTo(N, Res0, Res1, AddTo);
417 return ((DAGCombiner*)
DC)->CommitTargetLoweringOpt(TLO);
430 unsigned Depth = 0) {
438 if (Depth > 6)
return 0;
441 default:
return false;
445 return LegalOperations ? 0 : 1;
451 if (LegalOperations &&
464 if (!Options->UnsafeFPMath)
return 0;
471 if (Options->HonorSignDependentRoundingFPMath())
return 0;
492 bool LegalOperations,
unsigned Depth = 0) {
497 assert(Op.
hasOneUse() &&
"Unknown reuse!");
499 assert(Depth <= 6 &&
"GetNegatedExpression doesn't match isNegatibleForFree");
503 APFloat V = cast<ConstantFPSDNode>(Op)->getValueAPF();
517 LegalOperations, Depth+1),
522 LegalOperations, Depth+1),
530 if (N0CFP->getValueAPF().isZero())
547 LegalOperations, Depth+1),
554 LegalOperations, Depth+1));
560 LegalOperations, Depth+1));
564 LegalOperations, Depth+1),
586 cast<ConstantSDNode>(N.
getOperand(2))->getAPIntValue() == 1 &&
587 cast<ConstantSDNode>(N.
getOperand(3))->isNullValue()) {
606 SDValue DAGCombiner::ReassociateOps(
unsigned Opc,
SDLoc DL,
610 if (isa<ConstantSDNode>(N1)) {
613 DAG.FoldConstantArithmetic(Opc, VT,
615 cast<ConstantSDNode>(N1));
622 AddToWorkList(OpNode.
getNode());
623 return DAG.getNode(Opc, DL, VT, OpNode, N0.
getOperand(1));
628 if (isa<ConstantSDNode>(N0)) {
631 DAG.FoldConstantArithmetic(Opc, VT,
633 cast<ConstantSDNode>(N0));
640 AddToWorkList(OpNode.
getNode());
641 return DAG.getNode(Opc, DL, VT, OpNode, N1.
getOperand(1));
650 assert(N->
getNumValues() == NumTo &&
"Broken CombineTo call!");
654 dbgs() <<
"\nWith: ";
656 dbgs() <<
" and " << NumTo-1 <<
" other values\n";
657 for (
unsigned i = 0, e = NumTo; i != e; ++i)
658 assert((!To[i].getNode() ||
660 "Cannot combine value to value of different type!"));
661 WorkListRemover DeadNodes(*
this);
662 DAG.ReplaceAllUsesWith(N, To);
665 for (
unsigned i = 0, e = NumTo; i != e; ++i) {
666 if (To[i].getNode()) {
667 AddToWorkList(To[i].getNode());
668 AddUsersToWorkList(To[i].getNode());
679 removeFromWorkList(N);
691 WorkListRemover DeadNodes(*
this);
692 DAG.ReplaceAllUsesOfValueWith(TLO.
Old, TLO.
New);
717 bool DAGCombiner::SimplifyDemandedBits(
SDValue Op,
const APInt &Demanded) {
719 APInt KnownZero, KnownOne;
720 if (!TLI.SimplifyDemandedBits(Op, Demanded, KnownZero, KnownOne, TLO))
730 dbgs() <<
"\nWith: ";
734 CommitTargetLoweringOpt(TLO);
738 void DAGCombiner::ReplaceLoadWithPromotedLoad(
SDNode *
Load,
SDNode *ExtLoad) {
745 dbgs() <<
"\nWith: ";
748 WorkListRemover DeadNodes(*
this);
749 DAG.ReplaceAllUsesOfValueWith(
SDValue(Load, 0), Trunc);
750 DAG.ReplaceAllUsesOfValueWith(
SDValue(Load, 1),
SDValue(ExtLoad, 1));
751 removeFromWorkList(Load);
752 DAG.DeleteNode(Load);
753 AddToWorkList(Trunc.
getNode());
760 EVT MemVT =
LD->getMemoryVT();
764 :
LD->getExtensionType();
766 return DAG.getExtLoad(ExtType, dl, PVT,
767 LD->getChain(),
LD->getBasePtr(),
768 MemVT,
LD->getMemOperand());
785 return DAG.getNode(ExtOpc, dl, PVT, Op);
799 bool Replace =
false;
800 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
803 AddToWorkList(NewOp.
getNode());
814 bool Replace =
false;
815 SDValue NewOp = PromoteOperand(Op, PVT, Replace);
818 AddToWorkList(NewOp.
getNode());
822 return DAG.getZeroExtendInReg(NewOp, dl, OldVT);
829 if (!LegalOperations)
839 if (TLI.isTypeDesirableForOp(Opc, VT))
845 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
846 assert(PVT != VT &&
"Don't know what type to promote to!");
848 bool Replace0 =
false;
850 SDValue NN0 = PromoteOperand(N0, PVT, Replace0);
854 bool Replace1 =
false;
860 NN1 = PromoteOperand(N1, PVT, Replace1);
878 DAG.getNode(Opc, dl, PVT, NN0, NN1));
887 if (!LegalOperations)
897 if (TLI.isTypeDesirableForOp(Opc, VT))
903 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
904 assert(PVT != VT &&
"Don't know what type to promote to!");
906 bool Replace =
false;
909 N0 = SExtPromoteOperand(Op.
getOperand(0), PVT);
911 N0 = ZExtPromoteOperand(Op.
getOperand(0), PVT);
913 N0 = PromoteOperand(N0, PVT, Replace);
914 if (N0.getNode() == 0)
917 AddToWorkList(N0.getNode());
925 DAG.getNode(Opc, dl, PVT, N0, Op.
getOperand(1)));
931 if (!LegalOperations)
941 if (TLI.isTypeDesirableForOp(Opc, VT))
947 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
948 assert(PVT != VT &&
"Don't know what type to promote to!");
959 bool DAGCombiner::PromoteLoad(
SDValue Op) {
960 if (!LegalOperations)
970 if (TLI.isTypeDesirableForOp(Opc, VT))
976 if (TLI.IsDesirableToPromoteOp(Op, PVT)) {
977 assert(PVT != VT &&
"Don't know what type to promote to!");
987 SDValue NewLD = DAG.getExtLoad(ExtType, dl, PVT,
997 WorkListRemover DeadNodes(*
this);
998 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 0), Result);
1000 removeFromWorkList(N);
1002 AddToWorkList(Result.
getNode());
1021 E = DAG.allnodes_end();
I != E; ++
I)
1035 while (!WorkListContents.empty()) {
1043 N = WorkListOrder.pop_back_val();
1044 }
while (!WorkListContents.erase(N));
1073 "Node was deleted but visit returned new node!");
1077 dbgs() <<
"\nWith: ";
1082 DAG.TransferDbgValues(
SDValue(N, 0), RV);
1083 WorkListRemover DeadNodes(*
this);
1085 DAG.ReplaceAllUsesWith(N, RV.
getNode());
1090 DAG.ReplaceAllUsesWith(N, &OpV);
1095 AddUsersToWorkList(RV.
getNode());
1109 removeFromWorkList(N);
1117 DAG.setRoot(
Dummy.getValue());
1118 DAG.RemoveDeadNodes();
1146 case ISD::OR:
return visitOR(N);
1206 "Node was deleted but visit returned NULL!");
1213 DagCombineInfo(DAG,
Level,
false,
this);
1215 RV = TLI.PerformDAGCombine(N, DagCombineInfo);
1229 RV = PromoteIntBinOp(
SDValue(N, 0));
1234 RV = PromoteIntShiftOp(
SDValue(N, 0));
1239 RV = PromoteExtend(
SDValue(N, 0));
1242 if (PromoteLoad(
SDValue(N, 0)))
1257 if (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1)) {
1277 for (
unsigned i = 1; i < NumOps-1; ++i)
1297 bool Changed =
false;
1304 for (
unsigned i = 0; i < TFs.
size(); ++i) {
1347 Result = DAG.getEntryNode();
1355 return CombineTo(N, Result,
false);
1363 WorkListRemover DeadNodes(*
this);
1369 AddUsersToWorkList(N);
1374 removeFromWorkList(N);
1409 if (VT.isVector()) {
1410 SDValue FoldedVOp = SimplifyVBinOp(N);
1411 if (FoldedVOp.
getNode())
return FoldedVOp;
1427 return DAG.FoldConstantArithmetic(
ISD::ADD, VT, N0C, N1C);
1432 if (N1C && N1C->isNullValue())
1436 if (!LegalOperations && TLI.isOffsetFoldingLegal(GA) && N1C &&
1438 return DAG.getGlobalAddress(GA->getGlobal(),
SDLoc(N1C), VT,
1440 (uint64_t)N1C->getSExtValue());
1445 DAG.getConstant(N1C->getAPIntValue()+
1454 cast<ConstantSDNode>(N0.
getOperand(0))->isNullValue())
1458 cast<ConstantSDNode>(N1.
getOperand(0))->isNullValue())
1467 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
1468 N0 == N1.getOperand(1).getOperand(0))
1470 N1.getOperand(1).getOperand(1));
1472 if (N1.getOpcode() ==
ISD::SUB && N1.getOperand(1).getOpcode() ==
ISD::ADD &&
1473 N0 == N1.getOperand(1).getOperand(1))
1474 return DAG.getNode(
ISD::SUB,
SDLoc(N), VT, N1.getOperand(0),
1475 N1.getOperand(1).getOperand(0));
1478 N1.getOperand(0).getOpcode() ==
ISD::SUB &&
1479 N0 == N1.getOperand(0).getOperand(1))
1480 return DAG.getNode(N1.getOpcode(),
SDLoc(N), VT,
1481 N1.getOperand(0).getOperand(0), N1.getOperand(1));
1490 if (isa<ConstantSDNode>(N00) || isa<ConstantSDNode>(N10))
1500 if (VT.isInteger() && !VT.isVector()) {
1501 APInt LHSZero, LHSOne;
1502 APInt RHSZero, RHSOne;
1503 DAG.ComputeMaskedBits(N0, LHSZero, LHSOne);
1506 DAG.ComputeMaskedBits(N1, RHSZero, RHSOne);
1510 if ((RHSZero & ~LHSZero) == ~LHSZero || (LHSZero & ~RHSZero) == ~RHSZero)
1516 if (N0.getOpcode() ==
ISD::SHL && N0.getNode()->hasOneUse()) {
1518 if (Result.
getNode())
return Result;
1520 if (N1.getOpcode() ==
ISD::SHL && N1.getNode()->hasOneUse()) {
1522 if (Result.
getNode())
return Result;
1527 N1.getOperand(0).getOpcode() ==
ISD::SUB)
1529 dyn_cast<ConstantSDNode>(N1.getOperand(0).getOperand(0)))
1530 if (
C->getAPIntValue() == 0)
1533 N1.getOperand(0).getOperand(1),
1536 N0.getOperand(0).getOpcode() ==
ISD::SUB)
1538 dyn_cast<ConstantSDNode>(N0.getOperand(0).getOperand(0)))
1539 if (
C->getAPIntValue() == 0)
1542 N0.getOperand(0).getOperand(1),
1548 unsigned NumSignBits = DAG.ComputeNumSignBits(AndOp0);
1549 unsigned DestBits = VT.getScalarType().getSizeInBits();
1553 if (NumSignBits == DestBits && AndOp1 && AndOp1->
isOne()) {
1561 N0.getOperand(0).getValueType() ==
MVT::i1 &&
1565 return DAG.getNode(
ISD::SUB, DL, VT, N1, ZExt);
1580 return CombineTo(N, DAG.getNode(
ISD::ADD,
SDLoc(N), VT, N0, N1),
1589 if (N1C && N1C->isNullValue())
1594 APInt LHSZero, LHSOne;
1595 APInt RHSZero, RHSOne;
1596 DAG.ComputeMaskedBits(N0, LHSZero, LHSOne);
1599 DAG.ComputeMaskedBits(N1, RHSZero, RHSOne);
1603 if ((RHSZero & ~LHSZero) == ~LHSZero || (LHSZero & ~RHSZero) == ~RHSZero)
1604 return CombineTo(N, DAG.getNode(
ISD::OR,
SDLoc(N), VT, N0, N1),
1635 bool LegalOperations,
bool LegalTypes) {
1653 if (VT.isVector()) {
1654 SDValue FoldedVOp = SimplifyVBinOp(N);
1655 if (FoldedVOp.
getNode())
return FoldedVOp;
1668 return DAG.FoldConstantArithmetic(
ISD::SUB, VT, N0C, N1C);
1672 DAG.getConstant(-N1C->getAPIntValue(), VT));
1680 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(0) == N1)
1683 if (N0.getOpcode() ==
ISD::ADD && N0.getOperand(1) == N1)
1694 (N0.getOperand(1).getOpcode() ==
ISD::SUB ||
1695 N0.getOperand(1).getOpcode() ==
ISD::ADD) &&
1696 N0.getOperand(1).getOperand(0) == N1)
1697 return DAG.getNode(N0.getOperand(1).getOpcode(),
SDLoc(N), VT,
1698 N0.getOperand(0), N0.getOperand(1).getOperand(1));
1701 N0.getOperand(1).getOpcode() ==
ISD::ADD &&
1702 N0.getOperand(1).getOperand(1) == N1)
1704 N0.getOperand(0), N0.getOperand(1).getOperand(0));
1707 N0.getOperand(1).getOpcode() ==
ISD::SUB &&
1708 N0.getOperand(1).getOperand(1) == N1)
1710 N0.getOperand(0), N0.getOperand(1).getOperand(0));
1720 if (!LegalOperations && TLI.isOffsetFoldingLegal(GA)) {
1723 return DAG.getGlobalAddress(GA->getGlobal(),
SDLoc(N1C), VT,
1725 (uint64_t)N1C->getSExtValue());
1728 if (GA->getGlobal() == GB->getGlobal())
1729 return DAG.getConstant((uint64_t)GA->getOffset() - GB->getOffset(),
1745 return CombineTo(N, DAG.getNode(
ISD::SUB,
SDLoc(N), VT, N0, N1),
1751 return CombineTo(N, DAG.getConstant(0, VT),
1756 if (N1C && N1C->isNullValue())
1762 return CombineTo(N, DAG.getNode(
ISD::XOR,
SDLoc(N), VT, N1, N0),
1789 unsigned SplatBitSize;
1804 return DAG.getConstant(0, VT);
1806 bool N0IsConst =
false;
1807 bool N1IsConst =
false;
1808 APInt ConstValue0, ConstValue1;
1811 SDValue FoldedVOp = SimplifyVBinOp(N);
1812 if (FoldedVOp.
getNode())
return FoldedVOp;
1826 if (N0IsConst && N1IsConst)
1830 if (N0IsConst && !N1IsConst)
1833 if (N1IsConst && ConstValue1 == 0)
1840 if (N1IsConst && ConstValue1 == 1 && IsFullSplat)
1845 DAG.getConstant(0, VT), N0);
1847 if (N1IsConst && ConstValue1.
isPowerOf2() && IsFullSplat)
1849 DAG.getConstant(ConstValue1.
logBase2(),
1852 if (N1IsConst && (-ConstValue1).isPowerOf2() && IsFullSplat) {
1853 unsigned Log2Val = (-ConstValue1).
logBase2();
1857 DAG.getConstant(0, VT),
1859 DAG.getConstant(Log2Val,
1893 Sh.getOperand(0),
Y);
1925 if (VT.isVector()) {
1926 SDValue FoldedVOp = SimplifyVBinOp(N);
1927 if (FoldedVOp.
getNode())
return FoldedVOp;
1932 return DAG.FoldConstantArithmetic(
ISD::SDIV, VT, N0C, N1C);
1934 if (N1C && N1C->getAPIntValue() == 1LL)
1937 if (N1C && N1C->isAllOnesValue())
1939 DAG.getConstant(0, VT), N0);
1942 if (!VT.isVector()) {
1943 if (DAG.SignBitIsZero(N1) && DAG.SignBitIsZero(N0))
1948 if (N1C && !N1C->isNullValue() &&
1949 (N1C->getAPIntValue().isPowerOf2() ||
1950 (-N1C->getAPIntValue()).isPowerOf2())) {
1953 if (TLI.isPow2DivCheap())
1956 unsigned lg2 = N1C->getAPIntValue().countTrailingZeros();
1960 DAG.getConstant(VT.getSizeInBits()-1,
1966 DAG.getConstant(VT.getSizeInBits() - lg2,
1969 AddToWorkList(SRL.getNode());
1976 if (N1C->getAPIntValue().isNonNegative())
1979 AddToWorkList(SRA.getNode());
1981 DAG.getConstant(0, VT),
SRA);
1986 if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap()) {
1993 return DAG.getConstant(0, VT);
2009 if (VT.isVector()) {
2010 SDValue FoldedVOp = SimplifyVBinOp(N);
2011 if (FoldedVOp.
getNode())
return FoldedVOp;
2016 return DAG.FoldConstantArithmetic(
ISD::UDIV, VT, N0C, N1C);
2018 if (N1C && N1C->getAPIntValue().isPowerOf2())
2020 DAG.getConstant(N1C->getAPIntValue().logBase2(),
2025 if (SHC->getAPIntValue().isPowerOf2()) {
2029 DAG.getConstant(SHC->getAPIntValue()
2038 if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap()) {
2045 return DAG.getConstant(0, VT);
2062 return DAG.FoldConstantArithmetic(
ISD::SREM, VT, N0C, N1C);
2065 if (!VT.isVector()) {
2066 if (DAG.SignBitIsZero(N1) && DAG.SignBitIsZero(N0))
2072 if (N1C && !N1C->isNullValue()) {
2076 if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.
getNode()) {
2087 return DAG.getConstant(0, VT);
2104 return DAG.FoldConstantArithmetic(
ISD::UREM, VT, N0C, N1C);
2106 if (N1C && !N1C->isNullValue() && N1C->getAPIntValue().isPowerOf2())
2108 DAG.getConstant(N1C->getAPIntValue()-1,VT));
2112 if (SHC->getAPIntValue().isPowerOf2()) {
2125 if (N1C && !N1C->isNullValue()) {
2129 if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.
getNode()) {
2140 return DAG.getConstant(0, VT);
2165 return DAG.getConstant(0, VT);
2169 if (VT.isSimple() && !VT.isVector()) {
2170 MVT Simple = VT.getSimpleVT();
2173 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
2201 return DAG.getConstant(0, VT);
2205 if (VT.isSimple() && !VT.isVector()) {
2206 MVT Simple = VT.getSimpleVT();
2209 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
2226 SDValue DAGCombiner::SimplifyNodeWithTwoResults(
SDNode *N,
unsigned LoOp,
2231 (!LegalOperations ||
2235 return CombineTo(N, Res, Res);
2241 (!LegalOperations ||
2245 return CombineTo(N, Res, Res);
2249 if (LoExists && HiExists)
2258 if (LoOpt.getNode() && LoOpt.getNode() != Lo.
getNode() &&
2259 (!LegalOperations ||
2260 TLI.isOperationLegal(LoOpt.getOpcode(), LoOpt.getValueType())))
2261 return CombineTo(N, LoOpt, LoOpt);
2269 if (HiOpt.getNode() && HiOpt != Hi &&
2270 (!LegalOperations ||
2271 TLI.isOperationLegal(HiOpt.getOpcode(), HiOpt.getValueType())))
2272 return CombineTo(N, HiOpt, HiOpt);
2280 if (Res.
getNode())
return Res;
2291 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
2301 return CombineTo(N, Lo, Hi);
2310 if (Res.
getNode())
return Res;
2321 if (TLI.isOperationLegal(
ISD::MUL, NewVT)) {
2331 return CombineTo(N, Lo, Hi);
2341 if (C2->getAPIntValue() == 2)
2351 if (C2->getAPIntValue() == 2)
2360 if (Res.
getNode())
return Res;
2367 if (Res.
getNode())
return Res;
2374 SDValue DAGCombiner::SimplifyBinOpWithSameOpcodeHands(
SDNode *N) {
2395 (!LegalTypes || TLI.isTypeDesirableForOp(N->
getOpcode(), Op0VT))) ||
2397 (!TLI.isZExtFree(VT, Op0VT) ||
2398 !TLI.isTruncateFree(Op0VT, VT)) &&
2399 TLI.isTypeLegal(Op0VT))) &&
2402 (!LegalOperations || TLI.isOperationLegal(N->
getOpcode(), Op0VT))) {
2406 AddToWorkList(ORNode.
getNode());
2420 AddToWorkList(ORNode.
getNode());
2464 "Inputs to shuffles are not the same type");
2470 bool SameMask =
true;
2471 for (
unsigned i = 0; i != NumElts; ++i) {
2473 int Idx1 = SVN1->getMaskElt(i);
2484 return DAG.getVectorShuffle(VT,
SDLoc(N), Op,
2485 DAG.getUNDEF(VT), &SVN0->
getMask()[0]);
2495 SDValue LL, LR, RL, RR, CC0, CC1;
2499 unsigned BitWidth = VT.getScalarType().getSizeInBits();
2502 if (VT.isVector()) {
2503 SDValue FoldedVOp = SimplifyVBinOp(N);
2504 if (FoldedVOp.
getNode())
return FoldedVOp;
2521 return DAG.getConstant(0, VT);
2524 return DAG.FoldConstantArithmetic(
ISD::AND, VT, N0C, N1C);
2529 if (N1C && N1C->isAllOnesValue())
2532 if (N1C && DAG.MaskedValueIsZero(
SDValue(N, 0),
2534 return DAG.getConstant(0, VT);
2542 if ((ORI->getAPIntValue() & N1C->getAPIntValue()) == N1C->getAPIntValue())
2547 APInt Mask = ~N1C->getAPIntValue();
2549 if (DAG.MaskedValueIsZero(N0Op0, Mask)) {
2559 CombineTo(N0.
getNode(), Zext);
2580 Constant =
C->getAPIntValue();
2582 APInt SplatValue, SplatUndef;
2583 unsigned SplatBitSize;
2585 bool IsSplat = Vector->isConstantSplat(SplatValue, SplatUndef,
2586 SplatBitSize, HasAnyUndefs);
2590 SplatValue |= SplatUndef;
2596 EVT VT = Vector->getValueType(0);
2602 if (BitWidth > SplatBitSize)
2603 for (SplatValue = SplatValue.
zextOrTrunc(BitWidth);
2604 SplatBitSize < BitWidth;
2605 SplatBitSize = SplatBitSize * 2)
2606 SplatValue |= SplatValue.
shl(SplatBitSize);
2609 for (
unsigned i = 0, n = SplatBitSize/BitWidth; i < n; ++i)
2617 bool CanZextLoadProfitably = TLI.isLoadExtLegal(
ISD::ZEXTLOAD,
2628 default: B =
false;
break;
2634 if (B && Constant.isAllOnesValue()) {
2649 CombineTo(Load, To, 3,
true);
2651 CombineTo(Load, NewLoad.getValue(0), NewLoad.getValue(1));
2657 CombineTo(N, (N0.
getNode() ==
Load) ? NewLoad : N0);
2667 if (LR == RR && isa<ConstantSDNode>(LR) && Op0 == Op1 &&
2670 if (cast<ConstantSDNode>(LR)->isNullValue() && Op1 ==
ISD::SETEQ) {
2673 AddToWorkList(ORNode.
getNode());
2674 return DAG.getSetCC(
SDLoc(N), VT, ORNode, LR, Op1);
2677 if (cast<ConstantSDNode>(LR)->isAllOnesValue() && Op1 ==
ISD::SETEQ) {
2680 AddToWorkList(ANDNode.
getNode());
2681 return DAG.getSetCC(
SDLoc(N), VT, ANDNode, LR, Op1);
2684 if (cast<ConstantSDNode>(LR)->isAllOnesValue() && Op1 ==
ISD::SETGT) {
2687 AddToWorkList(ORNode.
getNode());
2688 return DAG.getSetCC(
SDLoc(N), VT, ORNode, LR, Op1);
2692 if (LL == RL && isa<ConstantSDNode>(LR) && isa<ConstantSDNode>(RR) &&
2694 Op0 ==
ISD::SETNE && ((cast<ConstantSDNode>(LR)->isNullValue() &&
2695 cast<ConstantSDNode>(RR)->isAllOnesValue()) ||
2696 (cast<ConstantSDNode>(LR)->isAllOnesValue() &&
2697 cast<ConstantSDNode>(RR)->isNullValue()))) {
2700 AddToWorkList(ADDNode.
getNode());
2701 return DAG.getSetCC(
SDLoc(N), VT, ADDNode,
2705 if (LL == RR && LR == RL) {
2709 if (LL == RL && LR == RR) {
2713 (!LegalOperations ||
2724 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
2725 if (Tmp.
getNode())
return Tmp;
2742 BitWidth - MemVT.getScalarType().getSizeInBits())) &&
2762 BitWidth - MemVT.getScalarType().getSizeInBits())) &&
2783 : cast<LoadSDNode>(N0);
2786 uint32_t ActiveBits = N1C->getAPIntValue().getActiveBits();
2791 if (ExtVT == LoadedVT &&
2792 (!LegalOperations || TLI.isLoadExtLegal(
ISD::ZEXTLOAD, ExtVT))) {
2800 CombineTo(LN0, NewLoad, NewLoad.
getValue(1));
2808 (!LegalOperations || TLI.isLoadExtLegal(
ISD::ZEXTLOAD, ExtVT))) {
2817 if (TLI.isBigEndian()) {
2818 unsigned LVTStoreBytes = LoadedVT.getStoreSize();
2820 unsigned PtrOff = LVTStoreBytes - EVTStoreBytes;
2822 NewPtr, DAG.getConstant(PtrOff, PtrType));
2823 Alignment =
MinAlign(Alignment, PtrOff);
2826 AddToWorkList(NewPtr.
getNode());
2836 CombineTo(LN0, Load, Load.
getValue(1));
2854 SRLI->getZExtValue());
2855 if (DAG.MaskedValueIsZero(N0.
getOperand(1), Mask)) {
2860 N0.
getOperand(0), DAG.getConstant(ADDC, VT));
2861 CombineTo(N0.
getNode(), NewAdd);
2884 bool DemandHighBits) {
2885 if (!LegalOperations)
2895 bool LookPassAnd0 =
false;
2896 bool LookPassAnd1 =
false;
2908 LookPassAnd0 =
true;
2918 LookPassAnd1 =
true;
2933 if (N01C->
getZExtValue() != 8 || N11C->getZExtValue() != 8)
2945 LookPassAnd0 =
true;
2956 LookPassAnd1 =
true;
2965 if (DemandHighBits && OpSizeInBits > 16) {
2974 if (!LookPassAnd1 &&
2975 !DAG.MaskedValueIsZero(
2981 if (OpSizeInBits > 16)
3006 case 0xFF: Num = 0;
break;
3007 case 0xFF00: Num = 1;
break;
3008 case 0xFF0000: Num = 2;
break;
3009 case 0xFF000000: Num = 3;
break;
3015 if (Num == 0 || Num == 2) {
3035 if (Num != 0 && Num != 2)
3043 if (Num != 1 && Num != 3)
3061 if (!LegalOperations)
3112 if (Parts[0] != Parts[1] || Parts[0] != Parts[2] || Parts[0] != Parts[3])
3121 if (TLI.isOperationLegalOrCustom(
ISD::ROTL, VT))
3123 if (TLI.isOperationLegalOrCustom(
ISD::ROTR, VT))
3133 SDValue LL, LR, RL, RR, CC0, CC1;
3139 if (VT.isVector()) {
3140 SDValue FoldedVOp = SimplifyVBinOp(N);
3141 if (FoldedVOp.
getNode())
return FoldedVOp;
3157 if (!LegalOperations &&
3159 EVT EltVT = VT.
isVector() ? VT.getVectorElementType() : VT;
3164 return DAG.FoldConstantArithmetic(
ISD::OR, VT, N0C, N1C);
3169 if (N1C && N1C->isNullValue())
3172 if (N1C && N1C->isAllOnesValue())
3175 if (N1C && DAG.MaskedValueIsZero(N0, ~N1C->getAPIntValue()))
3179 SDValue BSwap = MatchBSwapHWord(N, N0, N1);
3182 BSwap = MatchBSwapHWordLow(N, N0, N1);
3199 DAG.FoldConstantArithmetic(
ISD::OR, VT, N1C, C1));
3206 if (LR == RR && isa<ConstantSDNode>(LR) && Op0 == Op1 &&
3210 if (cast<ConstantSDNode>(LR)->isNullValue() &&
3214 AddToWorkList(ORNode.
getNode());
3215 return DAG.getSetCC(
SDLoc(N), VT, ORNode, LR, Op1);
3219 if (cast<ConstantSDNode>(LR)->isAllOnesValue() &&
3223 AddToWorkList(ANDNode.
getNode());
3224 return DAG.getSetCC(
SDLoc(N), VT, ANDNode, LR, Op1);
3228 if (LL == RR && LR == RL) {
3232 if (LL == RL && LR == RR) {
3236 (!LegalOperations ||
3247 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
3248 if (Tmp.
getNode())
return Tmp;
3260 const APInt &LHSMask =
3261 cast<ConstantSDNode>(N0.
getOperand(1))->getAPIntValue();
3262 const APInt &RHSMask =
3263 cast<ConstantSDNode>(N1.
getOperand(1))->getAPIntValue();
3265 if (DAG.MaskedValueIsZero(N0.
getOperand(0), RHSMask&~LHSMask) &&
3266 DAG.MaskedValueIsZero(N1.
getOperand(0), LHSMask&~RHSMask)) {
3270 DAG.getConstant(LHSMask | RHSMask, VT));
3279 if (!VT.isVector() &&
3311 if (!TLI.isTypeLegal(VT))
return 0;
3314 bool HasROTL = TLI.isOperationLegalOrCustom(
ISD::ROTL, VT);
3315 bool HasROTR = TLI.isOperationLegalOrCustom(
ISD::ROTR, VT);
3316 if (!HasROTL && !HasROTR)
return 0;
3352 uint64_t LShVal = cast<ConstantSDNode>(LHSShiftAmt)->getZExtValue();
3353 uint64_t RShVal = cast<ConstantSDNode>(RHSShiftAmt)->getZExtValue();
3354 if ((LShVal + RShVal) != OpSizeInBits)
3358 LHSShiftArg, HasROTL ? LHSShiftAmt : RHSShiftAmt);
3366 Mask &= cast<ConstantSDNode>(LHSMask)->getAPIntValue() | RHSBits;
3370 Mask &= cast<ConstantSDNode>(RHSMask)->getAPIntValue() | LHSBits;
3385 SDValue LExtOp0 = LHSShiftAmt;
3386 SDValue RExtOp0 = RHSShiftAmt;
3405 dyn_cast<ConstantSDNode>(RExtOp0.
getOperand(0))) {
3406 if (
SUBC->getAPIntValue() == OpSizeInBits) {
3408 HasROTL ? LHSShiftAmt : RHSShiftAmt).getNode();
3419 bool HasROTRWithLArg = TLI.isOperationLegalOrCustom(ISD::ROTR, LArgVT);
3420 bool HasROTLWithLArg = TLI.isOperationLegalOrCustom(
ISD::ROTL, LArgVT);
3421 if (HasROTRWithLArg || HasROTLWithLArg) {
3425 LArgExtOp0, HasROTL ? LHSShiftAmt : RHSShiftAmt);
3426 return DAG.getNode(LHSShiftArg.
getOpcode(), DL, VT, V).getNode();
3438 dyn_cast<ConstantSDNode>(LExtOp0.
getOperand(0))) {
3439 if (
SUBC->getAPIntValue() == OpSizeInBits) {
3440 return DAG.getNode(HasROTR ? ISD::ROTR :
ISD::ROTL, DL, VT, LHSShiftArg,
3441 HasROTR ? RHSShiftAmt : LHSShiftAmt).getNode();
3452 bool HasROTRWithRArg = TLI.isOperationLegalOrCustom(ISD::ROTR, RArgVT);
3453 bool HasROTLWithRArg = TLI.isOperationLegalOrCustom(ISD::ROTL, RArgVT);
3454 if (HasROTRWithRArg || HasROTLWithRArg) {
3457 DAG.
getNode(HasROTRWithRArg ? ISD::ROTR : ISD::ROTL, DL, RArgVT,
3458 RArgExtOp0, HasROTR ? RHSShiftAmt : LHSShiftAmt);
3459 return DAG.getNode(RHSShiftArg.
getOpcode(), DL, VT, V).getNode();
3478 if (VT.isVector()) {
3479 SDValue FoldedVOp = SimplifyVBinOp(N);
3480 if (FoldedVOp.
getNode())
return FoldedVOp;
3491 return DAG.getConstant(0, VT);
3499 return DAG.FoldConstantArithmetic(
ISD::XOR, VT, N0C, N1C);
3504 if (N1C && N1C->isNullValue())
3517 if (!LegalOperations ||
3523 return DAG.getSetCC(
SDLoc(N), VT, LHS, RHS, NotCC);
3543 if (N1C && N1C->getAPIntValue() == 1 && VT ==
MVT::i1 &&
3550 AddToWorkList(LHS.
getNode()); AddToWorkList(RHS.getNode());
3551 return DAG.getNode(NewOpcode,
SDLoc(N), VT, LHS, RHS);
3555 if (N1C && N1C->isAllOnesValue() &&
3558 if (isa<ConstantSDNode>(RHS) || isa<ConstantSDNode>(LHS)) {
3562 AddToWorkList(LHS.
getNode()); AddToWorkList(RHS.getNode());
3563 return DAG.getNode(NewOpcode,
SDLoc(N), VT, LHS, RHS);
3571 AddToWorkList(NotX.
getNode());
3580 DAG.getConstant(N1C->getAPIntValue() ^
3584 DAG.getConstant(N1C->getAPIntValue() ^
3585 N01C->getAPIntValue(), VT));
3593 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
3594 if (Tmp.
getNode())
return Tmp;
3598 if (!VT.isVector() &&
3607 SDValue DAGCombiner::visitShiftByConstant(
SDNode *N,
unsigned Amt) {
3615 bool HighBitSet =
false;
3635 if (!BinOpCst)
return SDValue();
3646 !isa<ConstantSDNode>(BinOpLHSVal->
getOperand(1)))
3657 if (BinOpRHSSignSet != HighBitSet)
3672 return DAG.getNode(LHS->
getOpcode(),
SDLoc(N), VT, NewShift, NewRHS);
3681 unsigned OpSizeInBits = VT.getScalarType().getSizeInBits();
3684 if (VT.isVector()) {
3685 SDValue FoldedVOp = SimplifyVBinOp(N);
3686 if (FoldedVOp.
getNode())
return FoldedVOp;
3691 return DAG.FoldConstantArithmetic(
ISD::SHL, VT, N0C, N1C);
3696 if (N1C && N1C->getZExtValue() >= OpSizeInBits)
3697 return DAG.getUNDEF(VT);
3699 if (N1C && N1C->isNullValue())
3703 return DAG.getConstant(0, VT);
3705 if (DAG.MaskedValueIsZero(
SDValue(N, 0),
3707 return DAG.getConstant(0, VT);
3723 DAG.getConstant(TruncC, TruncVT)));
3733 uint64_t c1 = cast<ConstantSDNode>(N0.
getOperand(1))->getZExtValue();
3734 uint64_t c2 = N1C->getZExtValue();
3735 if (c1 + c2 >= OpSizeInBits)
3736 return DAG.getConstant(0, VT);
3753 uint64_t c2 = N1C->getZExtValue();
3756 if (c2 >= OpSizeInBits - InnerShiftSize) {
3757 if (c1 + c2 >= OpSizeInBits)
3758 return DAG.getConstant(0, VT);
3774 if (c1 < VT.getSizeInBits()) {
3775 uint64_t c2 = N1C->getZExtValue();
3780 NewOp0, DAG.getConstant(c2, CountVT));
3781 AddToWorkList(NewSHL.
getNode());
3793 uint64_t c1 = cast<ConstantSDNode>(N0.
getOperand(1))->getZExtValue();
3794 if (c1 < VT.getSizeInBits()) {
3795 uint64_t c2 = N1C->getZExtValue();
3797 VT.getSizeInBits() - c1);
3800 Mask = Mask.
shl(c2-c1);
3804 Mask = Mask.
lshr(c1-c2);
3809 DAG.getConstant(Mask, VT));
3816 VT.getSizeInBits() -
3817 N1C->getZExtValue()),
3824 SDValue NewSHL = visitShiftByConstant(N, N1C->getZExtValue());
3838 unsigned OpSizeInBits = VT.getScalarType().getSizeInBits();
3841 if (VT.isVector()) {
3842 SDValue FoldedVOp = SimplifyVBinOp(N);
3843 if (FoldedVOp.
getNode())
return FoldedVOp;
3848 return DAG.FoldConstantArithmetic(
ISD::SRA, VT, N0C, N1C);
3856 if (N1C && N1C->getZExtValue() >= OpSizeInBits)
3857 return DAG.getUNDEF(VT);
3859 if (N1C && N1C->isNullValue())
3864 unsigned LowBits = OpSizeInBits - (
unsigned)N1C->getZExtValue();
3869 if ((!LegalOperations ||
3878 unsigned Sum = N1C->getZExtValue() + C1->
getZExtValue();
3879 if (Sum >= OpSizeInBits) Sum = OpSizeInBits-1;
3881 DAG.getConstant(Sum, N1C->getValueType(0)));
3897 OpSizeInBits - N1C->getZExtValue());
3899 signed ShiftAmt = N1C->getZExtValue() - N01C->
getZExtValue();
3905 if ((ShiftAmt > 0) &&
3908 TLI.isTruncateFree(VT, TruncVT)) {
3910 SDValue Amt = DAG.getConstant(ShiftAmt,
3924 N1.getOperand(0).getOpcode() ==
ISD::AND &&
3925 N1.hasOneUse() && N1.getOperand(0).hasOneUse()) {
3928 EVT TruncVT = N1.getValueType();
3938 DAG.getConstant(TruncC, TruncVT)));
3957 DAG.getConstant(LargeShiftAmt->
getZExtValue() + N1C->getZExtValue(),
3971 if (DAG.SignBitIsZero(N0))
3975 SDValue NewSRA = visitShiftByConstant(N, N1C->getZExtValue());
3989 unsigned OpSizeInBits = VT.getScalarType().getSizeInBits();
3992 if (VT.isVector()) {
3993 SDValue FoldedVOp = SimplifyVBinOp(N);
3994 if (FoldedVOp.
getNode())
return FoldedVOp;
3999 return DAG.FoldConstantArithmetic(
ISD::SRL, VT, N0C, N1C);
4004 if (N1C && N1C->getZExtValue() >= OpSizeInBits)
4005 return DAG.getUNDEF(VT);
4007 if (N1C && N1C->isNullValue())
4010 if (N1C && DAG.MaskedValueIsZero(
SDValue(N, 0),
4012 return DAG.getConstant(0, VT);
4017 uint64_t c1 = cast<ConstantSDNode>(N0.
getOperand(1))->getZExtValue();
4018 uint64_t c2 = N1C->getZExtValue();
4019 if (c1 + c2 >= OpSizeInBits)
4020 return DAG.getConstant(0, VT);
4031 uint64_t c2 = N1C->getZExtValue();
4036 if (c1 + OpSizeInBits == InnerShiftSize) {
4037 if (c1 + c2 >= InnerShiftSize)
4038 return DAG.getConstant(0, VT);
4042 DAG.getConstant(c1 + c2, ShiftCountVT)));
4051 DAG.getConstant(~0ULL >> ShAmt, VT));
4059 return DAG.getUNDEF(VT);
4061 if (!LegalTypes || TLI.isTypeDesirableForOp(
ISD::SRL, SmallVT)) {
4062 uint64_t ShiftAmt = N1C->getZExtValue();
4066 AddToWorkList(SmallShift.
getNode());
4070 DAG.getConstant(Mask, VT));
4076 if (N1C && N1C->getZExtValue() + 1 == VT.getSizeInBits()) {
4083 N1C->getAPIntValue() ==
Log2_32(VT.getSizeInBits())) {
4084 APInt KnownZero, KnownOne;
4085 DAG.ComputeMaskedBits(N0.
getOperand(0), KnownZero, KnownOne);
4089 if (KnownOne.
getBoolValue())
return DAG.getConstant(0, VT);
4093 APInt UnknownBits = ~KnownZero;
4094 if (UnknownBits == 0)
return DAG.getConstant(1, VT);
4097 if ((UnknownBits & (UnknownBits - 1)) == 0) {
4112 Op, DAG.getConstant(1, VT));
4132 DAG.getConstant(TruncC, TruncVT)));
4142 SDValue NewSRL = visitShiftByConstant(N, N1C->getZExtValue());
4148 SDValue NarrowLoad = ReduceLoadWidth(N);
4189 if (isa<ConstantSDNode>(N0))
4199 if (isa<ConstantSDNode>(N0))
4209 if (isa<ConstantSDNode>(N0))
4219 if (isa<ConstantSDNode>(N0))
4229 if (isa<ConstantSDNode>(N0))
4254 if (VT ==
MVT::i1 && N1C && N1C->getAPIntValue() == 1)
4257 if (VT.isInteger() &&
4260 TLI.getBooleanContents(
false) ==
4262 N1C && N2C && N1C->isNullValue() && N2C->getAPIntValue() == 1) {
4266 N0, DAG.getConstant(1, VT0));
4268 N0, DAG.getConstant(1, VT0));
4269 AddToWorkList(XORNode.
getNode());
4275 if (VT == VT0 && VT ==
MVT::i1 && N1C && N1C->isNullValue()) {
4277 AddToWorkList(NOTNode.
getNode());
4281 if (VT == VT0 && VT ==
MVT::i1 && N2C && N2C->getAPIntValue() == 1) {
4283 AddToWorkList(NOTNode.
getNode());
4287 if (VT ==
MVT::i1 && N2C && N2C->isNullValue())
4291 if (VT ==
MVT::i1 && (N0 == N1 || (N1C && N1C->getAPIntValue() == 1)))
4295 if (VT ==
MVT::i1 && (N0 == N2 || (N2C && N2C->getAPIntValue() == 0)))
4299 if (SimplifySelectOps(N, N1, N2))
4313 return SimplifySelect(
SDLoc(N), N0, N1, N2);
4333 return std::make_pair(Lo, Hi);
4367 AddToWorkList(Shift.
getNode());
4369 return DAG.getNode(
ISD::XOR, DL, VT, Add, Shift);
4381 if (TLI.getTypeAction(*DAG.getContext(), VT) !=
4387 llvm::tie(LL, LH) = DAG.SplitVectorOperand(N, 1);
4388 llvm::tie(RL, RH) = DAG.SplitVectorOperand(N, 2);
4418 N0, N1, CC,
SDLoc(N),
false);
4423 if (!SCCC->isNullValue())
4437 if (SimplifySelectOps(N, N2, N3))
4441 return SimplifySelectCC(
SDLoc(N), N0, N1, N2, N3, CC);
4446 cast<CondCodeSDNode>(N->
getOperand(2))->
get(),
4458 bool HasCopyToRegUses =
false;
4466 if (UI.getUse().getResNo() != N0.
getResNo())
4475 for (
unsigned i = 0; i != 2; ++i) {
4479 if (!isa<ConstantSDNode>(UseOp))
4493 HasCopyToRegUses =
true;
4496 if (HasCopyToRegUses) {
4497 bool BothLiveOut =
false;
4500 SDUse &Use = UI.getUse();
4509 return ExtendNodes.
size();
4518 for (
unsigned i = 0, e = SetCCs.
size(); i != e; ++i) {
4519 SDNode *SetCC = SetCCs[i];
4522 for (
unsigned j = 0; j != 2; ++j) {
4532 &Ops[0], Ops.
size()));
4541 if (isa<ConstantSDNode>(N0))
4557 CombineTo(N0.
getNode(), NarrowLoad);
4570 unsigned NumSignBits = DAG.ComputeNumSignBits(Op);
4572 if (OpBits == DestBits) {
4575 if (NumSignBits > DestBits-MidBits)
4577 }
else if (OpBits < DestBits) {
4580 if (NumSignBits > OpBits-MidBits)
4585 if (NumSignBits > OpBits-MidBits)
4592 if (OpBits < DestBits)
4594 else if (OpBits > DestBits)
4606 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
4608 bool DoXform =
true;
4618 CombineTo(N, ExtLoad);
4622 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
4634 if ((!LegalOperations && !LN0->
isVolatile()) ||
4640 CombineTo(N, ExtLoad);
4656 (!LegalOperations && TLI.isOperationLegal(N0.
getOpcode(), VT))) {
4659 bool DoXform =
true;
4672 ExtLoad, DAG.getConstant(Mask, VT));
4678 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
4688 if (VT.
isVector() && !LegalOperations &&
4689 TLI.getBooleanContents(
true) ==
4705 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
4711 if (SVT == MatchingVectorType) {
4712 SDValue VsetCC = DAG.getSetCC(
SDLoc(N), MatchingVectorType,
4714 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
4715 return DAG.getSExtOrTrunc(VsetCC,
SDLoc(N), VT);
4725 NegOne, DAG.getConstant(0, VT),
4726 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true);
4727 if (SCC.
getNode())
return SCC;
4729 (!LegalOperations ||
4731 return DAG.getSelect(
SDLoc(N), VT,
4732 DAG.getSetCC(
SDLoc(N),
4735 cast<CondCodeSDNode>(N0.
getOperand(2))->
get()),
4736 NegOne, DAG.getConstant(0, VT));
4742 DAG.SignBitIsZero(N0))
4771 if (COp0 && COp0->isNullValue())
4773 else if (COp1 && COp1->isNullValue())
4791 if (isa<ConstantSDNode>(N0))
4806 APInt TruncatedBits =
4813 if (TruncatedBits == (KnownZero & TruncatedBits)) {
4830 CombineTo(N0.
getNode(), NarrowLoad);
4840 (!LegalOperations || TLI.isOperationLegal(
ISD::AND, VT))) {
4848 CombineTo(N0.
getNode(), NarrowLoad);
4863 return DAG.getZeroExtendInReg(Op,
SDLoc(N),
4884 X, DAG.getConstant(Mask, VT));
4892 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
4894 bool DoXform =
true;
4904 CombineTo(N, ExtLoad);
4909 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
4922 (!LegalOperations && TLI.isOperationLegal(N0.
getOpcode(), VT))) {
4925 bool DoXform =
true;
4938 ExtLoad, DAG.getConstant(Mask, VT));
4944 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
4957 if ((!LegalOperations && !LN0->
isVolatile()) ||
4963 CombineTo(N, ExtLoad);
4973 if (!LegalOperations && VT.
isVector()) {
4979 DAG.getConstant(1, EltVT));
4989 cast<CondCodeSDNode>(N0.
getOperand(2))->
get()),
4991 &OneOps[0], OneOps.size()));
4996 EVT MatchingElementType =
4999 EVT MatchingVectorType =
5005 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
5007 DAG.getSExtOrTrunc(VsetCC,
SDLoc(N), VT),
5009 &OneOps[0], OneOps.size()));
5015 DAG.getConstant(1, VT), DAG.getConstant(0, VT),
5016 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true);
5017 if (SCC.
getNode())
return SCC;
5026 unsigned ShAmtVal = cast<ConstantSDNode>(ShAmt)->getZExtValue();
5033 if (ShAmtVal > KnownZeroBits)
5043 return DAG.getNode(N0.
getOpcode(), DL, VT,
5056 if (isa<ConstantSDNode>(N0))
5073 CombineTo(N0.
getNode(), NarrowLoad);
5107 X, DAG.getConstant(Mask, VT));
5115 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
5117 bool DoXform =
true;
5127 CombineTo(N, ExtLoad);
5131 ExtendSetCCUses(SetCCs, Trunc, ExtLoad,
SDLoc(N),
5148 CombineTo(N, ExtLoad);
5159 if (VT.
isVector() && !LegalOperations) {
5169 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
5174 EVT MatchingElementType =
5177 EVT MatchingVectorType =
5183 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
5184 return DAG.getSExtOrTrunc(VsetCC,
SDLoc(N), VT);
5191 DAG.getConstant(1, VT), DAG.getConstant(0, VT),
5192 cast<CondCodeSDNode>(N0.
getOperand(2))->
get(),
true);
5208 assert(CV != 0 &&
"Const value should be ConstSDNode.");
5210 APInt NewVal = CVal & Mask;
5218 if (DAG.MaskedValueIsZero(V.
getOperand(0), Mask))
5220 if (DAG.MaskedValueIsZero(V.
getOperand(1), Mask))
5229 unsigned Amt = RHSC->getZExtValue();
5232 if (Amt >= Mask.getBitWidth())
break;
5233 APInt NewMask = Mask << Amt;
5264 ExtVT = cast<VTSDNode>(N->
getOperand(1))->getVT();
5274 if (LegalOperations && !TLI.isLoadExtLegal(ExtType, ExtVT))
5289 if ((ShAmt & (EVTBits-1)) == 0) {
5297 if (!isa<LoadSDNode>(N0))
return SDValue();
5302 if (cast<LoadSDNode>(N0)->getExtensionType() ==
ISD::SEXTLOAD)
5308 if (ShAmt >= cast<LoadSDNode>(N0)->getMemoryVT().getSizeInBits())
5315 unsigned ShLeftAmt = 0;
5317 ExtVT == VT && TLI.isNarrowingProfitable(N0.
getValueType(), VT)) {
5326 if (!isa<LoadSDNode>(N0) || !N0.
hasOneUse())
5361 if (TLI.isBigEndian()) {
5364 ShAmt = LVTStoreBits - EVTStoreBits - ShAmt;
5367 uint64_t PtrOff = ShAmt / 8;
5371 DAG.getConstant(PtrOff, PtrType));
5372 AddToWorkList(NewPtr.getNode());
5381 Load = DAG.getExtLoad(ExtType,
SDLoc(N0), VT, LN0->
getChain(),NewPtr,
5387 WorkListRemover DeadNodes(*
this);
5392 if (ShLeftAmt != 0) {
5401 Result = DAG.getConstant(0, VT);
5404 Result, DAG.getConstant(ShLeftAmt, ShImmTy));
5415 EVT EVT = cast<VTSDNode>(N1)->getVT();
5424 if (DAG.ComputeNumSignBits(N0) >= VTBits-EVTBits+1)
5445 return DAG.getZeroExtendInReg(N0,
SDLoc(N), EVT);
5454 SDValue NarrowLoad = ReduceLoadWidth(N);
5463 if (ShAmt->getZExtValue()+EVTBits <= VTBits) {
5466 unsigned InSignBits = DAG.ComputeNumSignBits(N0.
getOperand(0));
5467 if (VTBits-(ShAmt->getZExtValue()+EVTBits) < InSignBits)
5476 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
5477 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
5484 CombineTo(N, ExtLoad);
5485 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
5486 AddToWorkList(ExtLoad.getNode());
5492 EVT == cast<LoadSDNode>(N0)->getMemoryVT() &&
5493 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
5500 CombineTo(N, ExtLoad);
5501 CombineTo(N0.
getNode(), ExtLoad, ExtLoad.getValue(1));
5520 bool isLE = TLI.isLittleEndian();
5526 if (isa<ConstantSDNode>(N0))
5558 LegalTypes && !LegalOperations && N0->
hasOneUse()) {
5571 if (isa<ConstantSDNode>(EltNo) &&
isTypeLegal(NVT)) {
5572 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
5573 EVT IndexTy = TLI.getVectorIdxTy();
5574 int Index = isLE ? (Elt*SizeRatio) : (Elt*SizeRatio + (SizeRatio-1));
5581 DAG.getConstant(Index, IndexTy));
5599 if (BuildVectEltTy == TruncVecEltTy) {
5603 unsigned TruncEltOffset = BuildVecNumElts / TruncVecNumElts;
5605 assert((BuildVecNumElts % TruncVecNumElts) == 0 &&
5606 "Invalid number of elements");
5609 for (
unsigned i = 0, e = BuildVecNumElts; i != e; i += TruncEltOffset)
5631 if (!LegalTypes || TLI.isTypeDesirableForOp(N0.
getOpcode(), VT)) {
5632 SDValue Reduced = ReduceLoadWidth(N);
5642 unsigned NumDefs = 0;
5660 return DAG.getUNDEF(VT);
5663 assert(V.
getNode() &&
"The single defined operand is empty!");
5665 for (
unsigned i = 0, e = VTs.
size(); i != e; ++i) {
5672 Opnds.push_back(NV);
5675 &Opnds[0], Opnds.size());
5696 SDValue DAGCombiner::CombineConsecutiveLoads(
SDNode *N, EVT VT) {
5702 LD1->getPointerInfo().getAddrSpace() !=
5703 LD2->getPointerInfo().getAddrSpace())
5705 EVT LD1VT = LD1->getValueType(0);
5711 !LD1->isVolatile() &&
5712 !LD2->isVolatile() &&
5713 DAG.isConsecutiveLoad(LD2, LD1, LD1VT.
getSizeInBits()/8, 1)) {
5714 unsigned Align = LD1->getAlignment();
5715 unsigned NewAlign = TLI.getDataLayout()->
5718 if (NewAlign <= Align &&
5719 (!LegalOperations || TLI.isOperationLegal(
ISD::LOAD, VT)))
5720 return DAG.getLoad(VT,
SDLoc(N), LD1->getChain(),
5721 LD1->getBasePtr(), LD1->getPointerInfo(),
5722 false,
false,
false,
Align);
5739 bool isSimple =
true;
5750 "Element type of vector ValueType must not be vector!");
5752 return ConstantFoldBITCASTofBUILD_VECTOR(N0.
getNode(), DestEltVT);
5756 if (isa<ConstantSDNode>(N0) || isa<ConstantFPSDNode>(N0)) {
5759 if (!LegalOperations ||
5768 DAG.DeleteNode(Res.
getNode());
5781 !cast<LoadSDNode>(N0)->isVolatile() &&
5782 (!LegalOperations || TLI.isOperationLegal(
ISD::LOAD, VT)) &&
5785 unsigned Align = TLI.getDataLayout()->
5789 if (Align <= OrigAlign) {
5813 AddToWorkList(NewConv.
getNode());
5818 NewConv, DAG.getConstant(SignBit, VT));
5821 NewConv, DAG.getConstant(~SignBit, VT));
5840 if (OrigXWidth < VTWidth) {
5843 }
else if (OrigXWidth > VTWidth) {
5848 DAG.getConstant(OrigXWidth-VTWidth, X.
getValueType()));
5851 AddToWorkList(X.getNode());
5856 X, DAG.getConstant(SignBit, VT));
5857 AddToWorkList(X.getNode());
5862 Cst, DAG.getConstant(~SignBit, VT));
5863 AddToWorkList(Cst.getNode());
5881 return CombineConsecutiveLoads(N, VT);
5888 ConstantFoldBITCASTofBUILD_VECTOR(
SDNode *BV, EVT DstEltVT) {
5892 if (SrcEltVT == DstEltVT)
return SDValue(BV, 0);
5899 if (SrcBitSize == DstBitSize) {
5922 &Ops[0], Ops.
size());
5931 assert((SrcEltVT ==
MVT::f32 || SrcEltVT ==
MVT::f64) &&
"Unknown FP VT!");
5933 BV = ConstantFoldBITCASTofBUILD_VECTOR(BV, IntVT).getNode();
5940 assert((DstEltVT ==
MVT::f32 || DstEltVT ==
MVT::f64) &&
"Unknown FP VT!");
5942 SDNode *Tmp = ConstantFoldBITCASTofBUILD_VECTOR(BV, TmpVT).
getNode();
5945 return ConstantFoldBITCASTofBUILD_VECTOR(Tmp, DstEltVT);
5951 if (SrcBitSize < DstBitSize) {
5952 unsigned NumInputsPerOutput = DstBitSize/SrcBitSize;
5955 for (
unsigned i = 0, e = BV->getNumOperands(); i != e;
5956 i += NumInputsPerOutput) {
5957 bool isLE = TLI.isLittleEndian();
5959 bool EltIsUndef =
true;
5960 for (
unsigned j = 0; j != NumInputsPerOutput; ++j) {
5962 NewBits <<= SrcBitSize;
5967 NewBits |= cast<ConstantSDNode>(Op)->getAPIntValue().
5968 zextOrTrunc(SrcBitSize).
zext(DstBitSize);
5974 Ops.
push_back(DAG.getConstant(NewBits, DstEltVT));
5979 &Ops[0], Ops.
size());
5985 unsigned NumOutputsPerInput = SrcBitSize/DstBitSize;
5987 NumOutputsPerInput*BV->getNumOperands());
5990 for (
unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) {
5991 if (BV->getOperand(i).getOpcode() ==
ISD::UNDEF) {
5992 for (
unsigned j = 0; j != NumOutputsPerInput; ++j)
5997 APInt OpVal = cast<ConstantSDNode>(BV->getOperand(i))->
6000 for (
unsigned j = 0; j != NumOutputsPerInput; ++j) {
6002 Ops.push_back(DAG.getConstant(ThisVal, DstEltVT));
6003 if (isS2V && i == 0 && j == 0 && ThisVal.
zext(SrcBitSize) == OpVal)
6007 OpVal = OpVal.
lshr(DstBitSize);
6011 if (TLI.isBigEndian())
6012 std::reverse(Ops.end()-NumOutputsPerInput, Ops.end());
6016 &Ops[0], Ops.size());
6027 if (VT.isVector()) {
6028 SDValue FoldedVOp = SimplifyVBinOp(N);
6029 if (FoldedVOp.
getNode())
return FoldedVOp;
6036 if (N0CFP && !N1CFP)
6039 if (DAG.getTarget().Options.UnsafeFPMath && N1CFP &&
6040 N1CFP->getValueAPF().isZero())
6043 if ((!LegalOperations || TLI.isOperationLegalOrCustom(
ISD::FSUB, VT)) &&
6048 if ((!LegalOperations || TLI.isOperationLegalOrCustom(
ISD::FSUB, VT)) &&
6054 if (DAG.getTarget().Options.UnsafeFPMath && N1CFP &&
6073 if (AllowNewFpConst && DAG.getTarget().Options.UnsafeFPMath &&
6075 return DAG.getConstantFP(0.0, VT);
6078 if (AllowNewFpConst && DAG.getTarget().Options.UnsafeFPMath &&
6080 return DAG.getConstantFP(0.0, VT);
6085 if (DAG.getTarget().Options.UnsafeFPMath &&
6086 TLI.isOperationLegalOrCustom(
ISD::FMUL, VT) &&
6093 if (CFP00 && !CFP01 && N0.
getOperand(1) == N1) {
6096 DAG.getConstantFP(1.0, VT));
6102 if (CFP01 && !CFP00 && N0.
getOperand(0) == N1) {
6105 DAG.getConstantFP(1.0, VT));
6116 DAG.getConstantFP(2.0, VT));
6127 DAG.getConstantFP(2.0, VT));
6138 if (CFP10 && !CFP11 && N1.
getOperand(1) == N0) {
6141 DAG.getConstantFP(1.0, VT));
6147 if (CFP11 && !CFP10 && N1.
getOperand(0) == N0) {
6150 DAG.getConstantFP(1.0, VT));
6162 DAG.getConstantFP(2.0, VT));
6173 DAG.getConstantFP(2.0, VT));
6185 N1, DAG.getConstantFP(3.0, VT));
6194 N0, DAG.getConstantFP(3.0, VT));
6198 if (AllowNewFpConst &&
6205 DAG.getConstantFP(4.0, VT));
6210 DAG.getTarget().Options.UnsafeFPMath) &&
6211 DAG.getTarget().getTargetLowering()->isFMAFasterThanFMulAndFAdd(VT) &&
6212 (!LegalOperations || TLI.isOperationLegalOrCustom(
ISD::FMA, VT))) {
6238 if (VT.isVector()) {
6239 SDValue FoldedVOp = SimplifyVBinOp(N);
6240 if (FoldedVOp.
getNode())
return FoldedVOp;
6247 if (DAG.getTarget().Options.UnsafeFPMath &&
6248 N1CFP && N1CFP->getValueAPF().isZero())
6251 if (DAG.getTarget().Options.UnsafeFPMath &&
6255 if (!LegalOperations || TLI.isOperationLegal(
ISD::FNEG, VT))
6256 return DAG.getNode(
ISD::FNEG, dl, VT, N1);
6260 return DAG.getNode(
ISD::FADD, dl, VT, N0,
6267 if (DAG.getTarget().Options.UnsafeFPMath) {
6269 return DAG.getConstantFP(0.0f, VT);
6276 &DAG.getTarget().Options))
6280 &DAG.getTarget().Options))
6287 DAG.getTarget().Options.UnsafeFPMath) &&
6288 DAG.getTarget().getTargetLowering()->isFMAFasterThanFMulAndFAdd(VT) &&
6289 (!LegalOperations || TLI.isOperationLegalOrCustom(
ISD::FMA, VT))) {
6293 return DAG.getNode(
ISD::FMA, dl, VT,
6300 return DAG.getNode(
ISD::FMA, dl, VT,
6312 DAG.getNode(
ISD::FNEG, dl, VT, N00), N01,
6329 if (VT.isVector()) {
6330 SDValue FoldedVOp = SimplifyVBinOp(N);
6331 if (FoldedVOp.
getNode())
return FoldedVOp;
6338 if (N0CFP && !N1CFP)
6341 if (DAG.getTarget().Options.UnsafeFPMath &&
6342 N1CFP && N1CFP->getValueAPF().isZero())
6345 if (DAG.getTarget().Options.UnsafeFPMath &&
6349 if (N1CFP && N1CFP->isExactlyValue(1.0))
6352 if (N1CFP && N1CFP->isExactlyValue(+2.0))
6355 if (N1CFP && N1CFP->isExactlyValue(-1.0))
6361 &DAG.getTarget().Options)) {
6363 &DAG.getTarget().Options)) {
6366 if (LHSNeg == 2 || RHSNeg == 2)
6374 if (DAG.getTarget().Options.UnsafeFPMath &&
6393 if (DAG.getTarget().Options.UnsafeFPMath) {
6394 if (N0CFP && N0CFP->
isZero())
6396 if (N1CFP && N1CFP->isZero())
6401 if (N1CFP && N1CFP->isExactlyValue(1.0))
6405 if (N0CFP && !N1CFP)
6409 if (DAG.getTarget().Options.UnsafeFPMath && N1CFP &&
6413 return DAG.getNode(
ISD::FMUL, dl, VT, N0,
6419 if (DAG.getTarget().Options.UnsafeFPMath &&
6422 return DAG.getNode(
ISD::FMA, dl, VT,
6431 if (N1CFP->isExactlyValue(1.0))
6432 return DAG.getNode(
ISD::FADD, dl, VT, N0, N2);
6434 if (N1CFP->isExactlyValue(-1.0) &&
6437 AddToWorkList(RHSNeg.
getNode());
6438 return DAG.getNode(
ISD::FADD, dl, VT, N2, RHSNeg);
6443 if (DAG.getTarget().Options.UnsafeFPMath && N1CFP && N0 == N2)
6444 return DAG.getNode(
ISD::FMUL, dl, VT, N0,
6446 N1, DAG.getConstantFP(1.0, VT)));
6449 if (DAG.getTarget().Options.UnsafeFPMath && N1CFP &&
6451 return DAG.getNode(
ISD::FMUL, dl, VT, N0,
6453 N1, DAG.getConstantFP(-1.0, VT)));
6468 if (VT.isVector()) {
6469 SDValue FoldedVOp = SimplifyVBinOp(N);
6470 if (FoldedVOp.
getNode())
return FoldedVOp;
6478 if (N1CFP && DAG.getTarget().Options.UnsafeFPMath) {
6480 APFloat N1APF = N1CFP->getValueAPF();
6486 (!LegalOperations ||
6493 DAG.getConstantFP(Recip, VT));
6498 &DAG.getTarget().Options)) {
6500 &DAG.getTarget().Options)) {
6503 if (LHSNeg == 2 || RHSNeg == 2)
6538 const APFloat& V = N1CFP->getValueAPF();
6586 (!LegalOperations ||
6595 if (DAG.SignBitIsZero(N0))
6608 (!LegalOperations ||
6612 DAG.getConstantFP(-1.0, VT) , DAG.getConstantFP(0.0, VT),
6621 (!LegalOperations ||
6625 DAG.getConstantFP(1.0, VT) , DAG.getConstantFP(0.0, VT),
6643 (!LegalOperations ||
6652 if (DAG.SignBitIsZero(N0))
6665 (!LegalOperations ||
6669 DAG.getConstantFP(1.0, VT), DAG.getConstantFP(0.0, VT),
6722 DAG.getIntPtrConstant(IsTrunc));
6740 EVT EVT = cast<VTSDNode>(N->
getOperand(1))->getVT();
6780 ((!LegalOperations && !cast<LoadSDNode>(N0)->isVolatile()) ||
6787 CombineTo(N, ExtLoad);
6791 ExtLoad.getValue(1));
6803 SDValue FoldedVOp = SimplifyVUnaryOp(N);
6804 if (FoldedVOp.
getNode())
return FoldedVOp;
6808 &DAG.getTarget().Options))
6882 if (VT.isVector()) {
6883 SDValue FoldedVOp = SimplifyVUnaryOp(N);
6884 if (FoldedVOp.
getNode())
return FoldedVOp;
6975 const APInt &AndConst = cast<ConstantSDNode>(AndOp1)->getAPIntValue();
6978 cast<ConstantSDNode>(Op1)->getAPIntValue()==AndConst.
logBase2()) {
6980 DAG.getSetCC(
SDLoc(N),
6989 CombineTo(N, NewBRCond,
false);
6992 removeFromWorkList(Trunc);
6993 DAG.DeleteNode(Trunc);
6996 WorkListRemover DeadNodes(*
this);
6997 DAG.ReplaceAllUsesOfValueWith(N1, SetCC);
6998 removeFromWorkList(N1.
getNode());
7018 SDValue Tmp = visitXOR(TheXor);
7020 if (Tmp.
getNode() != TheXor) {
7023 dbgs() <<
"\nWith: ";
7026 WorkListRemover DeadNodes(*
this);
7027 DAG.ReplaceAllUsesOfValueWith(N1, Tmp);
7028 removeFromWorkList(TheXor);
7029 DAG.DeleteNode(TheXor);
7043 if (RHSCI->getAPIntValue() == 1 && Op0.
hasOneUse() &&
7057 WorkListRemover DeadNodes(*
this);
7058 DAG.ReplaceAllUsesOfValueWith(N1, SetCC);
7059 removeFromWorkList(N1.
getNode());
7083 CondLHS, CondRHS, CC->
get(),
SDLoc(N),
7104 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(Use)) {
7109 if (
ST->isIndexed() ||
ST->getBasePtr().getNode() !=
N)
7111 VT =
ST->getValue().getValueType();
7144 bool DAGCombiner::CombineToPreIndexedLoadStore(
SDNode *N) {
7151 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
7160 if (
ST->isIndexed())
7162 VT =
ST->getMemoryVT();
7166 Ptr =
ST->getBasePtr();
7188 bool Swapped =
false;
7189 if (isa<ConstantSDNode>(BasePtr)) {
7195 if (isa<ConstantSDNode>(Offset) &&
7196 cast<ConstantSDNode>(Offset)->isNullValue())
7209 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
7214 SDValue Val = cast<StoreSDNode>(
N)->getValue();
7223 if (isa<ConstantSDNode>(Offset))
7242 "Use of ADD/SUB but not an operand");
7244 if (!isa<ConstantSDNode>(Op1)) {
7262 bool RealUse =
false;
7288 BasePtr, Offset, AM);
7291 BasePtr, Offset, AM);
7296 dbgs() <<
"\nWith: ";
7299 WorkListRemover DeadNodes(*
this);
7314 for (
unsigned i = 0, e = OtherUses.
size(); i != e; ++i) {
7315 unsigned OffsetIdx = 1;
7316 if (OtherUses[i]->getOperand(OffsetIdx).getNode() == BasePtr.
getNode())
7318 assert(OtherUses[i]->getOperand(!OffsetIdx).getNode() ==
7319 BasePtr.
getNode() &&
"Expected BasePtr operand");
7333 cast<ConstantSDNode>(OtherUses[i]->getOperand(OffsetIdx));
7335 APInt Offset0 = CN->getAPIntValue();
7336 APInt Offset1 = cast<ConstantSDNode>(Offset)->getAPIntValue();
7338 X0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 1) ? -1 : 1;
7339 Y0 = (OtherUses[i]->getOpcode() ==
ISD::SUB && OffsetIdx == 0) ? -1 : 1;
7345 APInt CNV = Offset0;
7346 if (X0 < 0) CNV = -CNV;
7347 if (X1 * Y0 * Y1 < 0) CNV = CNV + Offset1;
7348 else CNV = CNV - Offset1;
7351 SDValue NewOp1 = DAG.getConstant(CNV, CN->getValueType(0));
7355 SDLoc(OtherUses[i]),
7357 DAG.ReplaceAllUsesOfValueWith(
SDValue(OtherUses[i], 0), NewUse);
7358 removeFromWorkList(OtherUses[i]);
7359 DAG.DeleteNode(OtherUses[i]);
7363 DAG.ReplaceAllUsesOfValueWith(Ptr, Result.
getValue(isLoad ? 1 : 0));
7364 removeFromWorkList(Ptr.
getNode());
7365 DAG.DeleteNode(Ptr.
getNode());
7375 bool DAGCombiner::CombineToPostIndexedLoadStore(
SDNode *N) {
7382 if (
LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
7391 if (
ST->isIndexed())
7393 VT =
ST->getMemoryVT();
7397 Ptr =
ST->getBasePtr();
7418 if (isa<ConstantSDNode>(Offset) &&
7419 cast<ConstantSDNode>(Offset)->isNullValue())
7429 if (isa<FrameIndexSDNode>(BasePtr) || isa<RegisterSDNode>(BasePtr))
7433 bool TryNext =
false;
7443 bool RealUse =
false;
7445 EEE = Use->
use_end(); III != EEE; ++III) {
7465 BasePtr, Offset, AM)
7467 BasePtr, Offset, AM);
7472 dbgs() <<
"\nWith: ";
7475 WorkListRemover DeadNodes(*
this);
7487 DAG.ReplaceAllUsesOfValueWith(
SDValue(Op, 0),
7489 removeFromWorkList(Op);
7519 dbgs() <<
"\nWith chain: ";
7520 Chain.getNode()->dump(&DAG);
7522 WorkListRemover DeadNodes(*
this);
7523 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1), Chain);
7526 removeFromWorkList(N);
7539 dbgs() <<
"\nWith: ";
7541 dbgs() <<
" and 2 other values\n");
7542 WorkListRemover DeadNodes(*
this);
7543 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 0), Undef);
7544 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1),
7546 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 2), Chain);
7547 removeFromWorkList(N);
7563 return CombineTo(N, Chain.
getOperand(1), Chain);
7569 if (
unsigned Align = DAG.InferPtrAlignment(Ptr)) {
7578 return CombineTo(N, NewLoad,
SDValue(NewLoad.
getNode(), 1),
true);
7583 bool UseAA = CombinerAA.getNumOccurrences() > 0 ? CombinerAA :
7587 SDValue BetterChain = FindBetterChain(N, Chain);
7590 if (Chain != BetterChain) {
7609 AddToWorkList(Token.
getNode());
7613 return CombineTo(N, ReplLoad.
getValue(0), Token,
false);
7618 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
7642 struct LoadedSlice {
7650 unsigned CrossRegisterBanksCopies;
7654 Cost(
bool ForCodeSize =
false)
7655 : ForCodeSize(ForCodeSize), Loads(0), Truncates(0),
7656 CrossRegisterBanksCopies(0), ZExts(0), Shift(0) {}
7659 Cost(
const LoadedSlice &
LS,
bool ForCodeSize =
false)
7660 : ForCodeSize(ForCodeSize), Loads(1), Truncates(0),
7661 CrossRegisterBanksCopies(0), ZExts(0), Shift(0) {
7662 EVT TruncType = LS.Inst->getValueType(0);
7663 EVT LoadedType = LS.getLoadedType();
7664 if (TruncType != LoadedType &&
7665 !LS.DAG->getTargetLoweringInfo().isZExtFree(LoadedType, TruncType))
7673 void addSliceGain(
const LoadedSlice &LS) {
7677 LS.Inst->getOperand(0).getValueType()))
7683 if (LS.canMergeExpensiveCrossRegisterBankCopy())
7684 ++CrossRegisterBanksCopies;
7689 Truncates += RHS.Truncates;
7690 CrossRegisterBanksCopies += RHS.CrossRegisterBanksCopies;
7697 return Loads == RHS.Loads && Truncates == RHS.Truncates &&
7698 CrossRegisterBanksCopies == RHS.CrossRegisterBanksCopies &&
7699 ZExts == RHS.ZExts && Shift == RHS.Shift;
7702 bool operator!=(
const Cost &RHS)
const {
return !(*
this == RHS); }
7707 unsigned ExpensiveOpsLHS = Loads + CrossRegisterBanksCopies;
7708 unsigned ExpensiveOpsRHS = RHS.Loads + RHS.CrossRegisterBanksCopies;
7711 if (!ForCodeSize && ExpensiveOpsLHS != ExpensiveOpsRHS)
7712 return ExpensiveOpsLHS < ExpensiveOpsRHS;
7713 return (Truncates + ZExts + Shift + ExpensiveOpsLHS) <
7714 (RHS.Truncates + RHS.ZExts + RHS.Shift + ExpensiveOpsRHS);
7717 bool operator>(
const Cost &RHS)
const {
return RHS < *
this; }
7719 bool operator<=(
const Cost &RHS)
const {
return !(RHS < *
this); }
7721 bool operator>=(
const Cost &RHS)
const {
return !(*
this < RHS); }
7736 : Inst(Inst), Origin(Origin), Shift(Shift), DAG(DAG) {}
7738 LoadedSlice(
const LoadedSlice &LS)
7739 : Inst(LS.Inst), Origin(LS.Origin), Shift(LS.Shift), DAG(LS.DAG) {}
7744 APInt getUsedBits()
const {
7749 assert(Origin &&
"No original load to compare against.");
7750 unsigned BitWidth = Origin->getValueSizeInBits(0);
7751 assert(Inst &&
"This slice is not bound to an instruction");
7752 assert(Inst->getValueSizeInBits(0) <= BitWidth &&
7753 "Extracted slice is bigger than the whole type!");
7754 APInt UsedBits(Inst->getValueSizeInBits(0), 0);
7756 UsedBits = UsedBits.zext(BitWidth);
7762 unsigned getLoadedSize()
const {
7763 unsigned SliceSize = getUsedBits().countPopulation();
7764 assert(!(SliceSize & 0x7) &&
"Size is not a multiple of a byte.");
7765 return SliceSize / 8;
7770 EVT getLoadedType()
const {
7771 assert(DAG &&
"Missing context");
7777 unsigned getAlignment()
const {
7778 unsigned Alignment = Origin->getAlignment();
7779 unsigned Offset = getOffsetFromBase();
7781 Alignment =
MinAlign(Alignment, Alignment + Offset);
7786 bool isLegal()
const {
7788 if (!Origin || !Inst || !DAG)
7792 if (Origin->getOffset().getOpcode() !=
ISD::UNDEF)
7798 EVT SliceType = getLoadedType();
7808 EVT PtrType = Origin->getBasePtr().getValueType();
7821 EVT TruncateType = Inst->getValueType(0);
7822 if (TruncateType != SliceType &&
7832 uint64_t getOffsetFromBase()
const {
7833 assert(DAG &&
"Missing context.");
7835 DAG->getTargetLoweringInfo().getDataLayout()->isBigEndian();
7836 assert(!(Shift & 0x7) &&
"Shifts not aligned on Bytes are not supported.");
7837 uint64_t Offset = Shift / 8;
7839 assert(!(Origin->getValueSizeInBits(0) & 0x7) &&
7840 "The size of the original loaded type is not a multiple of a"
7844 assert(TySizeInBytes > Offset &&
7845 "Invalid shift amount for given loaded size");
7847 Offset = TySizeInBytes - Offset - getLoadedSize();
7858 assert(Inst && Origin &&
"Unable to replace a non-existing slice.");
7859 const SDValue &OldBaseAddr = Origin->getBasePtr();
7860 SDValue BaseAddr = OldBaseAddr;
7862 int64_t Offset =
static_cast<int64_t
>(getOffsetFromBase());
7863 assert(Offset >= 0 &&
"Offset too big to fit in int64_t!");
7867 BaseAddr = DAG->getNode(
ISD::ADD,
SDLoc(Origin), ArithType, BaseAddr,
7868 DAG->getConstant(Offset, ArithType));
7872 EVT SliceType = getLoadedType();
7875 SDValue LastInst = DAG->getLoad(
7876 SliceType,
SDLoc(Origin), Origin->getChain(), BaseAddr,
7877 Origin->getPointerInfo().getWithOffset(Offset), Origin->isVolatile(),
7878 Origin->isNonTemporal(), Origin->isInvariant(), getAlignment());
7881 EVT FinalType = Inst->getValueType(0);
7882 if (SliceType != FinalType)
7892 bool canMergeExpensiveCrossRegisterBankCopy()
const {
7893 if (!Inst || !Inst->hasOneUse())
7898 assert(DAG &&
"Missing context");
7920 if (RequiredAlignment > getAlignment())
7928 if (Inst->getValueType(0) != getLoadedType())
7938 bool operator()(
const LoadedSlice &LHS,
const LoadedSlice &RHS) {
7939 assert(LHS.Origin == RHS.Origin &&
"Different bases not implemented.");
7940 return LHS.getOffsetFromBase() < RHS.getOffsetFromBase();
7964 const LoadedSlice &Second) {
7965 assert(First.Origin == Second.Origin && First.Origin &&
7966 "Unable to match different memory origins.");
7967 APInt UsedBits = First.getUsedBits();
7968 assert((UsedBits & Second.getUsedBits()) == 0 &&
7969 "Slices are not supposed to overlap.");
7970 UsedBits |= Second.getUsedBits();
7979 LoadedSlice::Cost &GlobalLSCost) {
7980 unsigned NumberOfSlices = LoadedSlices.
size();
7982 if (NumberOfSlices < 2)
7988 const TargetLowering &TLI = LoadedSlices[0].DAG->getTargetLoweringInfo();
7991 const LoadedSlice *First = NULL;
7992 const LoadedSlice *Second = NULL;
7993 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice,
7997 Second = &LoadedSlices[CurrSlice];
8004 EVT LoadedType = First->getLoadedType();
8007 if (LoadedType != Second->getLoadedType())
8011 unsigned RequiredAlignment = 0;
8012 if (!TLI.hasPairedLoad(LoadedType, RequiredAlignment)) {
8018 if (RequiredAlignment > First->getAlignment())
8025 assert(GlobalLSCost.Loads > 0 &&
"We save more loads than we created!");
8026 --GlobalLSCost.Loads;
8043 const APInt &UsedBits,
bool ForCodeSize) {
8044 unsigned NumberOfSlices = LoadedSlices.
size();
8045 if (StressLoadSlicing)
8046 return NumberOfSlices > 1;
8049 if (NumberOfSlices != 2)
8057 LoadedSlice::Cost OrigCost(ForCodeSize), GlobalSlicingCost(ForCodeSize);
8060 for (
unsigned CurrSlice = 0; CurrSlice < NumberOfSlices; ++CurrSlice) {
8061 const LoadedSlice &LS = LoadedSlices[CurrSlice];
8063 LoadedSlice::Cost SliceCost(LS, ForCodeSize);
8064 GlobalSlicingCost += SliceCost;
8068 OrigCost.addSliceGain(LS);
8073 return OrigCost > GlobalSlicingCost;
8082 bool DAGCombiner::SliceUpLoad(
SDNode *N) {
8101 UI != UIEnd; ++UI) {
8103 if (UI.getUse().getResNo() != 0)
8112 Shift = cast<ConstantSDNode>(User->
getOperand(1))->getZExtValue();
8130 LoadedSlice
LS(User, LD, Shift, &DAG);
8131 APInt CurrentUsedBits = LS.getUsedBits();
8134 if ((CurrentUsedBits & UsedBits) != 0)
8137 UsedBits |= CurrentUsedBits;
8144 LoadedSlices.push_back(LS);
8159 LSIt = LoadedSlices.
begin(),
8160 LSItEnd = LoadedSlices.end();
8161 LSIt != LSItEnd; ++LSIt) {
8162 SDValue SliceInst = LSIt->loadSlice();
8163 CombineTo(LSIt->Inst, SliceInst,
true);
8167 "It takes more than a zext to get to the loaded slice!!");
8172 &ArgChains[0], ArgChains.
size());
8173 DAG.ReplaceAllUsesOfValueWith(
SDValue(N, 1), Chain);
8180 static std::pair<unsigned, unsigned>
8182 std::pair<unsigned, unsigned> Result(0, 0);
8207 if (!isOk)
return Result;
8219 uint64_t NotMask = ~cast<ConstantSDNode>(V->
getOperand(1))->getSExtValue();
8221 if (NotMaskLZ & 7)
return Result;
8223 if (NotMaskTZ & 7)
return Result;
8224 if (NotMaskLZ == 64)
return Result;
8235 switch (MaskedBytes) {
8239 default:
return Result;
8244 if (NotMaskTZ && NotMaskTZ/8 % MaskedBytes)
return Result;
8246 Result.first = MaskedBytes;
8247 Result.second = NotMaskTZ/8;
8259 unsigned NumBytes = MaskInfo.first;
8260 unsigned ByteShift = MaskInfo.second;
8266 ByteShift*8, (ByteShift+NumBytes)*8);
8273 if (!DC->isTypeLegal(VT))
8288 StOffset = ByteShift;
8296 NewAlign =
MinAlign(NewAlign, StOffset);
8305 false,
false, NewAlign).getNode();
8334 std::pair<unsigned, unsigned> MaskedLoad;
8336 if (MaskedLoad.first)
8343 if (MaskedLoad.first)
8365 APInt Imm = cast<ConstantSDNode>(N1)->getAPIntValue();
8374 while (NewBW < BitWidth &&
8380 if (NewBW >= BitWidth)
8386 ShAmt = (((ShAmt + NewBW - 1) / NewBW) * NewBW) - NewBW;
8388 std::min(BitWidth, ShAmt + NewBW));
8389 if ((Imm & Mask) == Imm) {
8393 uint64_t PtrOff = ShAmt / 8;
8397 PtrOff = (BitWidth + 7 - NewBW) / 8 - PtrOff;
8413 SDValue NewVal = DAG.getNode(Opc,
SDLoc(Value), NewVT, NewLD,
8414 DAG.getConstant(NewImm, NewVT));
8418 false,
false, NewAlign);
8420 AddToWorkList(NewPtr.
getNode());
8421 AddToWorkList(NewLD.
getNode());
8422 AddToWorkList(NewVal.
getNode());
8423 WorkListRemover DeadNodes(*
this);
8446 if (!VT.isFloatingPoint() ||
8465 if (LDAlign < ABIAlign || STAlign < ABIAlign)
8471 false,
false,
false, LDAlign);
8476 false,
false, STAlign);
8478 AddToWorkList(NewLD.
getNode());
8479 AddToWorkList(NewST.
getNode());
8480 WorkListRemover DeadNodes(*
this);
8511 bool IsIndexSignExt) :
8512 Base(Base), Index(Index), Offset(Offset), IsIndexSignExt(IsIndexSignExt) {}
8515 return Other.
Base == Base && Other.
Index == Index &&
8521 bool IsIndexSignExt =
false;
8531 if (isa<ConstantSDNode>(Ptr->
getOperand(1))) {
8532 int64_t Offset = cast<ConstantSDNode>(Ptr->
getOperand(1))->getSExtValue();
8552 IsIndexSignExt =
true;
8563 if (!isa<ConstantSDNode>(Offset))
8569 IsIndexSignExt =
true;
8570 }
else IsIndexSignExt =
false;
8572 int64_t Off = cast<ConstantSDNode>(Offset)->getSExtValue();
8581 MemNode(N), OffsetFromBase(Offset), SequenceNum(Seq) { }
8599 bool DAGCombiner::MergeConsecutiveStores(
StoreSDNode* St) {
8602 bool NoVectors = DAG.getMachineFunction().getFunction()->getAttributes().
8612 bool IsLoadSrc = isa<LoadSDNode>(StoredVal);
8613 if (!isa<ConstantSDNode>(StoredVal) && !isa<ConstantFPSDNode>(StoredVal) &&
8668 if (
StoreSDNode *St = dyn_cast<StoreSDNode>(Index))
8690 if (
StoreSDNode *STn = dyn_cast<StoreSDNode>(NextInChain)) {
8694 }
else if (
LoadSDNode *Ldn = dyn_cast<LoadSDNode>(NextInChain)) {
8695 if (Ldn->isVolatile()) {
8702 NextInChain = Ldn->getChain().getNode();
8712 if (StoreNodes.
size() < 2)
8716 std::sort(StoreNodes.
begin(), StoreNodes.
end(),
8721 unsigned LastConsecutiveStore = 0;
8722 int64_t StartAddress = StoreNodes[0].OffsetFromBase;
8723 for (
unsigned i = 0, e = StoreNodes.
size(); i < e; ++i) {
8728 int64_t CurrAddress = StoreNodes[i].OffsetFromBase;
8729 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
8735 for (
unsigned ld = 0, lde = AliasLoadNodes.
size(); ld < lde; ++ld)
8736 if (isAlias(AliasLoadNodes[ld], StoreNodes[i].MemNode)) {
8745 LastConsecutiveStore = i;
8753 unsigned LastLegalType = 0;
8754 unsigned LastLegalVectorType = 0;
8755 bool NonZero =
false;
8756 for (
unsigned i=0; i<LastConsecutiveStore+1; ++i) {
8757 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
8761 NonZero |= !
C->isNullValue();
8763 NonZero |= !
C->getConstantFPValue()->isNullValue();
8770 unsigned StoreBW = (i+1) * ElementSizeBytes * 8;
8773 LastLegalType = i+1;
8777 EVT LegalizedStoredValueTy =
8780 LastLegalType = i+1;
8786 LastLegalVectorType = i + 1;
8791 if (NonZero || NoVectors)
8792 LastLegalVectorType = 0;
8795 if (LastLegalType == 0 && LastLegalVectorType == 0)
8798 bool UseVector = (LastLegalVectorType > LastLegalType) && !NoVectors;
8799 unsigned NumElem = UseVector ? LastLegalVectorType : LastLegalType;
8805 unsigned EarliestNodeUsed = 0;
8806 for (
unsigned i=0; i < NumElem; ++i) {
8811 if (StoreNodes[i].SequenceNum > StoreNodes[EarliestNodeUsed].SequenceNum)
8812 EarliestNodeUsed = i;
8816 LSBaseSDNode *EarliestOp = StoreNodes[EarliestNodeUsed].MemNode;
8817 SDLoc DL(StoreNodes[0].MemNode);
8823 assert(TLI.
isTypeLegal(Ty) &&
"Illegal vector store");
8824 StoredVal = DAG.getConstant(0, Ty);
8826 unsigned StoreBW = NumElem * ElementSizeBytes * 8;
8827 APInt StoreInt(StoreBW, 0);
8832 for (
unsigned i = 0; i < NumElem ; ++i) {
8833 unsigned Idx = IsLE ?(NumElem - 1 - i) : i;
8834 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[Idx].MemNode);
8836 StoreInt<<=ElementSizeBytes*8;
8838 StoreInt|=
C->getAPIntValue().zext(StoreBW);
8840 StoreInt|=
C->getValueAPF().bitcastToAPInt().zext(StoreBW);
8842 assert(
false &&
"Invalid constant element type");
8848 StoredVal = DAG.getConstant(StoreInt, StoreTy);
8851 SDValue NewStore = DAG.getStore(EarliestOp->
getChain(), DL, StoredVal,
8858 CombineTo(EarliestOp, NewStore);
8860 for (
unsigned i = 0; i < NumElem ; ++i) {
8861 if (StoreNodes[i].MemNode == EarliestOp)
8863 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
8876 removeFromWorkList(St);
8893 for (
unsigned i=0; i<LastConsecutiveStore+1; ++i) {
8894 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
8899 if (!Ld->hasNUsesOfValue(1, 0))
8907 if (Ld->isVolatile() || Ld->isIndexed())
8915 if (Ld->getMemoryVT() != MemVT)
8933 if (LoadNodes.
size() < 2)
8939 unsigned LastConsecutiveLoad = 0;
8941 unsigned LastLegalVectorType = 0;
8942 unsigned LastLegalIntegerType = 0;
8943 StartAddress = LoadNodes[0].OffsetFromBase;
8944 SDValue FirstChain = LoadNodes[0].MemNode->getChain();
8945 for (
unsigned i = 1; i < LoadNodes.
size(); ++i) {
8947 if (LoadNodes[i].MemNode->getChain() != FirstChain)
8950 int64_t CurrAddress = LoadNodes[i].OffsetFromBase;
8951 if (CurrAddress - StartAddress != (ElementSizeBytes * i))
8953 LastConsecutiveLoad = i;
8958 LastLegalVectorType = i + 1;
8961 unsigned StoreBW = (i+1) * ElementSizeBytes * 8;
8964 LastLegalIntegerType = i + 1;
8968 EVT LegalizedStoredValueTy =
8974 LastLegalIntegerType = i+1;
8980 bool UseVectorTy = LastLegalVectorType > LastLegalIntegerType && !NoVectors;
8981 unsigned LastLegalType = std::max(LastLegalVectorType, LastLegalIntegerType);
8985 unsigned NumElem = std::min(LastConsecutiveStore, LastConsecutiveLoad) + 1;
8986 NumElem = std::min(LastLegalType, NumElem);
8992 unsigned EarliestNodeUsed = 0;
8993 LSBaseSDNode *EarliestOp = StoreNodes[EarliestNodeUsed].MemNode;
8994 for (
unsigned i=1; i<NumElem; ++i) {
8999 if (StoreNodes[i].SequenceNum > StoreNodes[EarliestNodeUsed].SequenceNum)
9000 EarliestNodeUsed = i;
9009 unsigned StoreBW = NumElem * ElementSizeBytes * 8;
9013 SDLoc LoadDL(LoadNodes[0].MemNode);
9014 SDLoc StoreDL(StoreNodes[0].MemNode);
9016 LoadSDNode *FirstLoad = cast<LoadSDNode>(LoadNodes[0].MemNode);
9017 SDValue NewLoad = DAG.getLoad(JointMemOpVT, LoadDL,
9021 false,
false,
false,
9024 SDValue NewStore = DAG.getStore(EarliestOp->
getChain(), StoreDL, NewLoad,
9030 LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[0].MemNode);
9031 DAG.ReplaceAllUsesOfValueWith(
SDValue(Ld, 1),
9032 SDValue(NewLoad.getNode(), 1));
9035 for (
unsigned i = 1; i < NumElem ; ++i) {
9038 LoadSDNode *Ld = cast<LoadSDNode>(LoadNodes[i].MemNode);
9043 CombineTo(EarliestOp, NewStore);
9045 for (
unsigned i = 0; i < NumElem ; ++i) {
9047 if (StoreNodes[i].MemNode == EarliestOp)
9049 StoreSDNode *St = cast<StoreSDNode>(StoreNodes[i].MemNode);
9051 removeFromWorkList(St);
9072 if (Align <= OrigAlign &&
9103 Tmp = DAG.getConstant((uint32_t)CFP->
getValueAPF().
9104 bitcastToAPInt().getZExtValue(),
MVT::i32);
9105 return DAG.getStore(Chain,
SDLoc(N), Tmp,
9115 return DAG.getStore(Chain,
SDLoc(N), Tmp,
9136 isVolatile, isNonTemporal,
9140 Alignment =
MinAlign(Alignment, 4U);
9143 isVolatile, isNonTemporal,
9144 Alignment, TBAAInfo);
9156 if (
unsigned Align = DAG.InferPtrAlignment(Ptr)) {
9158 return DAG.getTruncStore(Chain,
SDLoc(N), Value,
9167 SDValue NewST = TransformFPLoadStorePair(N);
9171 bool UseAA = CombinerAA.getNumOccurrences() > 0 ? CombinerAA :
9175 SDValue BetterChain = FindBetterChain(N, Chain);
9178 if (Chain != BetterChain) {
9183 ReplStore = DAG.getTruncStore(BetterChain,
SDLoc(N), Value, Ptr,
9186 ReplStore = DAG.getStore(BetterChain,
SDLoc(N), Value, Ptr,
9195 AddToWorkList(Token.
getNode());
9198 return CombineTo(N, Token,
false);
9203 if (CombineToPreIndexedLoadStore(N) || CombineToPostIndexedLoadStore(N))
9213 GetDemandedBits(Value,
9217 AddToWorkList(Value.
getNode());
9219 return DAG.getTruncStore(Chain,
SDLoc(N), Shorter,
9233 if (
LoadSDNode *Ld = dyn_cast<LoadSDNode>(Value)) {
9238 Chain.reachesChainWithoutSideEffects(
SDValue(Ld, 1))) {
9257 bool EverChanged =
false;
9263 bool Changed = MergeConsecutiveStores(ST);
9264 EverChanged |= Changed;
9265 if (!Changed)
break;
9272 return ReduceLoadOpStoreWidth(N);
9292 if (!isa<ConstantSDNode>(EltNo))
9294 unsigned Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
9313 if (Elt < Ops.
size()) {
9316 EVT OpVT = Ops[0].getValueType();
9326 VT, &Ops[0], Ops.
size());
9342 return DAG.getSExtOrTrunc(InOp,
SDLoc(InVec), NVT);
9348 bool ConstEltNo = isa<ConstantSDNode>(EltNo);
9356 && ConstEltNo && !LegalOperations) {
9357 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
9365 return DAG.getUNDEF(NVT);
9368 if (OrigElt < NumElem) {
9377 InVec, DAG.getConstant(OrigElt, IndexTy));
9382 if (!LegalOperations)
return SDValue();
9389 int Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
9390 bool NewLoad =
false;
9391 bool BCNumEltsChanged =
false;
9409 BCNumEltsChanged =
true;
9418 LN0 = cast<LoadSDNode>(InVec);
9427 }
else if ((SVN = dyn_cast<ShuffleVectorSDNode>(InVec))) {
9438 if (BCNumEltsChanged)
9443 int Idx = (Elt > (int)NumElems) ? -1 : SVN->
getMaskElt(Elt);
9454 LN0 = cast<LoadSDNode>(InVec);
9455 Elt = (Idx < (int)NumElems) ? Idx : Idx - (int)NumElems;
9466 return DAG.getUNDEF(LVT);
9483 unsigned PtrOff = 0;
9491 DAG.getConstant(PtrOff, PtrType));
9507 Load = DAG.getExtLoad(ExtType,
SDLoc(N), NVT, LN0->
getChain(),
9523 WorkListRemover DeadNodes(*
this);
9526 DAG.ReplaceAllUsesOfValuesWith(From, To, 2);
9529 AddToWorkList(Load.
getNode());
9530 AddUsersToWorkList(Load.
getNode());
9540 SDValue DAGCombiner::reduceBuildVecExtToExtBuildVec(
SDNode *N) {
9560 bool AllAnyExt =
true;
9562 for (
unsigned i = 0; i != NumInScalars; ++i) {
9571 if (!ZeroExt && !AnyExt) {
9583 else if (InTy != SourceType) {
9590 AllAnyExt &= AnyExt;
9597 bool ValidTypes = SourceType !=
MVT::Other &&
9608 assert(ElemRatio > 1 &&
"Invalid element size ratio");
9609 SDValue Filler = AllAnyExt ? DAG.getUNDEF(SourceType):
9610 DAG.getConstant(0, SourceType);
9623 In = DAG.getUNDEF(SourceType);
9626 unsigned Index = isLE ? (i * ElemRatio) :
9627 (i * ElemRatio + (ElemRatio - 1));
9629 assert(Index < Ops.
size() &&
"Invalid index");
9636 "Invalid vector size");
9649 SDValue DAGCombiner::reduceBuildVecConvertToConvertBuildVec(
SDNode *N) {
9657 unsigned NumDefs = 0;
9659 for (
unsigned i = 0; i != NumInScalars; ++i) {
9692 &&
"Should only handle conversion from integer to float.");
9693 assert(SrcVT !=
MVT::Other &&
"Cannot determine source type!");
9701 for (
unsigned i = 0; i != NumInScalars; ++i) {
9710 &Opnds[0], Opnds.
size());
9713 return DAG.getNode(Opcode, dl, VT, BV);
9723 return DAG.getUNDEF(VT);
9725 SDValue V = reduceBuildVecExtToExtBuildVec(N);
9729 V = reduceBuildVecConvertToConvertBuildVec(N);
9738 if (LegalOperations &&
9743 for (
unsigned i = 0; i != NumInScalars; ++i) {
9751 VecIn1 = VecIn2 =
SDValue(0, 0);
9757 if (ExtractedFromVec == VecIn1 || ExtractedFromVec == VecIn2)
9761 VecIn1 = ExtractedFromVec;
9762 }
else if (VecIn2.
getNode() == 0) {
9763 VecIn2 = ExtractedFromVec;
9766 VecIn1 = VecIn2 =
SDValue(0, 0);
9774 for (
unsigned i = 0; i != NumInScalars; ++i) {
9784 unsigned ExtIndex = cast<ConstantSDNode>(ExtVal)->getZExtValue();
9793 unsigned Idx = cast<ConstantSDNode>(ExtVal)->getZExtValue();
9821 VecIn2 = VecIn2.
getNode() ? VecIn2 : DAG.getUNDEF(VT);
9837 return DAG.getVectorShuffle(VT, dl, Ops[0], Ops[1], &Mask[0]);
9856 return DAG.getUNDEF(VT);
9915 unsigned IdentityIndex = i * PartNumElem;
9927 return SingleSource;
9947 assert((Idx % NumElems) == 0 &&
9948 "IDX in concat is not a multiple of the result vector length.");
9969 if (InsIdx && ExtIdx &&
10002 unsigned NumConcats = NumElts / NumElemsPerConcat;
10006 for (
unsigned I = 0;
I != NumConcats; ++
I) {
10008 unsigned Begin =
I * NumElemsPerConcat;
10009 bool AllUndef =
true, NoUndef =
true;
10010 for (
unsigned J = Begin; J != Begin + NumElemsPerConcat; ++J) {
10018 if (SVN->
getMaskElt(Begin) % NumElemsPerConcat != 0)
10021 for (
unsigned J = 1; J != NumElemsPerConcat; ++J)
10025 unsigned FirstElt = SVN->
getMaskElt(Begin) / NumElemsPerConcat;
10031 }
else if (AllUndef) {
10049 assert(N0.
getValueType() == VT &&
"Vector shuffle must be normalized in DAG");
10053 return DAG.getUNDEF(VT);
10060 for (
unsigned i = 0; i != NumElts; ++i) {
10062 if (Idx >= (
int)NumElts) Idx -= NumElts;
10065 return DAG.getVectorShuffle(VT,
SDLoc(N), N0, DAG.getUNDEF(VT),
10072 for (
unsigned i = 0; i != NumElts; ++i) {
10075 if (Idx >= (
int)NumElts)
10082 return DAG.getVectorShuffle(VT,
SDLoc(N), N1, DAG.getUNDEF(VT),
10088 bool Changed =
false;
10090 for (
unsigned i = 0; i != NumElts; ++i) {
10092 if (Idx >= (
int)NumElts) {
10099 return DAG.getVectorShuffle(VT,
SDLoc(N), N0, N1, &NewMask[0]);
10119 "BUILD_VECTOR has wrong number of operands");
10121 bool AllSame =
true;
10122 for (
unsigned i = 0; i != NumElts; ++i) {
10129 if (!Base.getNode())
10131 for (
unsigned i = 0; i != NumElts; ++i) {
10169 "Shuffle types don't match");
10171 for (
unsigned i = 0; i != NumElts; ++i) {
10173 assert(Idx < (
int)NumElts &&
"Index references undef operand");
10180 if (Idx >= 0 && (
unsigned)Idx != i)
10205 for (
unsigned i = 0; i != NumElts; ++i) {
10207 if (!isa<ConstantSDNode>(Elt))
10210 if (cast<ConstantSDNode>(Elt)->isAllOnesValue())
10212 else if (cast<ConstantSDNode>(Elt)->isNullValue())
10226 DAG.getConstant(0, EltVT));
10228 RVT, &ZeroOps[0], ZeroOps.size());
10230 SDValue Shuf = DAG.getVectorShuffle(RVT, dl, LHS, Zero, &Indices[0]);
10241 "SimplifyVBinOp only works on vectors!");
10245 SDValue Shuffle = XformToShuffleWithZero(N);
10246 if (Shuffle.
getNode())
return Shuffle;
10253 for (
unsigned i = 0, e = LHS.getNumOperands(); i != e; ++i) {
10269 cast<ConstantSDNode>(RHSOp.
getNode())->isNullValue()) ||
10271 cast<ConstantFPSDNode>(RHSOp.
getNode())->getValueAPF().isZero()))
10296 AddToWorkList(FoldOp.
getNode());
10299 if (Ops.
size() == LHS.getNumOperands())
10301 LHS.getValueType(), &Ops[0], Ops.
size());
10310 "SimplifyVUnaryOp only works on vectors!");
10319 for (
unsigned i = 0, e = N0.getNumOperands(); i != e; ++i) {
10330 AddToWorkList(FoldOp.
getNode());
10333 if (Ops.
size() != N0.getNumOperands())
10337 N0.getValueType(), &Ops[0], Ops.
size());
10345 cast<CondCodeSDNode>(N0.
getOperand(2))->
get());
10350 if (SCC.getNode()) {
10356 SCC.getOperand(0), SCC.getOperand(1),
10357 SCC.getOperand(4));
10358 AddToWorkList(SETCC.
getNode());
10359 return DAG.getSelect(
SDLoc(SCC), SCC.getValueType(),
10360 SCC.getOperand(2), SCC.getOperand(3),
SETCC);
10374 bool DAGCombiner::SimplifySelectOps(
SDNode *TheSelect,
SDValue LHS,
10411 RLD->getPointerInfo().getAddrSpace() != 0 ||
10423 (RLD->hasAnyUseOfValue(1) && RLD->isPredecessorOf(CondNode)))
10427 RLD->isPredecessorOf(LLD))
10429 Addr = DAG.getSelect(
SDLoc(TheSelect),
10432 RLD->getBasePtr());
10439 (RLD->hasAnyUseOfValue(1) &&
10440 (RLD->isPredecessorOf(CondLHS) || RLD->isPredecessorOf(CondRHS))))
10471 CombineTo(TheSelect, Load);
10489 if (N2 == N3)
return N2;
10498 N0, N1, CC, DL,
false);
10499 if (SCC.getNode()) AddToWorkList(SCC.getNode());
10500 ConstantSDNode *SCCC = dyn_cast_or_null<ConstantSDNode>(SCC.getNode());
10522 N2.getOperand(0) == N3)
10523 return DAG.getNode(
ISD::FABS, DL, VT, N3);
10542 (TV->hasOneUse() || FV->hasOneUse())) {
10543 Constant *Elts[] = {
10544 const_cast<ConstantFP*
>(FV->getConstantFPValue()),
10545 const_cast<ConstantFP*>(TV->getConstantFPValue())
10554 unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
10558 SDValue Zero = DAG.getIntPtrConstant(0);
10560 SDValue One = DAG.getIntPtrConstant(EltSize);
10562 SDValue Cond = DAG.getSetCC(DL,
10565 AddToWorkList(Cond.
getNode());
10568 AddToWorkList(CstOffset.getNode());
10571 AddToWorkList(CPIdx.getNode());
10572 return DAG.getLoad(TV->getValueType(0), DL, DAG.getEntryNode(), CPIdx,
10574 false,
false, Alignment);
10585 EVT AType = N2.getValueType();
10586 if (XType.
bitsGE(AType)) {
10589 if (N2C && ((N2C->getAPIntValue() & (N2C->getAPIntValue()-1)) == 0)) {
10590 unsigned ShCtV = N2C->getAPIntValue().logBase2();
10592 SDValue ShCt = DAG.getConstant(ShCtV,
10596 AddToWorkList(Shift.
getNode());
10598 if (XType.
bitsGT(AType)) {
10600 AddToWorkList(Shift.
getNode());
10603 return DAG.getNode(
ISD::AND, DL, AType, Shift, N2);
10610 AddToWorkList(Shift.
getNode());
10612 if (XType.
bitsGT(AType)) {
10614 AddToWorkList(Shift.
getNode());
10617 return DAG.getNode(
ISD::AND, DL, AType, Shift, N2);
10630 N2C && N2C->isNullValue()) {
10648 return DAG.getNode(
ISD::AND, DL, VT, Shr, N3);
10653 if (N2C && N3C && N3C->isNullValue() && N2C->getAPIntValue().isPowerOf2() &&
10659 if (NotExtCompare && N2C->getAPIntValue() == 1)
10664 if (!LegalOperations ||
10673 Temp = DAG.getZeroExtendInReg(SCC,
SDLoc(N2),
10674 N2.getValueType());
10677 N2.getValueType(), SCC);
10681 N2.getValueType(), SCC);
10684 AddToWorkList(SCC.
getNode());
10685 AddToWorkList(Temp.
getNode());
10687 if (N2C->getAPIntValue() == 1)
10692 ISD::SHL, DL, N2.getValueType(), Temp,
10693 DAG.getConstant(N2C->getAPIntValue().logBase2(),
10701 if (0 && N3C && N3C->isNullValue() && N2C && (N2C->getAPIntValue() == 1ULL)) {
10703 if (!LegalOperations ||
10713 (!LegalOperations ||
10716 return DAG.getNode(
ISD::SRL, DL, XType, Ctlz,
10723 XType, DAG.getConstant(0, XType), N0);
10726 DAG.getNode(
ISD::AND, DL, XType, NegN0, NotN0),
10735 return DAG.getNode(
ISD::XOR, DL, XType, Sign, DAG.getConstant(1, XType));
10750 SubC = dyn_cast<ConstantSDNode>(N3.
getOperand(0));
10754 SubC = dyn_cast<ConstantSDNode>(N2.getOperand(0));
10756 EVT XType = N0.getValueType();
10764 AddToWorkList(Shift.
getNode());
10765 AddToWorkList(Add.
getNode());
10766 return DAG.getNode(
ISD::XOR, DL, XType, Add, Shift);
10776 SDLoc DL,
bool foldBooleans) {
10778 DagCombineInfo(DAG,
Level,
false,
this);
10779 return TLI.
SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL);
10787 std::vector<SDNode*> Built;
10790 for (std::vector<SDNode*>::iterator ii = Built.begin(), ee = Built.end();
10792 AddToWorkList(*ii);
10801 std::vector<SDNode*> Built;
10804 for (std::vector<SDNode*>::iterator ii = Built.begin(), ee = Built.end();
10806 AddToWorkList(*ii);
10816 Base = Ptr; Offset = 0; GV = 0; CV = 0;
10822 Offset +=
C->getZExtValue();
10830 GV =
G->getGlobal();
10831 Offset +=
G->getOffset();
10839 CV =
C->isMachineConstantPoolEntry() ? (
const void *)
C->getMachineCPVal()
10840 : (
const void *)
C->getConstVal();
10841 Offset +=
C->getOffset();
10845 return isa<FrameIndexSDNode>(Base);
10850 bool DAGCombiner::isAlias(
SDValue Ptr1, int64_t Size1,
bool IsVolatile1,
10851 const Value *SrcValue1,
int SrcValueOffset1,
10852 unsigned SrcValueAlign1,
10853 const MDNode *TBAAInfo1,
10854 SDValue Ptr2, int64_t Size2,
bool IsVolatile2,
10855 const Value *SrcValue2,
int SrcValueOffset2,
10856 unsigned SrcValueAlign2,
10857 const MDNode *TBAAInfo2)
const {
10859 if (Ptr1 == Ptr2)
return true;
10862 if (IsVolatile1 && IsVolatile2)
return true;
10866 int64_t Offset1, Offset2;
10868 const void *CV1, *CV2;
10869 bool isFrameIndex1 =
FindBaseOffset(Ptr1, Base1, Offset1, GV1, CV1);
10870 bool isFrameIndex2 =
FindBaseOffset(Ptr2, Base2, Offset2, GV2, CV2);
10873 if (Base1 == Base2 || (GV1 && (GV1 == GV2)) || (CV1 && (CV1 == CV2)))
10874 return !((Offset1 + Size1) <= Offset2 || (Offset2 + Size2) <= Offset1);
10880 if (isFrameIndex1 && isFrameIndex2) {
10882 Offset1 += MFI->
getObjectOffset(cast<FrameIndexSDNode>(Base1)->getIndex());
10883 Offset2 += MFI->
getObjectOffset(cast<FrameIndexSDNode>(Base2)->getIndex());
10884 return !((Offset1 + Size1) <= Offset2 || (Offset2 + Size2) <= Offset1);
10889 if ((isFrameIndex1 || CV1 || GV1) && (isFrameIndex2 || CV2 || GV2))
10896 if ((SrcValueAlign1 == SrcValueAlign2) &&
10897 (SrcValueOffset1 != SrcValueOffset2) &&
10898 (Size1 == Size2) && (SrcValueAlign1 > Size1)) {
10899 int64_t OffAlign1 = SrcValueOffset1 % SrcValueAlign1;
10900 int64_t OffAlign2 = SrcValueOffset2 % SrcValueAlign1;
10904 if ((OffAlign1 + Size1) <= OffAlign2 || (OffAlign2 + Size2) <= OffAlign1)
10908 bool UseAA = CombinerGlobalAA.getNumOccurrences() > 0 ? CombinerGlobalAA :
10910 if (UseAA && SrcValue1 && SrcValue2) {
10912 int64_t MinOffset = std::min(SrcValueOffset1, SrcValueOffset2);
10913 int64_t Overlap1 = Size1 + SrcValueOffset1 - MinOffset;
10914 int64_t Overlap2 = Size2 + SrcValueOffset2 - MinOffset;
10928 int64_t Size0, Size1;
10929 bool IsVolatile0, IsVolatile1;
10930 const Value *SrcValue0, *SrcValue1;
10931 int SrcValueOffset0, SrcValueOffset1;
10932 unsigned SrcValueAlign0, SrcValueAlign1;
10933 const MDNode *SrcTBAAInfo0, *SrcTBAAInfo1;
10934 FindAliasInfo(Op0, Ptr0, Size0, IsVolatile0, SrcValue0, SrcValueOffset0,
10935 SrcValueAlign0, SrcTBAAInfo0);
10936 FindAliasInfo(Op1, Ptr1, Size1, IsVolatile1, SrcValue1, SrcValueOffset1,
10937 SrcValueAlign1, SrcTBAAInfo1);
10938 return isAlias(Ptr0, Size0, IsVolatile0, SrcValue0, SrcValueOffset0,
10939 SrcValueAlign0, SrcTBAAInfo0,
10940 Ptr1, Size1, IsVolatile1, SrcValue1, SrcValueOffset1,
10941 SrcValueAlign1, SrcTBAAInfo1);
10946 bool DAGCombiner::FindAliasInfo(
SDNode *N,
10947 SDValue &Ptr, int64_t &Size,
bool &IsVolatile,
10948 const Value *&SrcValue,
10949 int &SrcValueOffset,
10950 unsigned &SrcValueAlign,
10951 const MDNode *&TBAAInfo)
const {
10961 return isa<LoadSDNode>(
LS) && !IsVolatile;
10966 void DAGCombiner::GatherAllAliases(
SDNode *N,
SDValue OriginalChain,
10975 const Value *SrcValue;
10976 int SrcValueOffset;
10977 unsigned SrcValueAlign;
10978 const MDNode *SrcTBAAInfo;
10979 bool IsLoad = FindAliasInfo(N, Ptr, Size, IsVolatile, SrcValue,
10980 SrcValueOffset, SrcValueAlign, SrcTBAAInfo);
10984 unsigned Depth = 0;
10989 while (!Chains.
empty()) {
11001 if (Depth > 6 || Aliases.
size() == 2) {
11022 const Value *OpSrcValue;
11023 int OpSrcValueOffset;
11024 unsigned OpSrcValueAlign;
11025 const MDNode *OpSrcTBAAInfo;
11026 bool IsOpLoad = FindAliasInfo(Chain.
getNode(), OpPtr,
OpSize,
11027 OpIsVolatile, OpSrcValue, OpSrcValueOffset,
11032 if (!(IsLoad && IsOpLoad) &&
11033 isAlias(Ptr, Size, IsVolatile, SrcValue, SrcValueOffset,
11034 SrcValueAlign, SrcTBAAInfo,
11035 OpPtr, OpSize, OpIsVolatile, OpSrcValue, OpSrcValueOffset,
11036 OpSrcValueAlign, OpSrcTBAAInfo)) {
11074 GatherAllAliases(N, OldChain, Aliases);
11077 if (Aliases.
size() == 0)
11078 return DAG.getEntryNode();
11081 if (Aliases.
size() == 1)
11086 &Aliases[0], Aliases.
size());
11095 DAGCombiner(*
this, AA, OptLevel).Run(Level);
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getValueSizeInBits(unsigned ResNo) const
opStatus divide(const APFloat &, roundingMode)
static MVT getIntegerVT(unsigned BitWidth)
std::string & operator+=(std::string &buffer, StringRef string)
void push_back(const T &Elt)
SDValue getConstant(uint64_t Val, EVT VT, bool isTarget=false)
SDValue getValue(unsigned R) const
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
bool isExactlyValue(double V) const
static bool areSlicesNextToEachOther(const LoadedSlice &First, const LoadedSlice &Second)
Check whether or not First and Second are next to each other in memory. This means that there is no h...
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVMContext * getContext() const
uint64_t getZExtValue() const
Get zero extended value.
void dump() const
dump - Dump this node, for debugging.
LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const
bool isNON_TRUNCStore(const SDNode *N)
Sorts LoadedSlice according to their offset.
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
const TargetMachine & getTargetMachine() const
SDVTList getVTList() const
bool equalBaseIndex(const BaseIndexOffset &Other)
static bool MatchRotateHalf(SDValue Op, SDValue &Shift, SDValue &Mask)
MatchRotateHalf - Match "(X shl/srl V1) & V2" where V2 may not be present.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
int getSplatIndex() const
const TargetMachine & getTarget() const
unsigned getPrefTypeAlignment(Type *Ty) const
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
virtual bool getPreIndexedAddressParts(SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
unsigned getOpcode() const
void operator>(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
void operator<(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
virtual bool isFAbsFree(EVT VT) const
Type * getTypeForEVT(LLVMContext &Context) const
unsigned getSizeInBits() const
bool isUnindexed() const
isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
bool isMask(unsigned numBits, const APInt &APIVal)
unsigned getNumOperands() const
void setAllBits()
Set every bit to 1.
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
unsigned getNumOperands() const
unsigned getValueSizeInBits() const
MDNode - a tuple of other values.
const SDValue & getOperand(unsigned Num) const
static MachinePointerInfo getConstantPool()
static bool isCommutativeBinOp(unsigned Opcode)
void ComputeMaskedBits(SDValue Op, APInt &KnownZero, APInt &KnownOne, unsigned Depth=0) const
static bool FindBaseOffset(SDValue Ptr, SDValue &Base, int64_t &Offset, const GlobalValue *&GV, const void *&CV)
FindBaseOffset - Return true if base is a frame index, which is known not.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
const SDValue & getBasePtr() const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
static SDNode * ShrinkLoadReplaceStoreWithStore(const std::pair< unsigned, unsigned > &MaskInfo, SDValue IVal, StoreSDNode *St, DAGCombiner *DC)
virtual bool isFPImmLegal(const APFloat &, EVT) const
EntryToken - This is the marker used to indicate the start of a region.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
bool bitsLT(EVT VT) const
bitsLT - Return true if this has less bits than VT.
bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask, APInt &KnownZero, APInt &KnownOne, TargetLoweringOpt &TLO, unsigned Depth=0) const
int64_t getSrcValueOffset() const
bool isAllOnesValue() const
bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const
Return true if the specified indexed load is legal on this target.
EVT getValueType(Type *Ty, bool AllowUnknown=false) const
bool isNegative() const
Determine sign of this APInt.
bool isVector() const
isVector - Return true if this is a vector value type.
EVT getShiftAmountTy(EVT LHSTy) const
bool isSEXTLoad(const SDNode *N)
bool isLittleEndian() const
unsigned CountTrailingOnes_64(uint64_t Value)
SDValue getStore(SDValue Chain, SDLoc dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, bool isVolatile, bool isNonTemporal, unsigned Alignment, const MDNode *TBAAInfo=0)
bool isRound() const
isRound - Return true if the size is a power-of-two number of bytes.
virtual bool isLegalAddImmediate(int64_t) const
bool isNormalStore(const SDNode *N)
#define llvm_unreachable(msg)
bool isBuildVectorAllZeros(const SDNode *N)
EVT getValueType(unsigned ResNo) const
bool HonorSignDependentRoundingFPMath() const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
virtual EVT getSetCCResultType(LLVMContext &Context, EVT VT) const
unsigned logBase2(const APInt &APIVal)
Returns the floor log base 2 of the specified APInt value.
bool isZEXTLoad(const SDNode *N)
MachinePointerInfo getWithOffset(int64_t O) const
EVT getScalarType() const
Abstract Stack Frame Information.
bool bitsGE(EVT VT) const
bitsGE - Return true if this has no less bits than VT.
int getMaskElt(unsigned Idx) const
virtual MVT getPointerTy(uint32_t=0) const
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type 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...
SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, ISD::CondCode Cond, bool foldBooleans, DAGCombinerInfo &DCI, SDLoc dl) const
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
bool getBoolValue() const
Convert APInt to a boolean value.
SDValue getConstantFP(double Val, EVT VT, bool isTarget=false)
APInt lshr(const APInt &LHS, unsigned shiftAmt)
Logical right-shift function.
EVT getVectorElementType() const
virtual bool getPostIndexedAddressParts(SDNode *, SDNode *, SDValue &, SDValue &, ISD::MemIndexedMode &, SelectionDAG &) const
STATISTIC(NodesCombined,"Number of dag nodes combined")
unsigned getNumValues() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type 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...
SDValue CombineTo(SDNode *N, const std::vector< SDValue > &To, bool AddTo=true)
Simple integer binary arithmetic operators.
unsigned getActiveBits() const
Compute the number of active bits in the value.
const SDValue & getBasePtr() const
SDValue getUNDEF(EVT VT)
getUNDEF - Return an UNDEF node. UNDEF does not have a useful SDLoc.
static bool isConstantSplatVector(SDNode *N, APInt &SplatValue)
Sorts store nodes in a link according to their offset from a shared.
const APInt & getAPIntValue() const
bool isLoadExtLegal(unsigned ExtType, EVT VT) const
Return true if the specified load with extension is legal on this target.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const
Left-shift function.
virtual bool isDesirableToTransformToIntegerOp(unsigned, EVT) const
EVT getMemoryVT() const
getMemoryVT - Return the type of the in-memory value.
SDValue BuildSDIV(SDNode *N, 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 ...
bool isSignedIntSetCC(CondCode Code)
virtual MVT getVectorIdxTy() const
static bool isTruncateOf(SelectionDAG &DAG, SDValue N, SDValue &Op, APInt &KnownZero)
UNDEF - An undefined node.
static bool isBSwapHWordElement(SDValue N, SmallVectorImpl< SDNode * > &Parts)
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef, unsigned &SplatBitSize, bool &HasAnyUndefs, unsigned MinSplatBits=0, bool isBigEndian=false)
SDNode * getNode() const
get the SDNode which holds the desired result
void operator<=(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
unsigned getStoreSize() const
bool isTypeLegal(EVT VT) const
static bool ExtendUsesToFormExtLoad(SDNode *N, SDValue N0, unsigned ExtOpc, SmallVectorImpl< SDNode * > &ExtendNodes, const TargetLowering &TLI)
initializer< Ty > init(const Ty &Val)
bool isNormalLoad(const SDNode *N)
unsigned getStoreSizeInBits() const
const SDValue & getBasePtr() const
bool isZero() const
isZero - Return true if the value is positive or negative zero.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
const SDValue & getOperand(unsigned i) const
Simple binary floating point operators.
bool isNonTemporal() const
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
void Combine(CombineLevel Level, AliasAnalysis &AA, CodeGenOpt::Level OptLevel)
LLVM Constant Representation.
int64_t getSExtValue() const
Get sign extended value.
static BaseIndexOffset match(SDValue Ptr)
Parses tree in Ptr for base, index, offset addresses.
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)
std::pair< SDValue, SDValue > SplitVectorOperand(const SDNode *N, unsigned OpNo)
void AddToWorklist(SDNode *N)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const
Sign extend to a new width.
virtual bool isTruncateFree(Type *, Type *) const
unsigned getOriginalAlignment() const
Returns alignment and volatility of the memory access.
const DataLayout * getDataLayout() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getOpcode() const
virtual bool isNarrowingProfitable(EVT, EVT) const
CondCode getSetCCSwappedOperands(CondCode Operation)
unsigned countPopulation() const
Count the number of bits set.
use_iterator use_begin() const
const SDValue & getValue() const
Location - A description of a memory location.
Bit counting operators with an undefined result for zero inputs.
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
void append(in_iter in_start, in_iter in_end)
uint64_t NextPowerOf2(uint64_t A)
static SDValue tryFoldToZero(SDLoc DL, const TargetLowering &TLI, EVT VT, SelectionDAG &DAG, bool LegalOperations, bool LegalTypes)
const APFloat & getValueAPF() const
bool bitsEq(EVT VT) const
bitsEq - Return true if this has the same number of bits as VT.
const ConstantFP * getConstantFPValue() const
static bool areUsedBitsDense(const APInt &UsedBits)
Check that all bits set in UsedBits form a dense region, i.e., UsedBits looks like 0...
static void adjustCostForPairing(SmallVectorImpl< LoadedSlice > &LoadedSlices, LoadedSlice::Cost &GlobalLSCost)
Adjust the GlobalLSCost according to the target paring capabilities and the layout of the slices...
ISD::MemIndexedMode getAddressingMode() const
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements)
uint64_t getConstantOperandVal(unsigned Num) const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static char isNegatibleForFree(SDValue Op, bool LegalOperations, const TargetLowering &TLI, const TargetOptions *Options, unsigned Depth=0)
bool isEXTLoad(const SDNode *N)
const MachinePointerInfo & getPointerInfo() const
int64_t getObjectOffset(int ObjectIdx) const
bool isUNINDEXEDLoad(const SDNode *N)
const SDValue & getOffset() const
bool bitsGT(EVT VT) const
bitsGT - Return true if this has more bits than VT.
ArrayRef< int > getMask() const
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
unsigned getABITypeAlignment(Type *Ty) const
bool isBuildVectorAllOnes(const SDNode *N)
Node predicates.
static bool canFoldInAddressingMode(SDNode *N, SDNode *Use, SelectionDAG &DAG, const TargetLowering &TLI)
const STC & getSubtarget() const
void RemoveFromWorklist(SDNode *N)
uint64_t getTypeAllocSize(Type *Ty) const
BooleanContent getBooleanContents(bool isVec) const
virtual bool isVectorClearMaskLegal(const SmallVectorImpl< int > &, EVT) const
unsigned logBase2() const
bool isPredecessorOf(const SDNode *N) const
bool allOperandsUndef(const SDNode *N)
const SDValue & getChain() const
Byte Swap and Counting operators.
MachineMemOperand * getMemOperand() const
void operator>=(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
unsigned getAddrSpace() const
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
static std::pair< SDValue, SDValue > SplitVSETCC(const SDNode *N, SelectionDAG &DAG)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
unsigned Log2_32(uint32_t Value)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const MDNode * getTBAAInfo() const
Returns the TBAAInfo that describes the dereference.
ISD::LoadExtType getExtensionType() const
Class for arbitrary precision integers.
static bool isOneUseSetCC(SDValue N)
static SDNode * getBuildPairElt(SDNode *N, unsigned i)
int64_t getSExtValue() const
op_iterator op_begin() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
static SDValue GetNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOperations, unsigned Depth=0)
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
AddrMode
ARM Addressing Modes.
APInt bitcastToAPInt() const
SDValue getNode(unsigned Opcode, SDLoc DL, EVT VT)
ANY_EXTEND - Used for integer types. The high bits are undefined.
static std::pair< unsigned, unsigned > CheckForMaskedLoad(SDValue V, SDValue Ptr, SDValue Chain)
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger)
static SDValue partitionShuffleOfConcats(SDNode *N, SelectionDAG &DAG)
bool operator()(const LoadedSlice &LHS, const LoadedSlice &RHS)
MemOpLink(LSBaseSDNode *N, int64_t Offset, unsigned Seq)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool operator!=(uint64_t V1, const APInt &V2)
bool isAllOnesValue() const
Determine if all bits are set.
uint64_t MinAlign(uint64_t A, uint64_t B)
BaseIndexOffset(SDValue Base, SDValue Index, int64_t Offset, bool IsIndexSignExt)
bool isScalarToVector(const SDNode *N)
Bitwise operators - logical and, logical or, logical xor.
bool hasAnyUseOfValue(unsigned Value) const
unsigned getSizeInBits() const
getSizeInBits - Return the size of the specified value type in bits.
static bool isSetCCEquivalent(SDValue N, SDValue &LHS, SDValue &RHS, SDValue &CC)
bool isIndexed() const
isIndexed - Return true if this is a pre/post inc/dec load/store.
op_iterator op_end() const
static ArrayType * get(Type *ElementType, uint64_t NumElements)
virtual const TargetRegisterInfo * getRegisterInfo() const
static SDValue getInputChainForNode(SDNode *N)
bool isNON_EXTLoad(const SDNode *N)
const Value * getSrcValue() const
Returns the SrcValue and offset that describes the location of the access.
bool operator()(MemOpLink LHS, MemOpLink RHS)
bool isByteSized() const
isByteSized - Return true if the bit size is a multiple of 8.
bool isFloatingPoint() const
isFloatingPoint - Return true if this is a FP, or a vector FP type.
bool hasPredecessorHelper(const SDNode *N, SmallPtrSet< const SDNode *, 32 > &Visited, SmallVectorImpl< const SDNode * > &Worklist) const
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
LLVM Value Representation.
static bool isSlicingProfitable(SmallVectorImpl< LoadedSlice > &LoadedSlices, const APInt &UsedBits, bool ForCodeSize)
Check the profitability of all involved LoadedSlice. Currently, it is considered profitable if there ...
bool isZero() const
Returns true if and only if the float is plus or minus zero.
bool isTruncatingStore() const
Disable implicit floating point insts.
SDValue BuildUDIV(SDNode *N, 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 ...
const TargetLowering & getTargetLoweringInfo() const
bool isInt(int64_t x)
isInt - Checks if an integer fits into the given bit width.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const
bool isPowerOf2_32(uint32_t Value)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
bool operator==(uint64_t V1, const APInt &V2)
static APInt getNullValue(unsigned numBits)
Get the '0' value.
static SDValue combineShlAddConstant(SDLoc DL, SDValue N0, SDValue N1, SelectionDAG &DAG)
SDNode * getUser()
getUser - This returns the SDNode that contains this Use.
TRUNCATE - Completely drop the high bits.
bool isUIntN(unsigned N, uint64_t x)
unsigned getAlignment() const
MVT getSimpleValueType(unsigned ResNo) const
tier< T1, T2 > tie(T1 &f, T2 &s)
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
virtual bool isFNegFree(EVT VT) const
const fltSemantics & getSemantics() const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
EVT changeVectorElementTypeToInteger() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
unsigned getResNo() const
getResNo - Convenience function for get().getResNo().
void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO)
uint64_t getBaseAlignment() const
ISD::CondCode get() const
uint64_t getZExtValue() const
unsigned getVectorNumElements() const
Function must be optimized for size first.