58 if (
F.getFnAttribute(
"disable-tail-calls").getValueAsBool())
64 AttrBuilder CallerAttrs(
F.getContext(),
F.getAttributes().getRetAttrs());
65 for (
const auto &Attr :
66 {Attribute::Alignment, Attribute::Dereferenceable,
67 Attribute::DereferenceableOrNull, Attribute::NoAlias,
68 Attribute::NonNull, Attribute::NoUndef, Attribute::Range})
75 if (CallerAttrs.
contains(Attribute::ZExt) ||
76 CallerAttrs.
contains(Attribute::SExt))
87 for (
unsigned I = 0, E = ArgLocs.
size();
I != E; ++
I) {
103 Register ArgReg = cast<RegisterSDNode>(
Value->getOperand(1))->getReg();
104 if (
MRI.getLiveInPhysReg(ArgReg) != Reg)
114 IsSExt = Call->paramHasAttr(ArgIdx, Attribute::SExt);
115 IsZExt = Call->paramHasAttr(ArgIdx, Attribute::ZExt);
116 IsInReg = Call->paramHasAttr(ArgIdx, Attribute::InReg);
117 IsSRet = Call->paramHasAttr(ArgIdx, Attribute::StructRet);
118 IsNest = Call->paramHasAttr(ArgIdx, Attribute::Nest);
119 IsByVal = Call->paramHasAttr(ArgIdx, Attribute::ByVal);
120 IsPreallocated = Call->paramHasAttr(ArgIdx, Attribute::Preallocated);
121 IsInAlloca = Call->paramHasAttr(ArgIdx, Attribute::InAlloca);
122 IsReturned = Call->paramHasAttr(ArgIdx, Attribute::Returned);
123 IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf);
124 IsSwiftAsync = Call->paramHasAttr(ArgIdx, Attribute::SwiftAsync);
125 IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError);
126 Alignment = Call->getParamStackAlign(ArgIdx);
129 "multiple ABI attributes?");
145std::pair<SDValue, SDValue>
155 Args.reserve(Ops.
size());
158 for (
unsigned i = 0; i < Ops.
size(); ++i) {
161 Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.
getContext());
164 Entry.IsZExt = !Entry.IsSExt;
168 Entry.IsSExt = Entry.IsZExt =
false;
170 Args.push_back(Entry);
173 if (LC == RTLIB::UNKNOWN_LIBCALL)
181 bool zeroExtend = !signExtend;
185 signExtend = zeroExtend =
false;
196 return LowerCallTo(CLI);
200 std::vector<EVT> &MemOps,
unsigned Limit,
const MemOp &
Op,
unsigned DstAS,
202 if (Limit != ~
unsigned(0) &&
Op.isMemcpyWithFixedDstAlign() &&
203 Op.getSrcAlign() <
Op.getDstAlign())
208 if (VT == MVT::Other) {
212 VT = MVT::LAST_INTEGER_VALUETYPE;
213 if (
Op.isFixedDstAlign())
220 MVT LVT = MVT::LAST_INTEGER_VALUETYPE;
231 unsigned NumMemOps = 0;
235 while (VTSize >
Size) {
246 else if (NewVT == MVT::i64 &&
258 if (NewVT == MVT::i8)
267 if (NumMemOps &&
Op.allowOverlap() && NewVTSize <
Size &&
269 VT, DstAS,
Op.isFixedDstAlign() ?
Op.getDstAlign() :
Align(1),
279 if (++NumMemOps > Limit)
282 MemOps.push_back(VT);
297 return softenSetCCOperands(DAG, VT, NewLHS, NewRHS, CCCode, dl, OldLHS,
307 bool IsSignaling)
const {
312 assert((VT == MVT::f32 || VT == MVT::f64 || VT == MVT::f128 || VT == MVT::ppcf128)
313 &&
"Unsupported setcc type!");
316 RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL;
317 bool ShouldInvertCC =
false;
321 LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 :
322 (VT == MVT::f64) ? RTLIB::OEQ_F64 :
323 (VT == MVT::f128) ? RTLIB::OEQ_F128 : RTLIB::OEQ_PPCF128;
327 LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 :
328 (VT == MVT::f64) ? RTLIB::UNE_F64 :
329 (VT == MVT::f128) ? RTLIB::UNE_F128 : RTLIB::UNE_PPCF128;
333 LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 :
334 (VT == MVT::f64) ? RTLIB::OGE_F64 :
335 (VT == MVT::f128) ? RTLIB::OGE_F128 : RTLIB::OGE_PPCF128;
339 LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 :
340 (VT == MVT::f64) ? RTLIB::OLT_F64 :
341 (VT == MVT::f128) ? RTLIB::OLT_F128 : RTLIB::OLT_PPCF128;
345 LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 :
346 (VT == MVT::f64) ? RTLIB::OLE_F64 :
347 (VT == MVT::f128) ? RTLIB::OLE_F128 : RTLIB::OLE_PPCF128;
351 LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 :
352 (VT == MVT::f64) ? RTLIB::OGT_F64 :
353 (VT == MVT::f128) ? RTLIB::OGT_F128 : RTLIB::OGT_PPCF128;
356 ShouldInvertCC =
true;
359 LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 :
360 (VT == MVT::f64) ? RTLIB::UO_F64 :
361 (VT == MVT::f128) ? RTLIB::UO_F128 : RTLIB::UO_PPCF128;
365 ShouldInvertCC =
true;
368 LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 :
369 (VT == MVT::f64) ? RTLIB::UO_F64 :
370 (VT == MVT::f128) ? RTLIB::UO_F128 : RTLIB::UO_PPCF128;
371 LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 :
372 (VT == MVT::f64) ? RTLIB::OEQ_F64 :
373 (VT == MVT::f128) ? RTLIB::OEQ_F128 : RTLIB::OEQ_PPCF128;
377 ShouldInvertCC =
true;
380 LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 :
381 (VT == MVT::f64) ? RTLIB::OGE_F64 :
382 (VT == MVT::f128) ? RTLIB::OGE_F128 : RTLIB::OGE_PPCF128;
385 LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 :
386 (VT == MVT::f64) ? RTLIB::OGT_F64 :
387 (VT == MVT::f128) ? RTLIB::OGT_F128 : RTLIB::OGT_PPCF128;
390 LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 :
391 (VT == MVT::f64) ? RTLIB::OLE_F64 :
392 (VT == MVT::f128) ? RTLIB::OLE_F128 : RTLIB::OLE_PPCF128;
395 LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 :
396 (VT == MVT::f64) ? RTLIB::OLT_F64 :
397 (VT == MVT::f128) ? RTLIB::OLT_F128 : RTLIB::OLT_PPCF128;
405 SDValue Ops[2] = {NewLHS, NewRHS};
410 auto Call = makeLibCall(DAG, LC1, RetVT, Ops, CallOptions, dl, Chain);
415 if (ShouldInvertCC) {
417 CCCode = getSetCCInverse(CCCode, RetVT);
420 if (LC2 == RTLIB::UNKNOWN_LIBCALL) {
427 auto Call2 = makeLibCall(DAG, LC2, RetVT, Ops, CallOptions, dl, Chain);
430 CCCode = getSetCCInverse(CCCode, RetVT);
431 NewLHS = DAG.
getSetCC(dl, SetCCVT, Call2.first, NewRHS, CCCode);
445 if (!isPositionIndependent())
459 unsigned JTEncoding = getJumpTableEncoding();
495 if (!
TM.shouldAssumeDSOLocal(GV))
499 if (isPositionIndependent())
515 const APInt &DemandedElts,
518 unsigned Opcode =
Op.getOpcode();
526 if (targetShrinkDemandedConstant(
Op,
DemandedBits, DemandedElts, TLO))
536 auto *Op1C = dyn_cast<ConstantSDNode>(
Op.getOperand(1));
537 if (!Op1C || Op1C->isOpaque())
541 const APInt &
C = Op1C->getAPIntValue();
546 EVT VT =
Op.getValueType();
563 EVT VT =
Op.getValueType();
578 "ShrinkDemandedOp only supports binary operators!");
579 assert(
Op.getNode()->getNumValues() == 1 &&
580 "ShrinkDemandedOp only supports nodes with one result!");
582 EVT VT =
Op.getValueType();
591 Op.getOperand(1).getValueType().getScalarSizeInBits() ==
BitWidth &&
592 "ShrinkDemandedOp only supports operands that have the same size!");
596 if (!
Op.getNode()->hasOneUse())
609 Op.getOpcode(), dl, SmallVT,
612 assert(DemandedSize <= SmallVTBits &&
"Narrowed below demanded bits?");
627 bool Simplified = SimplifyDemandedBits(
Op,
DemandedBits, Known, TLO);
636 const APInt &DemandedElts,
656 bool AssumeSingleUse)
const {
657 EVT VT =
Op.getValueType();
673 EVT VT =
Op.getValueType();
691 switch (
Op.getOpcode()) {
697 EVT SrcVT = Src.getValueType();
698 EVT DstVT =
Op.getValueType();
704 if (NumSrcEltBits == NumDstEltBits)
705 if (
SDValue V = SimplifyMultipleUseDemandedBits(
709 if (SrcVT.
isVector() && (NumDstEltBits % NumSrcEltBits) == 0) {
710 unsigned Scale = NumDstEltBits / NumSrcEltBits;
714 for (
unsigned i = 0; i != Scale; ++i) {
715 unsigned EltOffset = IsLE ? i : (Scale - 1 - i);
716 unsigned BitOffset = EltOffset * NumSrcEltBits;
719 DemandedSrcBits |= Sub;
720 for (
unsigned j = 0; j != NumElts; ++j)
722 DemandedSrcElts.
setBit((j * Scale) + i);
726 if (
SDValue V = SimplifyMultipleUseDemandedBits(
727 Src, DemandedSrcBits, DemandedSrcElts, DAG,
Depth + 1))
732 if (IsLE && (NumSrcEltBits % NumDstEltBits) == 0) {
733 unsigned Scale = NumSrcEltBits / NumDstEltBits;
737 for (
unsigned i = 0; i != NumElts; ++i)
738 if (DemandedElts[i]) {
739 unsigned Offset = (i % Scale) * NumDstEltBits;
741 DemandedSrcElts.
setBit(i / Scale);
744 if (
SDValue V = SimplifyMultipleUseDemandedBits(
745 Src, DemandedSrcBits, DemandedSrcElts, DAG,
Depth + 1))
766 return Op.getOperand(0);
768 return Op.getOperand(1);
779 return Op.getOperand(0);
781 return Op.getOperand(1);
791 return Op.getOperand(0);
793 return Op.getOperand(1);
799 if (std::optional<uint64_t> MaxSA =
802 unsigned ShAmt = *MaxSA;
803 unsigned NumSignBits =
806 if (NumSignBits > ShAmt && (NumSignBits - ShAmt) >= (UpperDemandedBits))
835 EVT ExVT = cast<VTSDNode>(
Op.getOperand(1))->getVT();
842 if (NumSignBits >= (
BitWidth - ExBits + 1))
855 EVT SrcVT = Src.getValueType();
856 EVT DstVT =
Op.getValueType();
857 if (IsLE && DemandedElts == 1 &&
870 auto *CIdx = dyn_cast<ConstantSDNode>(
Op.getOperand(2));
873 !DemandedElts[CIdx->getZExtValue()])
887 if (DemandedSubElts == 0)
897 bool AllUndef =
true, IdentityLHS =
true, IdentityRHS =
true;
898 for (
unsigned i = 0; i != NumElts; ++i) {
899 int M = ShuffleMask[i];
900 if (M < 0 || !DemandedElts[i])
903 IdentityLHS &= (M == (int)i);
904 IdentityRHS &= ((M - NumElts) == i);
910 return Op.getOperand(0);
912 return Op.getOperand(1);
922 if (
SDValue V = SimplifyMultipleUseDemandedBitsForTargetNode(
932 unsigned Depth)
const {
933 EVT VT =
Op.getValueType();
940 return SimplifyMultipleUseDemandedBits(
Op,
DemandedBits, DemandedElts, DAG,
946 unsigned Depth)
const {
948 return SimplifyMultipleUseDemandedBits(
Op,
DemandedBits, DemandedElts, DAG,
960 "SRL or SRA node is required here!");
963 if (!N1C || !N1C->
isOne())
1010 unsigned ShiftOpc =
Op.getOpcode();
1011 bool IsSigned =
false;
1015 unsigned NumSigned = std::min(NumSignedA, NumSignedB) - 1;
1020 unsigned NumZero = std::min(NumZeroA, NumZeroB);
1026 if (NumZero >= 2 && NumSigned < NumZero) {
1031 if (NumSigned >= 1) {
1039 if (NumZero >= 1 && NumSigned < NumZero) {
1059 EVT VT =
Op.getValueType();
1073 Add.getOperand(1)) &&
1084 (isa<ConstantSDNode>(ExtOpA) || isa<ConstantSDNode>(ExtOpB)))
1104 unsigned Depth,
bool AssumeSingleUse)
const {
1107 "Mask size mismatches value type size!");
1112 EVT VT =
Op.getValueType();
1114 unsigned NumElts = OriginalDemandedElts.
getBitWidth();
1116 "Unexpected vector size");
1119 APInt DemandedElts = OriginalDemandedElts;
1139 cast<ConstantFPSDNode>(
Op)->getValueAPF().bitcastToAPInt());
1144 bool HasMultiUse =
false;
1145 if (!AssumeSingleUse && !
Op.getNode()->hasOneUse()) {
1154 }
else if (OriginalDemandedBits == 0 || OriginalDemandedElts == 0) {
1163 switch (
Op.getOpcode()) {
1167 if (!DemandedElts[0])
1172 unsigned SrcBitWidth = Src.getScalarValueSizeInBits();
1174 if (SimplifyDemandedBits(Src, SrcDemandedBits, SrcKnown, TLO,
Depth + 1))
1179 if (DemandedElts == 1)
1192 if (SimplifyDemandedBits(Scl, DemandedSclBits, KnownScl, TLO,
Depth + 1))
1201 auto *LD = cast<LoadSDNode>(
Op);
1202 if (getTargetConstantFromLoad(LD)) {
1208 EVT MemVT = LD->getMemoryVT();
1220 auto *CIdx = dyn_cast<ConstantSDNode>(
Op.getOperand(2));
1225 APInt DemandedVecElts(DemandedElts);
1227 unsigned Idx = CIdx->getZExtValue();
1231 if (!DemandedElts[
Idx])
1238 if (SimplifyDemandedBits(Scl, DemandedSclBits, KnownScl, TLO,
Depth + 1))
1244 if (SimplifyDemandedBits(Vec,
DemandedBits, DemandedVecElts, KnownVec, TLO,
1248 if (!!DemandedVecElts)
1263 APInt DemandedSrcElts = DemandedElts;
1267 if (SimplifyDemandedBits(Sub,
DemandedBits, DemandedSubElts, KnownSub, TLO,
1270 if (SimplifyDemandedBits(Src,
DemandedBits, DemandedSrcElts, KnownSrc, TLO,
1276 if (!!DemandedSubElts)
1278 if (!!DemandedSrcElts)
1284 SDValue NewSub = SimplifyMultipleUseDemandedBits(
1286 SDValue NewSrc = SimplifyMultipleUseDemandedBits(
1288 if (NewSub || NewSrc) {
1289 NewSub = NewSub ? NewSub : Sub;
1290 NewSrc = NewSrc ? NewSrc : Src;
1303 if (Src.getValueType().isScalableVector())
1306 unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
1309 if (SimplifyDemandedBits(Src,
DemandedBits, DemandedSrcElts, Known, TLO,
1315 SDValue DemandedSrc = SimplifyMultipleUseDemandedBits(
1330 EVT SubVT =
Op.getOperand(0).getValueType();
1333 for (
unsigned i = 0; i != NumSubVecs; ++i) {
1334 APInt DemandedSubElts =
1335 DemandedElts.
extractBits(NumSubElts, i * NumSubElts);
1336 if (SimplifyDemandedBits(
Op.getOperand(i),
DemandedBits, DemandedSubElts,
1337 Known2, TLO,
Depth + 1))
1340 if (!!DemandedSubElts)
1350 APInt DemandedLHS, DemandedRHS;
1355 if (!!DemandedLHS || !!DemandedRHS) {
1361 if (!!DemandedLHS) {
1362 if (SimplifyDemandedBits(Op0,
DemandedBits, DemandedLHS, Known2, TLO,
1367 if (!!DemandedRHS) {
1368 if (SimplifyDemandedBits(Op1,
DemandedBits, DemandedRHS, Known2, TLO,
1375 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1377 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
1379 if (DemandedOp0 || DemandedOp1) {
1380 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
1381 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
1416 LHSKnown.
One == ~RHSC->getAPIntValue()) {
1428 unsigned NumSubElts =
1445 if (SimplifyDemandedBits(Op1,
DemandedBits, DemandedElts, Known, TLO,
1449 Known2, TLO,
Depth + 1))
1471 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1473 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
1475 if (DemandedOp0 || DemandedOp1) {
1476 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
1477 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
1490 if (SimplifyDemandedBits(Op1,
DemandedBits, DemandedElts, Known, TLO,
1492 if (Flags.hasDisjoint()) {
1493 Flags.setDisjoint(
false);
1494 Op->setFlags(Flags);
1499 if (SimplifyDemandedBits(Op0, ~Known.
One &
DemandedBits, DemandedElts,
1500 Known2, TLO,
Depth + 1)) {
1501 if (Flags.hasDisjoint()) {
1502 Flags.setDisjoint(
false);
1503 Op->setFlags(Flags);
1523 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1525 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
1527 if (DemandedOp0 || DemandedOp1) {
1528 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
1529 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
1540 for (
int I = 0;
I != 2; ++
I) {
1543 SDValue Alt =
Op.getOperand(1 -
I).getOperand(0);
1544 SDValue C2 =
Op.getOperand(1 -
I).getOperand(1);
1546 for (
int J = 0; J != 2; ++J) {
1569 if (SimplifyDemandedBits(Op1,
DemandedBits, DemandedElts, Known, TLO,
1572 if (SimplifyDemandedBits(Op0,
DemandedBits, DemandedElts, Known2, TLO,
1599 if (
C->getAPIntValue() == Known2.
One) {
1608 if (!
C->isAllOnes() &&
DemandedBits.isSubsetOf(
C->getAPIntValue())) {
1620 if (ShiftC->getAPIntValue().ult(
BitWidth)) {
1621 uint64_t ShiftAmt = ShiftC->getZExtValue();
1624 : Ones.
lshr(ShiftAmt);
1642 if (!
C || !
C->isAllOnes())
1648 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1650 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
1652 if (DemandedOp0 || DemandedOp1) {
1653 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
1654 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
1664 if (SimplifyDemandedBits(
Op.getOperand(2),
DemandedBits, DemandedElts,
1665 Known, TLO,
Depth + 1))
1667 if (SimplifyDemandedBits(
Op.getOperand(1),
DemandedBits, DemandedElts,
1668 Known2, TLO,
Depth + 1))
1679 if (SimplifyDemandedBits(
Op.getOperand(2),
DemandedBits, DemandedElts,
1680 Known, TLO,
Depth + 1))
1682 if (SimplifyDemandedBits(
Op.getOperand(1),
DemandedBits, DemandedElts,
1683 Known2, TLO,
Depth + 1))
1690 if (SimplifyDemandedBits(
Op.getOperand(3),
DemandedBits, DemandedElts,
1691 Known, TLO,
Depth + 1))
1693 if (SimplifyDemandedBits(
Op.getOperand(2),
DemandedBits, DemandedElts,
1694 Known2, TLO,
Depth + 1))
1737 if (std::optional<uint64_t> KnownSA =
1739 unsigned ShAmt = *KnownSA;
1749 if (std::optional<uint64_t> InnerSA =
1751 unsigned C1 = *InnerSA;
1753 int Diff = ShAmt - C1;
1772 if (ShAmt < InnerBits &&
DemandedBits.getActiveBits() <= InnerBits &&
1773 isTypeDesirableForOp(
ISD::SHL, InnerVT)) {
1790 InnerOp, DemandedElts,
Depth + 2)) {
1791 unsigned InnerShAmt = *SA2;
1792 if (InnerShAmt < ShAmt && InnerShAmt < InnerBits &&
1794 (InnerBits - InnerShAmt + ShAmt) &&
1808 if (SimplifyDemandedBits(Op0, InDemandedMask, DemandedElts, Known, TLO,
1811 if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
1814 Flags.setNoSignedWrap(
false);
1815 Flags.setNoUnsignedWrap(
false);
1816 Op->setFlags(Flags);
1820 Known.
Zero <<= ShAmt;
1821 Known.
One <<= ShAmt;
1827 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
1828 Op0, InDemandedMask, DemandedElts, TLO.
DAG,
Depth + 1);
1839 Op.getNode()->hasOneUse()) {
1847 isTypeDesirableForOp(
ISD::SHL, SmallVT) &&
1850 assert(DemandedSize <= SmallVTBits &&
1851 "Narrowed below demanded bits?");
1871 isTypeDesirableForOp(
ISD::SHL, HalfVT) &&
1880 Flags.setNoSignedWrap(IsNSW);
1881 Flags.setNoUnsignedWrap(IsNUW);
1886 NewShiftAmt, Flags);
1899 if (SimplifyDemandedBits(Op0, DemandedFromOp, DemandedElts, Known, TLO,
1902 if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
1905 Flags.setNoSignedWrap(
false);
1906 Flags.setNoUnsignedWrap(
false);
1907 Op->setFlags(Flags);
1917 if (std::optional<uint64_t> MaxSA =
1919 unsigned ShAmt = *MaxSA;
1920 unsigned NumSignBits =
1923 if (NumSignBits > ShAmt && (NumSignBits - ShAmt) >= (UpperDemandedBits))
1933 if (std::optional<uint64_t> KnownSA =
1935 unsigned ShAmt = *KnownSA;
1945 if (std::optional<uint64_t> InnerSA =
1947 unsigned C1 = *InnerSA;
1949 int Diff = ShAmt - C1;
1965 if (
Op->getFlags().hasExact())
1974 isTypeDesirableForOp(
ISD::SRL, HalfVT) &&
1990 if (SimplifyDemandedBits(Op0, InDemandedMask, DemandedElts, Known, TLO,
2000 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
2001 Op0, InDemandedMask, DemandedElts, TLO.
DAG,
Depth + 1);
2015 DemandedElts,
Depth + 1))
2039 if (std::optional<uint64_t> KnownSA =
2041 unsigned ShAmt = *KnownSA;
2048 if (std::optional<uint64_t> InnerSA =
2050 unsigned LowBits =
BitWidth - ShAmt;
2056 if (*InnerSA == ShAmt) {
2066 unsigned NumSignBits =
2068 if (NumSignBits > ShAmt)
2078 if (
Op->getFlags().hasExact())
2086 if (SimplifyDemandedBits(Op0, InDemandedMask, DemandedElts, Known, TLO,
2097 Flags.setExact(
Op->getFlags().hasExact());
2115 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
2116 Op0, InDemandedMask, DemandedElts, TLO.
DAG,
Depth + 1);
2126 DemandedElts,
Depth + 1))
2139 unsigned Amt = SA->getAPIntValue().urem(
BitWidth);
2144 if (SimplifyDemandedBits(IsFSHL ? Op0 : Op1,
DemandedBits, DemandedElts,
2145 Known, TLO,
Depth + 1))
2154 if (SimplifyDemandedBits(Op0, Demanded0, DemandedElts, Known2, TLO,
2157 if (SimplifyDemandedBits(Op1, Demanded1, DemandedElts, Known, TLO,
2170 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
2171 Op0, Demanded0, DemandedElts, TLO.
DAG,
Depth + 1);
2172 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
2173 Op1, Demanded1, DemandedElts, TLO.
DAG,
Depth + 1);
2174 if (DemandedOp0 || DemandedOp1) {
2175 DemandedOp0 = DemandedOp0 ? DemandedOp0 : Op0;
2176 DemandedOp1 = DemandedOp1 ? DemandedOp1 : Op1;
2187 if (SimplifyDemandedBits(Op2, DemandedAmtBits, DemandedElts,
2188 Known2, TLO,
Depth + 1))
2204 unsigned Amt = SA->getAPIntValue().urem(
BitWidth);
2210 if (SimplifyDemandedBits(Op0, Demanded0, DemandedElts, Known2, TLO,
2220 DemandedBits.countr_zero() >= (IsROTL ? Amt : RevAmt)) {
2225 DemandedBits.countl_zero() >= (IsROTL ? RevAmt : Amt)) {
2234 if (SimplifyDemandedBits(Op1, DemandedAmtBits, DemandedElts, Known2, TLO,
2244 unsigned Opc =
Op.getOpcode();
2251 unsigned NumSignBits =
2255 if (NumSignBits >= NumDemandedUpperBits)
2296 if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedElts, Known2, TLO,
2322 unsigned ShiftAmount = NLZ > NTZ ? NLZ - NTZ : NTZ - NLZ;
2330 if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedElts, Known2, TLO,
2350 EVT ExVT = cast<VTSDNode>(
Op.getOperand(1))->getVT();
2355 unsigned MinSignedBits =
2357 bool AlreadySignExtended = ExVTBits >= MinSignedBits;
2360 if (!AlreadySignExtended) {
2378 InputDemandedBits.
setBit(ExVTBits - 1);
2380 if (SimplifyDemandedBits(Op0, InputDemandedBits, DemandedElts, Known, TLO,
2388 if (Known.
Zero[ExVTBits - 1])
2392 if (Known.
One[ExVTBits - 1]) {
2402 EVT HalfVT =
Op.getOperand(0).getValueType();
2410 if (SimplifyDemandedBits(
Op.getOperand(0), MaskLo, KnownLo, TLO,
Depth + 1))
2413 if (SimplifyDemandedBits(
Op.getOperand(1), MaskHi, KnownHi, TLO,
Depth + 1))
2416 Known = KnownHi.
concat(KnownLo);
2425 EVT SrcVT = Src.getValueType();
2434 if (IsLE && IsVecInReg && DemandedElts == 1 &&
2446 APInt InDemandedElts = DemandedElts.
zext(InElts);
2447 if (SimplifyDemandedBits(Src, InDemandedBits, InDemandedElts, Known, TLO,
2449 if (Flags.hasNonNeg()) {
2450 Flags.setNonNeg(
false);
2451 Op->setFlags(Flags);
2459 if (
SDValue NewSrc = SimplifyMultipleUseDemandedBits(
2460 Src, InDemandedBits, InDemandedElts, TLO.
DAG,
Depth + 1))
2470 EVT SrcVT = Src.getValueType();
2475 APInt InDemandedElts = DemandedElts.
zext(InElts);
2480 InDemandedBits.
setBit(InBits - 1);
2486 if (IsLE && IsVecInReg && DemandedElts == 1 &&
2501 if (SimplifyDemandedBits(Src, InDemandedBits, InDemandedElts, Known, TLO,
2516 Flags.setNonNeg(
true);
2522 if (
SDValue NewSrc = SimplifyMultipleUseDemandedBits(
2523 Src, InDemandedBits, InDemandedElts, TLO.
DAG,
Depth + 1))
2533 EVT SrcVT = Src.getValueType();
2540 if (IsLE && IsVecInReg && DemandedElts == 1 &&
2545 APInt InDemandedElts = DemandedElts.
zext(InElts);
2546 if (SimplifyDemandedBits(Src, InDemandedBits, InDemandedElts, Known, TLO,
2553 if (
SDValue NewSrc = SimplifyMultipleUseDemandedBits(
2554 Src, InDemandedBits, InDemandedElts, TLO.
DAG,
Depth + 1))
2563 unsigned OperandBitWidth = Src.getScalarValueSizeInBits();
2565 if (SimplifyDemandedBits(Src, TruncMask, DemandedElts, Known, TLO,
2571 if (
SDValue NewSrc = SimplifyMultipleUseDemandedBits(
2572 Src, TruncMask, DemandedElts, TLO.
DAG,
Depth + 1))
2577 switch (Src.getOpcode()) {
2588 if (Src.getNode()->hasOneUse()) {
2600 std::optional<uint64_t> ShAmtC =
2602 if (!ShAmtC || *ShAmtC >=
BitWidth)
2628 EVT ZVT = cast<VTSDNode>(
Op.getOperand(1))->getVT();
2630 if (SimplifyDemandedBits(
Op.getOperand(0), ~InMask |
DemandedBits, Known,
2634 Known.
Zero |= ~InMask;
2635 Known.
One &= (~Known.Zero);
2641 ElementCount SrcEltCnt = Src.getValueType().getVectorElementCount();
2642 unsigned EltBitWidth = Src.getScalarValueSizeInBits();
2650 if (
auto *CIdx = dyn_cast<ConstantSDNode>(
Idx))
2651 if (CIdx->getAPIntValue().ult(NumSrcElts))
2658 DemandedSrcBits = DemandedSrcBits.
trunc(EltBitWidth);
2660 if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedSrcElts, Known2, TLO,
2666 if (
SDValue DemandedSrc = SimplifyMultipleUseDemandedBits(
2667 Src, DemandedSrcBits, DemandedSrcElts, TLO.
DAG,
Depth + 1)) {
2683 EVT SrcVT = Src.getValueType();
2693 if ((OpVTLegal || i32Legal) && VT.
isSimple() && SrcVT != MVT::f16 &&
2694 SrcVT != MVT::f128) {
2696 EVT Ty = OpVTLegal ? VT : MVT::i32;
2700 unsigned OpVTSizeInBits =
Op.getValueSizeInBits();
2701 if (!OpVTLegal && OpVTSizeInBits > 32)
2703 unsigned ShVal =
Op.getValueSizeInBits() - 1;
2713 unsigned Scale =
BitWidth / NumSrcEltBits;
2717 for (
unsigned i = 0; i != Scale; ++i) {
2718 unsigned EltOffset = IsLE ? i : (Scale - 1 - i);
2719 unsigned BitOffset = EltOffset * NumSrcEltBits;
2722 DemandedSrcBits |= Sub;
2723 for (
unsigned j = 0; j != NumElts; ++j)
2724 if (DemandedElts[j])
2725 DemandedSrcElts.
setBit((j * Scale) + i);
2729 APInt KnownSrcUndef, KnownSrcZero;
2730 if (SimplifyDemandedVectorElts(Src, DemandedSrcElts, KnownSrcUndef,
2731 KnownSrcZero, TLO,
Depth + 1))
2735 if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedSrcElts,
2736 KnownSrcBits, TLO,
Depth + 1))
2738 }
else if (IsLE && (NumSrcEltBits %
BitWidth) == 0) {
2740 unsigned Scale = NumSrcEltBits /
BitWidth;
2744 for (
unsigned i = 0; i != NumElts; ++i)
2745 if (DemandedElts[i]) {
2748 DemandedSrcElts.
setBit(i / Scale);
2752 APInt KnownSrcUndef, KnownSrcZero;
2753 if (SimplifyDemandedVectorElts(Src, DemandedSrcElts, KnownSrcUndef,
2754 KnownSrcZero, TLO,
Depth + 1))
2759 if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedSrcElts,
2760 KnownSrcBits, TLO,
Depth + 1))
2765 if (
SDValue DemandedSrc = SimplifyMultipleUseDemandedBits(
2766 Src, DemandedSrcBits, DemandedSrcElts, TLO.
DAG,
Depth + 1)) {
2788 if (
C &&
C->getAPIntValue().countr_zero() == CTZ) {
2807 SDValue Op0 =
Op.getOperand(0), Op1 =
Op.getOperand(1);
2812 auto GetDemandedBitsLHSMask = [&](
APInt Demanded,
2818 if (SimplifyDemandedBits(Op1, LoMask, DemandedElts, KnownOp1, TLO,
2820 SimplifyDemandedBits(Op0, GetDemandedBitsLHSMask(LoMask, KnownOp1),
2821 DemandedElts, KnownOp0, TLO,
Depth + 1) ||
2824 if (Flags.hasNoSignedWrap() || Flags.hasNoUnsignedWrap()) {
2827 Flags.setNoSignedWrap(
false);
2828 Flags.setNoUnsignedWrap(
false);
2829 Op->setFlags(Flags);
2841 SDValue DemandedOp0 = SimplifyMultipleUseDemandedBits(
2842 Op0, LoMask, DemandedElts, TLO.
DAG,
Depth + 1);
2843 SDValue DemandedOp1 = SimplifyMultipleUseDemandedBits(
2844 Op1, LoMask, DemandedElts, TLO.
DAG,
Depth + 1);
2845 if (DemandedOp0 || DemandedOp1) {
2846 Flags.setNoSignedWrap(
false);
2847 Flags.setNoUnsignedWrap(
false);
2848 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
2849 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
2851 TLO.
DAG.
getNode(
Op.getOpcode(), dl, VT, Op0, Op1, Flags);
2863 if (
C && !
C->isAllOnes() && !
C->isOne() &&
2864 (
C->getAPIntValue() | HighMask).isAllOnes()) {
2868 Flags.setNoSignedWrap(
false);
2869 Flags.setNoUnsignedWrap(
false);
2877 auto getShiftLeftAmt = [&HighMask](
SDValue Mul) ->
unsigned {
2904 if (
unsigned ShAmt = getShiftLeftAmt(Op0))
2907 if (
unsigned ShAmt = getShiftLeftAmt(Op1))
2908 return foldMul(
ISD::SUB, Op1.getOperand(0), Op0, ShAmt);
2912 if (
unsigned ShAmt = getShiftLeftAmt(Op1))
2913 return foldMul(
ISD::ADD, Op1.getOperand(0), Op0, ShAmt);
2921 Op.getOpcode() ==
ISD::ADD, Flags.hasNoSignedWrap(),
2922 Flags.hasNoUnsignedWrap(), KnownOp0, KnownOp1);
2932 if (
Op.getValueType().isScalableVector())
2934 if (SimplifyDemandedBitsForTargetNode(
Op,
DemandedBits, DemandedElts,
2947 if (!isTargetCanonicalConstantNode(
Op) &&
2953 if (
auto *
C = dyn_cast<ConstantSDNode>(
Op))
2976 const APInt &DemandedElts,
2982 APInt KnownUndef, KnownZero;
2984 SimplifyDemandedVectorElts(
Op, DemandedElts, KnownUndef, KnownZero, TLO);
2996 const APInt &UndefOp0,
2997 const APInt &UndefOp1) {
3000 "Vector binop only");
3005 UndefOp1.
getBitWidth() == NumElts &&
"Bad type for undef analysis");
3007 auto getUndefOrConstantElt = [&](
SDValue V,
unsigned Index,
3008 const APInt &UndefVals) {
3009 if (UndefVals[
Index])
3012 if (
auto *BV = dyn_cast<BuildVectorSDNode>(V)) {
3016 auto *
C = dyn_cast<ConstantSDNode>(Elt);
3017 if (isa<ConstantFPSDNode>(Elt) || Elt.
isUndef() || (
C && !
C->isOpaque()))
3025 for (
unsigned i = 0; i != NumElts; ++i) {
3044 bool AssumeSingleUse)
const {
3045 EVT VT =
Op.getValueType();
3046 unsigned Opcode =
Op.getOpcode();
3047 APInt DemandedElts = OriginalDemandedElts;
3062 "Mask size mismatches value type element count!");
3071 if (!AssumeSingleUse && !
Op.getNode()->hasOneUse())
3075 if (DemandedElts == 0) {
3090 auto SimplifyDemandedVectorEltsBinOp = [&](
SDValue Op0,
SDValue Op1) {
3091 SDValue NewOp0 = SimplifyMultipleUseDemandedVectorElts(Op0, DemandedElts,
3093 SDValue NewOp1 = SimplifyMultipleUseDemandedVectorElts(Op1, DemandedElts,
3095 if (NewOp0 || NewOp1) {
3098 NewOp1 ? NewOp1 : Op1,
Op->getFlags());
3106 if (!DemandedElts[0]) {
3114 EVT SrcVT = Src.getValueType();
3126 if (SimplifyDemandedVectorElts(Src, SrcDemandedElts, SrcUndef, SrcZero,
3136 EVT SrcVT = Src.getValueType();
3145 if (NumSrcElts == NumElts)
3146 return SimplifyDemandedVectorElts(Src, DemandedElts, KnownUndef,
3147 KnownZero, TLO,
Depth + 1);
3149 APInt SrcDemandedElts, SrcZero, SrcUndef;
3153 if ((NumElts % NumSrcElts) == 0) {
3154 unsigned Scale = NumElts / NumSrcElts;
3156 if (SimplifyDemandedVectorElts(Src, SrcDemandedElts, SrcUndef, SrcZero,
3166 for (
unsigned i = 0; i != NumElts; ++i)
3167 if (DemandedElts[i]) {
3168 unsigned Ofs = (i % Scale) * EltSizeInBits;
3169 SrcDemandedBits.
setBits(Ofs, Ofs + EltSizeInBits);
3173 if (SimplifyDemandedBits(Src, SrcDemandedBits, SrcDemandedElts, Known,
3181 for (
unsigned SubElt = 0; SubElt != Scale; ++SubElt) {
3185 for (
unsigned SrcElt = 0; SrcElt != NumSrcElts; ++SrcElt) {
3186 unsigned Elt = Scale * SrcElt + SubElt;
3187 if (DemandedElts[Elt])
3195 for (
unsigned i = 0; i != NumSrcElts; ++i) {
3196 if (SrcDemandedElts[i]) {
3198 KnownZero.
setBits(i * Scale, (i + 1) * Scale);
3200 KnownUndef.
setBits(i * Scale, (i + 1) * Scale);
3208 if ((NumSrcElts % NumElts) == 0) {
3209 unsigned Scale = NumSrcElts / NumElts;
3211 if (SimplifyDemandedVectorElts(Src, SrcDemandedElts, SrcUndef, SrcZero,
3217 for (
unsigned i = 0; i != NumElts; ++i) {
3218 if (DemandedElts[i]) {
3247 [&](
SDValue Elt) { return Op.getOperand(0) != Elt; })) {
3249 bool Updated =
false;
3250 for (
unsigned i = 0; i != NumElts; ++i) {
3251 if (!DemandedElts[i] && !Ops[i].
isUndef()) {
3261 for (
unsigned i = 0; i != NumElts; ++i) {
3263 if (
SrcOp.isUndef()) {
3265 }
else if (EltSizeInBits ==
SrcOp.getScalarValueSizeInBits() &&
3273 EVT SubVT =
Op.getOperand(0).getValueType();
3276 for (
unsigned i = 0; i != NumSubVecs; ++i) {
3279 APInt SubUndef, SubZero;
3280 if (SimplifyDemandedVectorElts(SubOp, SubElts, SubUndef, SubZero, TLO,
3283 KnownUndef.
insertBits(SubUndef, i * NumSubElts);
3284 KnownZero.
insertBits(SubZero, i * NumSubElts);
3289 bool FoundNewSub =
false;
3291 for (
unsigned i = 0; i != NumSubVecs; ++i) {
3294 SDValue NewSubOp = SimplifyMultipleUseDemandedVectorElts(
3295 SubOp, SubElts, TLO.
DAG,
Depth + 1);
3296 DemandedSubOps.
push_back(NewSubOp ? NewSubOp : SubOp);
3297 FoundNewSub = NewSubOp ?
true : FoundNewSub;
3315 APInt DemandedSrcElts = DemandedElts;
3318 APInt SubUndef, SubZero;
3319 if (SimplifyDemandedVectorElts(Sub, DemandedSubElts, SubUndef, SubZero, TLO,
3324 if (!DemandedSrcElts && !Src.isUndef())
3329 if (SimplifyDemandedVectorElts(Src, DemandedSrcElts, KnownUndef, KnownZero,
3337 SDValue NewSrc = SimplifyMultipleUseDemandedVectorElts(
3338 Src, DemandedSrcElts, TLO.
DAG,
Depth + 1);
3339 SDValue NewSub = SimplifyMultipleUseDemandedVectorElts(
3340 Sub, DemandedSubElts, TLO.
DAG,
Depth + 1);
3341 if (NewSrc || NewSub) {
3342 NewSrc = NewSrc ? NewSrc : Src;
3343 NewSub = NewSub ? NewSub : Sub;
3345 NewSub,
Op.getOperand(2));
3354 if (Src.getValueType().isScalableVector())
3357 unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
3360 APInt SrcUndef, SrcZero;
3361 if (SimplifyDemandedVectorElts(Src, DemandedSrcElts, SrcUndef, SrcZero, TLO,
3369 SDValue NewSrc = SimplifyMultipleUseDemandedVectorElts(
3370 Src, DemandedSrcElts, TLO.
DAG,
Depth + 1);
3382 auto *CIdx = dyn_cast<ConstantSDNode>(
Op.getOperand(2));
3386 if (CIdx && CIdx->getAPIntValue().ult(NumElts)) {
3387 unsigned Idx = CIdx->getZExtValue();
3388 if (!DemandedElts[
Idx])
3391 APInt DemandedVecElts(DemandedElts);
3393 if (SimplifyDemandedVectorElts(Vec, DemandedVecElts, KnownUndef,
3394 KnownZero, TLO,
Depth + 1))
3403 APInt VecUndef, VecZero;
3404 if (SimplifyDemandedVectorElts(Vec, DemandedElts, VecUndef, VecZero, TLO,
3417 APInt UndefSel, ZeroSel;
3418 if (SimplifyDemandedVectorElts(Sel, DemandedElts, UndefSel, ZeroSel, TLO,
3423 APInt DemandedLHS(DemandedElts);
3424 APInt DemandedRHS(DemandedElts);
3425 APInt UndefLHS, ZeroLHS;
3426 APInt UndefRHS, ZeroRHS;
3427 if (SimplifyDemandedVectorElts(
LHS, DemandedLHS, UndefLHS, ZeroLHS, TLO,
3430 if (SimplifyDemandedVectorElts(
RHS, DemandedRHS, UndefRHS, ZeroRHS, TLO,
3434 KnownUndef = UndefLHS & UndefRHS;
3435 KnownZero = ZeroLHS & ZeroRHS;
3439 APInt DemandedSel = DemandedElts & ~KnownZero;
3440 if (DemandedSel != DemandedElts)
3441 if (SimplifyDemandedVectorElts(Sel, DemandedSel, UndefSel, ZeroSel, TLO,
3453 APInt DemandedLHS(NumElts, 0);
3454 APInt DemandedRHS(NumElts, 0);
3455 for (
unsigned i = 0; i != NumElts; ++i) {
3456 int M = ShuffleMask[i];
3457 if (M < 0 || !DemandedElts[i])
3459 assert(0 <= M && M < (
int)(2 * NumElts) &&
"Shuffle index out of range");
3460 if (M < (
int)NumElts)
3463 DemandedRHS.
setBit(M - NumElts);
3467 APInt UndefLHS, ZeroLHS;
3468 APInt UndefRHS, ZeroRHS;
3469 if (SimplifyDemandedVectorElts(
LHS, DemandedLHS, UndefLHS, ZeroLHS, TLO,
3472 if (SimplifyDemandedVectorElts(
RHS, DemandedRHS, UndefRHS, ZeroRHS, TLO,
3477 bool Updated =
false;
3478 bool IdentityLHS =
true, IdentityRHS =
true;
3480 for (
unsigned i = 0; i != NumElts; ++i) {
3481 int &M = NewMask[i];
3484 if (!DemandedElts[i] || (M < (
int)NumElts && UndefLHS[M]) ||
3485 (M >= (
int)NumElts && UndefRHS[M - NumElts])) {
3489 IdentityLHS &= (M < 0) || (M == (
int)i);
3490 IdentityRHS &= (M < 0) || ((M - NumElts) == i);
3495 if (Updated && !IdentityLHS && !IdentityRHS && !TLO.
LegalOps) {
3497 buildLegalVectorShuffle(VT,
DL,
LHS,
RHS, NewMask, TLO.
DAG);
3503 for (
unsigned i = 0; i != NumElts; ++i) {
3504 int M = ShuffleMask[i];
3507 }
else if (M < (
int)NumElts) {
3513 if (UndefRHS[M - NumElts])
3515 if (ZeroRHS[M - NumElts])
3524 APInt SrcUndef, SrcZero;
3526 unsigned NumSrcElts = Src.getValueType().getVectorNumElements();
3527 APInt DemandedSrcElts = DemandedElts.
zext(NumSrcElts);
3528 if (SimplifyDemandedVectorElts(Src, DemandedSrcElts, SrcUndef, SrcZero, TLO,
3535 Op.getValueSizeInBits() == Src.getValueSizeInBits() &&
3536 DemandedSrcElts == 1) {
3549 if (IsLE && DemandedSrcElts == 1 && Src.getOpcode() ==
ISD::AND &&
3550 Op->isOnlyUserOf(Src.getNode()) &&
3551 Op.getValueSizeInBits() == Src.getValueSizeInBits()) {
3553 EVT SrcVT = Src.getValueType();
3560 ISD::AND,
DL, SrcVT, {Src.getOperand(1), Mask})) {
3574 if (Op0 == Op1 &&
Op->isOnlyUserOf(Op0.
getNode())) {
3575 APInt UndefLHS, ZeroLHS;
3576 if (SimplifyDemandedVectorElts(Op0, DemandedElts, UndefLHS, ZeroLHS, TLO,
3597 APInt UndefRHS, ZeroRHS;
3598 if (SimplifyDemandedVectorElts(Op1, DemandedElts, UndefRHS, ZeroRHS, TLO,
3601 APInt UndefLHS, ZeroLHS;
3602 if (SimplifyDemandedVectorElts(Op0, DemandedElts, UndefLHS, ZeroLHS, TLO,
3606 KnownZero = ZeroLHS & ZeroRHS;
3612 if (SimplifyDemandedVectorEltsBinOp(Op0, Op1))
3624 APInt UndefRHS, ZeroRHS;
3625 if (SimplifyDemandedVectorElts(Op1, DemandedElts, UndefRHS, ZeroRHS, TLO,
3628 APInt UndefLHS, ZeroLHS;
3629 if (SimplifyDemandedVectorElts(Op0, DemandedElts, UndefLHS, ZeroLHS, TLO,
3633 KnownZero = ZeroLHS;
3634 KnownUndef = UndefLHS & UndefRHS;
3639 if (SimplifyDemandedVectorEltsBinOp(Op0, Op1))
3650 APInt SrcUndef, SrcZero;
3651 if (SimplifyDemandedVectorElts(Op1, DemandedElts, SrcUndef, SrcZero, TLO,
3656 APInt DemandedElts0 = DemandedElts & ~SrcZero;
3657 if (SimplifyDemandedVectorElts(Op0, DemandedElts0, KnownUndef, KnownZero,
3661 KnownUndef &= DemandedElts0;
3662 KnownZero &= DemandedElts0;
3667 if (DemandedElts.
isSubsetOf(SrcZero | KnownZero | SrcUndef | KnownUndef))
3674 KnownZero |= SrcZero;
3675 KnownUndef &= SrcUndef;
3676 KnownUndef &= ~KnownZero;
3680 if (SimplifyDemandedVectorEltsBinOp(Op0, Op1))
3687 if (SimplifyDemandedVectorElts(
Op.getOperand(0), DemandedElts, KnownUndef,
3688 KnownZero, TLO,
Depth + 1))
3700 if (SimplifyDemandedVectorEltsForTargetNode(
Op, DemandedElts, KnownUndef,
3701 KnownZero, TLO,
Depth))
3706 if (SimplifyDemandedBits(
Op,
DemandedBits, OriginalDemandedElts, Known,
3707 TLO,
Depth, AssumeSingleUse))
3713 assert((KnownUndef & KnownZero) == 0 &&
"Elements flagged as undef AND zero");
3727 const APInt &DemandedElts,
3729 unsigned Depth)
const {
3734 "Should use MaskedValueIsZero if you don't know whether Op"
3735 " is a target node!");
3742 unsigned Depth)
const {
3754 unsigned Depth)
const {
3763 unsigned Depth)
const {
3768 "Should use ComputeNumSignBits if you don't know whether Op"
3769 " is a target node!");
3786 "Should use SimplifyDemandedVectorElts if you don't know whether Op"
3787 " is a target node!");
3798 "Should use SimplifyDemandedBits if you don't know whether Op"
3799 " is a target node!");
3800 computeKnownBitsForTargetNode(
Op, Known, DemandedElts, TLO.
DAG,
Depth);
3812 "Should use SimplifyMultipleUseDemandedBits if you don't know whether Op"
3813 " is a target node!");
3846 "Should use isGuaranteedNotToBeUndefOrPoison if you don't know whether Op"
3847 " is a target node!");
3851 return !canCreateUndefOrPoisonForTargetNode(
Op, DemandedElts, DAG,
PoisonOnly,
3854 return DAG.isGuaranteedNotToBeUndefOrPoison(V, PoisonOnly,
3866 "Should use canCreateUndefOrPoison if you don't know whether Op"
3867 " is a target node!");
3875 unsigned Depth)
const {
3880 "Should use isKnownNeverNaN if you don't know whether Op"
3881 " is a target node!");
3886 const APInt &DemandedElts,
3889 unsigned Depth)
const {
3894 "Should use isSplatValue if you don't know whether Op"
3895 " is a target node!");
3910 CVal = CN->getAPIntValue();
3911 EltWidth =
N.getValueType().getScalarSizeInBits();
3918 CVal = CVal.
trunc(EltWidth);
3924 return CVal.
isOne();
3966 return (
N->isOne() && !SExt) || (SExt && (
N->getValueType(0) != MVT::i1));
3969 return N->isAllOnes() && SExt;
3978 DAGCombinerInfo &DCI)
const {
4006 auto *AndC = dyn_cast<ConstantSDNode>(N0.
getOperand(1));
4007 if (AndC &&
isNullConstant(N1) && AndC->getAPIntValue().isPowerOf2() &&
4010 AndC->getAPIntValue().getActiveBits());
4037 if (isXAndYEqZeroPreferableToXAndYEqY(
Cond, OpVT) &&
4045 if (DCI.isBeforeLegalizeOps() ||
4079SDValue TargetLowering::optimizeSetCCOfSignedTruncationCheck(
4084 if (!(C1 = dyn_cast<ConstantSDNode>(N1)))
4093 if (!(C01 = dyn_cast<ConstantSDNode>(N0->
getOperand(1))))
4097 EVT XVT =
X.getValueType();
4121 auto checkConstants = [&
I1, &I01]() ->
bool {
4126 if (checkConstants()) {
4134 if (!checkConstants())
4140 const unsigned KeptBits =
I1.logBase2();
4141 const unsigned KeptBitsMinusOne = I01.
logBase2();
4144 if (KeptBits != (KeptBitsMinusOne + 1))
4159 return DAG.
getSetCC(
DL, SCCVT, SExtInReg,
X, NewCond);
4163SDValue TargetLowering::optimizeSetCCByHoistingAndByConstFromLogicalShift(
4165 DAGCombinerInfo &DCI,
const SDLoc &
DL)
const {
4167 "Should be a comparison with 0.");
4169 "Valid only for [in]equality comparisons.");
4171 unsigned NewShiftOpcode;
4182 unsigned OldShiftOpcode =
V.getOpcode();
4183 switch (OldShiftOpcode) {
4195 C =
V.getOperand(0);
4200 Y =
V.getOperand(1);
4204 return TLI.shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
4205 X, XC,
CC,
Y, OldShiftOpcode, NewShiftOpcode, DAG);
4222 EVT VT =
X.getValueType();
4237 DAGCombinerInfo &DCI)
const {
4240 "Unexpected binop");
4268 if (!DCI.isCalledByLegalizer())
4269 DCI.AddToWorklist(YShl1.
getNode());
4284 if (CTPOP.getOpcode() !=
ISD::CTPOP || !CTPOP.hasOneUse())
4287 EVT CTVT = CTPOP.getValueType();
4288 SDValue CTOp = CTPOP.getOperand(0);
4308 for (
unsigned i = 0; i <
Passes; i++) {
4357 auto getRotateSource = [](
SDValue X) {
4359 return X.getOperand(0);