58 using namespace PatternMatch;
60 #define DEBUG_TYPE "instcombine"
62 STATISTIC(NumSimplified,
"Number of library calls simplified");
65 "unfold-element-atomic-memcpy-max-elements",
67 cl::desc(
"Maximum number of elements in atomic memcpy the optimizer is "
68 "allowed to unfold"));
74 if (ITy->getBitWidth() < 32)
87 assert((isa<ConstantInt>(Elt) || isa<ConstantFP>(Elt)) &&
88 "Unexpected constant data vector element type");
90 ? cast<ConstantInt>(Elt)->isNegative()
91 : cast<ConstantFP>(Elt)->isNegative();
97 Instruction *InstCombiner::SimplifyElementUnorderedAtomicMemCpy(
109 uint64_t NumElements = LengthInBytes / ElementSizeInBytes;
114 if (NumElements > 0) {
116 uint64_t ElementSizeInBits = ElementSizeInBytes * 8;
117 if (!getDataLayout().isLegalInteger(ElementSizeInBits))
127 Type *ElementPointerType =
131 Value *SrcCasted = Builder.CreatePointerCast(Src, ElementPointerType,
132 "memcpy_unfold.src_casted");
133 Value *DstCasted = Builder.CreatePointerCast(Dst, ElementPointerType,
134 "memcpy_unfold.dst_casted");
136 for (uint64_t i = 0; i < NumElements; ++i) {
140 Value *SrcElementAddr =
141 Builder.CreateGEP(SrcCasted, ElementIdxCI,
"memcpy_unfold.src_addr");
142 Value *DstElementAddr =
143 Builder.CreateGEP(DstCasted, ElementIdxCI,
"memcpy_unfold.dst_addr");
147 LoadInst *
Load = Builder.CreateLoad(SrcElementAddr,
"memcpy_unfold.val");
156 : ElementSizeInBytes);
163 : ElementSizeInBytes);
178 unsigned CopyAlign = MI->getAlignment();
180 if (CopyAlign < MinAlign) {
188 if (!MemOpLength)
return nullptr;
195 assert(Size &&
"0-sized memory transferring should be removed already.");
197 if (Size > 8 || (Size&(Size-1)))
202 cast<PointerType>(MI->getArgOperand(1)->getType())->getAddressSpace();
204 cast<PointerType>(MI->getArgOperand(0)->getType())->getAddressSpace();
214 if (M->getNumOperands() == 3 && M->getOperand(0) &&
215 mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
216 mdconst::extract<ConstantInt>(M->getOperand(0))->
isZero() &&
218 mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
219 mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
221 M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
222 CopyMD = cast<MDNode>(M->getOperand(2));
227 SrcAlign =
std::max(SrcAlign, CopyAlign);
228 DstAlign =
std::max(DstAlign, CopyAlign);
230 Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
231 Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
232 LoadInst *
L = Builder.CreateLoad(Src, MI->isVolatile());
236 MDNode *LoopMemParallelMD =
238 if (LoopMemParallelMD)
241 StoreInst *S = Builder.CreateStore(L, Dest, MI->isVolatile());
245 if (LoopMemParallelMD)
255 if (MI->getAlignment() < Alignment) {
267 Alignment = MI->getAlignment();
268 assert(Len &&
"0-sized memory setting should be removed already.");
274 Value *Dest = MI->getDest();
275 unsigned DstAddrSp = cast<PointerType>(Dest->getType())->getAddressSpace();
277 Dest = Builder.CreateBitCast(Dest, NewDstPtrTy);
280 if (Alignment == 0) Alignment = 1;
283 uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL;
298 bool LogicalShift =
false;
299 bool ShiftLeft =
false;
303 case Intrinsic::x86_sse2_psra_d:
304 case Intrinsic::x86_sse2_psra_w:
305 case Intrinsic::x86_sse2_psrai_d:
306 case Intrinsic::x86_sse2_psrai_w:
307 case Intrinsic::x86_avx2_psra_d:
308 case Intrinsic::x86_avx2_psra_w:
309 case Intrinsic::x86_avx2_psrai_d:
310 case Intrinsic::x86_avx2_psrai_w:
311 case Intrinsic::x86_avx512_psra_q_128:
312 case Intrinsic::x86_avx512_psrai_q_128:
313 case Intrinsic::x86_avx512_psra_q_256:
314 case Intrinsic::x86_avx512_psrai_q_256:
315 case Intrinsic::x86_avx512_psra_d_512:
316 case Intrinsic::x86_avx512_psra_q_512:
317 case Intrinsic::x86_avx512_psra_w_512:
318 case Intrinsic::x86_avx512_psrai_d_512:
319 case Intrinsic::x86_avx512_psrai_q_512:
320 case Intrinsic::x86_avx512_psrai_w_512:
321 LogicalShift =
false; ShiftLeft =
false;
323 case Intrinsic::x86_sse2_psrl_d:
324 case Intrinsic::x86_sse2_psrl_q:
325 case Intrinsic::x86_sse2_psrl_w:
326 case Intrinsic::x86_sse2_psrli_d:
327 case Intrinsic::x86_sse2_psrli_q:
328 case Intrinsic::x86_sse2_psrli_w:
329 case Intrinsic::x86_avx2_psrl_d:
330 case Intrinsic::x86_avx2_psrl_q:
331 case Intrinsic::x86_avx2_psrl_w:
332 case Intrinsic::x86_avx2_psrli_d:
333 case Intrinsic::x86_avx2_psrli_q:
334 case Intrinsic::x86_avx2_psrli_w:
335 case Intrinsic::x86_avx512_psrl_d_512:
336 case Intrinsic::x86_avx512_psrl_q_512:
337 case Intrinsic::x86_avx512_psrl_w_512:
338 case Intrinsic::x86_avx512_psrli_d_512:
339 case Intrinsic::x86_avx512_psrli_q_512:
340 case Intrinsic::x86_avx512_psrli_w_512:
341 LogicalShift =
true; ShiftLeft =
false;
343 case Intrinsic::x86_sse2_psll_d:
344 case Intrinsic::x86_sse2_psll_q:
345 case Intrinsic::x86_sse2_psll_w:
346 case Intrinsic::x86_sse2_pslli_d:
347 case Intrinsic::x86_sse2_pslli_q:
348 case Intrinsic::x86_sse2_pslli_w:
349 case Intrinsic::x86_avx2_psll_d:
350 case Intrinsic::x86_avx2_psll_q:
351 case Intrinsic::x86_avx2_psll_w:
352 case Intrinsic::x86_avx2_pslli_d:
353 case Intrinsic::x86_avx2_pslli_q:
354 case Intrinsic::x86_avx2_pslli_w:
355 case Intrinsic::x86_avx512_psll_d_512:
356 case Intrinsic::x86_avx512_psll_q_512:
357 case Intrinsic::x86_avx512_psll_w_512:
358 case Intrinsic::x86_avx512_pslli_d_512:
359 case Intrinsic::x86_avx512_pslli_q_512:
360 case Intrinsic::x86_avx512_pslli_w_512:
361 LogicalShift =
true; ShiftLeft =
true;
364 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
371 if (!CAZ && !CDV && !CInt)
378 auto VT = cast<VectorType>(CDV->getType());
379 unsigned BitWidth = VT->getElementType()->getPrimitiveSizeInBits();
380 assert((64 % BitWidth) == 0 &&
"Unexpected packed shift size");
381 unsigned NumSubElts = 64 / BitWidth;
384 for (
unsigned i = 0; i != NumSubElts; ++i) {
385 unsigned SubEltIdx = (NumSubElts - 1) - i;
386 auto SubElt = cast<ConstantInt>(CDV->getElementAsConstant(SubEltIdx));
392 Count = CInt->getValue();
395 auto VT = cast<VectorType>(Vec->getType());
396 auto SVT = VT->getElementType();
397 unsigned VWidth = VT->getNumElements();
398 unsigned BitWidth = SVT->getPrimitiveSizeInBits();
405 if (Count.
uge(BitWidth)) {
411 Count =
APInt(64, BitWidth - 1);
432 bool LogicalShift =
false;
433 bool ShiftLeft =
false;
437 case Intrinsic::x86_avx2_psrav_d:
438 case Intrinsic::x86_avx2_psrav_d_256:
439 case Intrinsic::x86_avx512_psrav_q_128:
440 case Intrinsic::x86_avx512_psrav_q_256:
441 case Intrinsic::x86_avx512_psrav_d_512:
442 case Intrinsic::x86_avx512_psrav_q_512:
443 case Intrinsic::x86_avx512_psrav_w_128:
444 case Intrinsic::x86_avx512_psrav_w_256:
445 case Intrinsic::x86_avx512_psrav_w_512:
446 LogicalShift =
false;
449 case Intrinsic::x86_avx2_psrlv_d:
450 case Intrinsic::x86_avx2_psrlv_d_256:
451 case Intrinsic::x86_avx2_psrlv_q:
452 case Intrinsic::x86_avx2_psrlv_q_256:
453 case Intrinsic::x86_avx512_psrlv_d_512:
454 case Intrinsic::x86_avx512_psrlv_q_512:
455 case Intrinsic::x86_avx512_psrlv_w_128:
456 case Intrinsic::x86_avx512_psrlv_w_256:
457 case Intrinsic::x86_avx512_psrlv_w_512:
461 case Intrinsic::x86_avx2_psllv_d:
462 case Intrinsic::x86_avx2_psllv_d_256:
463 case Intrinsic::x86_avx2_psllv_q:
464 case Intrinsic::x86_avx2_psllv_q_256:
465 case Intrinsic::x86_avx512_psllv_d_512:
466 case Intrinsic::x86_avx512_psllv_q_512:
467 case Intrinsic::x86_avx512_psllv_w_128:
468 case Intrinsic::x86_avx512_psllv_w_256:
469 case Intrinsic::x86_avx512_psllv_w_512:
474 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
482 auto VT = cast<VectorType>(II.
getType());
483 auto SVT = VT->getVectorElementType();
484 int NumElts = VT->getNumElements();
485 int BitWidth = SVT->getIntegerBitWidth();
489 bool AnyOutOfRange =
false;
491 for (
int I = 0;
I < NumElts; ++
I) {
492 auto *CElt = CShift->getAggregateElement(
I);
493 if (CElt && isa<UndefValue>(CElt)) {
498 auto *COp = dyn_cast_or_null<ConstantInt>(CElt);
505 APInt ShiftVal = COp->getValue();
506 if (ShiftVal.
uge(BitWidth)) {
507 AnyOutOfRange = LogicalShift;
508 ShiftAmts.
push_back(LogicalShift ? BitWidth : BitWidth - 1);
517 auto OutOfRange = [&](
int Idx) {
return (Idx < 0) || (BitWidth <= Idx); };
518 if (
all_of(ShiftAmts, OutOfRange)) {
520 for (
int Idx : ShiftAmts) {
524 assert(LogicalShift &&
"Logical shift expected");
537 for (
int Idx : ShiftAmts) {
564 if (isa<UndefValue>(Arg0) || isa<UndefValue>(Arg1))
572 if (!isa<Constant>(Arg0) || !isa<Constant>(Arg1))
578 "Unexpected muldq/muludq types");
581 bool IsSigned = (Intrinsic::x86_sse41_pmuldq == IntrinsicID ||
582 Intrinsic::x86_avx2_pmul_dq == IntrinsicID ||
583 Intrinsic::x86_avx512_pmul_dq_512 == IntrinsicID);
586 for (
unsigned i = 0; i != NumElts; ++i)
609 if (isa<UndefValue>(Arg0) && isa<UndefValue>(Arg1))
616 assert(NumDstElts == (2 * NumSrcElts) &&
"Unexpected packing types");
618 unsigned NumDstEltsPerLane = NumDstElts / NumLanes;
619 unsigned NumSrcEltsPerLane = NumSrcElts / NumLanes;
622 "Unexpected packing types");
631 for (
unsigned Lane = 0; Lane != NumLanes; ++Lane) {
632 for (
unsigned Elt = 0; Elt != NumDstEltsPerLane; ++Elt) {
633 unsigned SrcIdx = Lane * NumSrcEltsPerLane + Elt % NumSrcEltsPerLane;
634 auto *Cst = (Elt >= NumSrcEltsPerLane) ? Cst1 : Cst0;
635 auto *COp = Cst->getAggregateElement(SrcIdx);
636 if (COp && isa<UndefValue>(COp)) {
641 auto *CInt = dyn_cast_or_null<ConstantInt>(COp);
645 APInt Val = CInt->getValue();
647 "Unexpected constant bitwidth");
654 Val = Val.
trunc(DstScalarSizeInBits);
663 if (Val.
isIntN(DstScalarSizeInBits))
664 Val = Val.
trunc(DstScalarSizeInBits);
684 if (isa<UndefValue>(Arg))
698 auto *COp =
C->getAggregateElement(
I);
701 if (isa<UndefValue>(COp))
709 if ((CInt && CInt->isNegative()) || (CFp && CFp->isNegative()))
730 uint8_t Imm = CInt->getZExtValue();
731 uint8_t ZMask = Imm & 0xf;
732 uint8_t DestLane = (Imm >> 4) & 0x3;
733 uint8_t SourceLane = (Imm >> 6) & 0x3;
743 uint32_t ShuffleMask[4] = { 0, 1, 2, 3 };
752 (ZMask & (1 << DestLane))) {
756 ShuffleMask[DestLane] = SourceLane;
758 for (
unsigned i = 0; i < 4; ++i)
759 if ((ZMask >> i) & 0x1)
760 ShuffleMask[i] = i + 4;
767 ShuffleMask[DestLane] = SourceLane + 4;
778 auto LowConstantHighUndef = [&](uint64_t Val) {
792 if (CILength && CIIndex) {
802 unsigned Length = APLength == 0 ? 64 : APLength.
getZExtValue();
806 unsigned End = Index + Length;
817 if ((Length % 8) == 0 && (Index % 8) == 0) {
827 for (
int i = 0; i != (int)Length; ++i)
830 for (
int i = Length; i != 8; ++i)
833 for (
int i = 8; i != 16; ++i)
845 APInt Elt = CI0->getValue();
853 Value *
Args[] = {Op0, CILength, CIIndex};
861 if (CI0 && CI0->isZero())
862 return LowConstantHighUndef(0);
882 unsigned Length = APLength == 0 ? 64 : APLength.
getZExtValue();
886 unsigned End = Index + Length;
897 if ((Length % 8) == 0 && (Index % 8) == 0) {
907 for (
int i = 0; i != (int)Index; ++i)
909 for (
int i = 0; i != (int)Length; ++i)
912 for (
int i = Index + Length; i != 8; ++i)
914 for (
int i = 8; i != 16; ++i)
930 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)0))
935 APInt V00 = CI00->getValue();
936 APInt V10 = CI10->getValue();
940 APInt Val = V00 | V10;
954 Value *
Args[] = {Op0, Op1, CILength, CIIndex};
970 auto *VecTy = cast<VectorType>(II.
getType());
972 unsigned NumElts = VecTy->getNumElements();
973 assert((NumElts == 16 || NumElts == 32 || NumElts == 64) &&
974 "Unexpected number of elements in shuffle mask!");
981 for (
unsigned I = 0;
I < NumElts; ++
I) {
983 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
986 if (isa<UndefValue>(COp)) {
991 int8_t Index = cast<ConstantInt>(COp)->getValue().getZExtValue();
1000 Index = ((Index < 0) ? NumElts : Index & 0x0F) + (
I & 0xF0);
1017 auto *VecTy = cast<VectorType>(II.
getType());
1020 bool IsPD = VecTy->getScalarType()->isDoubleTy();
1021 unsigned NumLaneElts = IsPD ? 2 : 4;
1022 assert(NumElts == 16 || NumElts == 8 || NumElts == 4 || NumElts == 2);
1028 for (
unsigned I = 0;
I < NumElts; ++
I) {
1030 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
1033 if (isa<UndefValue>(COp)) {
1038 APInt Index = cast<ConstantInt>(COp)->getValue();
1049 Index +=
APInt(32, (
I / NumLaneElts) * NumLaneElts);
1067 auto *VecTy = cast<VectorType>(II.
getType());
1069 unsigned Size = VecTy->getNumElements();
1070 assert((Size == 4 || Size == 8 || Size == 16 || Size == 32 || Size == 64) &&
1071 "Unexpected shuffle mask size");
1076 for (
unsigned I = 0;
I <
Size; ++
I) {
1078 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
1081 if (isa<UndefValue>(COp)) {
1086 uint32_t Index = cast<ConstantInt>(COp)->getZExtValue();
1117 uint8_t Imm = CInt->getZExtValue();
1119 bool LowHalfZero = Imm & 0x08;
1120 bool HighHalfZero = Imm & 0x80;
1124 if (LowHalfZero && HighHalfZero)
1129 unsigned HalfSize = NumElts / 2;
1133 bool LowInputSelect = Imm & 0x02;
1134 bool HighInputSelect = Imm & 0x20;
1138 bool LowHalfSelect = Imm & 0x01;
1139 bool HighHalfSelect = Imm & 0x10;
1146 V0 = LowHalfZero ? ZeroVector : V0;
1147 V1 = HighHalfZero ? ZeroVector : V1;
1150 unsigned StartIndex = LowHalfSelect ? HalfSize : 0;
1151 for (
unsigned i = 0; i < HalfSize; ++i)
1152 ShuffleMask[i] = StartIndex + i;
1155 StartIndex = HighHalfSelect ? HalfSize : 0;
1156 StartIndex += NumElts;
1157 for (
unsigned i = 0; i < HalfSize; ++i)
1158 ShuffleMask[i + HalfSize] = StartIndex + i;
1167 if (
auto *CInt = dyn_cast<ConstantInt>(II.
getArgOperand(2))) {
1168 uint64_t Imm = CInt->getZExtValue() & 0x7;
1210 if (
auto *
C = dyn_cast<ConstantInt>(Mask))
1211 if (
C->getValue().zextOrTrunc(VWidth).isAllOnesValue())
1222 for (
unsigned i = 0; i != VWidth; ++i)
1243 if (C1 && C1->isNaN())
1250 if (isa<UndefValue>(Arg0))
1254 if (isa<UndefValue>(Arg1))
1263 if (Arg0 == X || Arg0 == Y)
1270 if (Arg1 == X || Arg1 == Y)
1276 if (C1 && C1->isInfinity()) {
1278 if (C1->isNegative())
1286 if (Arg0 == X || Arg0 == Y)
1293 if (Arg1 == X || Arg1 == Y)
1299 if (C1 && C1->isInfinity()) {
1301 if (!C1->isNegative())
1312 if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
1314 for (
unsigned I = 0,
E = ConstMask->getType()->getVectorNumElements();
I !=
E;
1316 if (
auto *MaskElt = ConstMask->getAggregateElement(
I))
1317 if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
1330 unsigned Alignment = cast<ConstantInt>(II.
getArgOperand(1))->getZExtValue();
1343 if (ConstMask->isNullValue())
1347 if (ConstMask->isAllOnesValue()) {
1349 unsigned Alignment = cast<ConstantInt>(II.
getArgOperand(2))->getZExtValue();
1359 if (ConstMask && ConstMask->isNullValue())
1368 if (ConstMask && ConstMask->isNullValue())
1377 "Expected cttz or ctlz intrinsic");
1393 if (PossibleZeros == DefiniteZeros) {
1427 "Expected ctpop intrinsic");
1434 unsigned BitWidth =
IT->getBitWidth();
1464 if (isa<ConstantAggregateZero>(Mask))
1476 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1500 if (isa<ConstantAggregateZero>(Mask)) {
1519 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1545 return maxnum(Src1, Src2);
1550 return maxnum(Src0, Src2);
1552 return maxnum(Src0, Src1);
1558 unsigned NumOperands) {
1561 for (
unsigned i = 0; i < NumOperands; i++)
1579 "Start intrinsic does not have expected ID");
1581 for (++BI; BI != BE; ++BI) {
1582 if (
auto *
E = dyn_cast<IntrinsicInst>(BI)) {
1583 if (isa<DbgInfoIntrinsic>(
E) ||
E->getIntrinsicID() == StartID)
1585 if (
E->getIntrinsicID() == EndID &&
1610 enum FtzRequirementTy {
1624 struct SimplifyAction {
1631 FtzRequirementTy FtzRequirement = FTZ_Any;
1633 SimplifyAction() =
default;
1636 : IID(IID), FtzRequirement(FtzReq) {}
1643 : BinaryOp(BinaryOp), FtzRequirement(FtzReq) {}
1645 SimplifyAction(SpecialCase Special, FtzRequirementTy FtzReq)
1646 : Special(Special), FtzRequirement(FtzReq) {}
1651 const SimplifyAction Action = [II]() -> SimplifyAction {
1655 case Intrinsic::nvvm_ceil_d:
1656 return {Intrinsic::ceil, FTZ_Any};
1657 case Intrinsic::nvvm_ceil_f:
1658 return {Intrinsic::ceil, FTZ_MustBeOff};
1659 case Intrinsic::nvvm_ceil_ftz_f:
1660 return {Intrinsic::ceil, FTZ_MustBeOn};
1661 case Intrinsic::nvvm_fabs_d:
1662 return {Intrinsic::fabs, FTZ_Any};
1663 case Intrinsic::nvvm_fabs_f:
1664 return {Intrinsic::fabs, FTZ_MustBeOff};
1665 case Intrinsic::nvvm_fabs_ftz_f:
1666 return {Intrinsic::fabs, FTZ_MustBeOn};
1667 case Intrinsic::nvvm_floor_d:
1668 return {Intrinsic::floor, FTZ_Any};
1669 case Intrinsic::nvvm_floor_f:
1670 return {Intrinsic::floor, FTZ_MustBeOff};
1671 case Intrinsic::nvvm_floor_ftz_f:
1672 return {Intrinsic::floor, FTZ_MustBeOn};
1673 case Intrinsic::nvvm_fma_rn_d:
1674 return {Intrinsic::fma, FTZ_Any};
1675 case Intrinsic::nvvm_fma_rn_f:
1676 return {Intrinsic::fma, FTZ_MustBeOff};
1677 case Intrinsic::nvvm_fma_rn_ftz_f:
1678 return {Intrinsic::fma, FTZ_MustBeOn};
1679 case Intrinsic::nvvm_fmax_d:
1681 case Intrinsic::nvvm_fmax_f:
1683 case Intrinsic::nvvm_fmax_ftz_f:
1685 case Intrinsic::nvvm_fmin_d:
1687 case Intrinsic::nvvm_fmin_f:
1689 case Intrinsic::nvvm_fmin_ftz_f:
1691 case Intrinsic::nvvm_round_d:
1693 case Intrinsic::nvvm_round_f:
1695 case Intrinsic::nvvm_round_ftz_f:
1697 case Intrinsic::nvvm_sqrt_rn_d:
1698 return {Intrinsic::sqrt, FTZ_Any};
1699 case Intrinsic::nvvm_sqrt_f:
1704 return {Intrinsic::sqrt, FTZ_Any};
1705 case Intrinsic::nvvm_sqrt_rn_f:
1706 return {Intrinsic::sqrt, FTZ_MustBeOff};
1707 case Intrinsic::nvvm_sqrt_rn_ftz_f:
1708 return {Intrinsic::sqrt, FTZ_MustBeOn};
1709 case Intrinsic::nvvm_trunc_d:
1710 return {Intrinsic::trunc, FTZ_Any};
1711 case Intrinsic::nvvm_trunc_f:
1712 return {Intrinsic::trunc, FTZ_MustBeOff};
1713 case Intrinsic::nvvm_trunc_ftz_f:
1714 return {Intrinsic::trunc, FTZ_MustBeOn};
1721 case Intrinsic::nvvm_d2i_rz:
1722 case Intrinsic::nvvm_f2i_rz:
1723 case Intrinsic::nvvm_d2ll_rz:
1724 case Intrinsic::nvvm_f2ll_rz:
1725 return {Instruction::FPToSI};
1726 case Intrinsic::nvvm_d2ui_rz:
1727 case Intrinsic::nvvm_f2ui_rz:
1728 case Intrinsic::nvvm_d2ull_rz:
1729 case Intrinsic::nvvm_f2ull_rz:
1730 return {Instruction::FPToUI};
1731 case Intrinsic::nvvm_i2d_rz:
1732 case Intrinsic::nvvm_i2f_rz:
1733 case Intrinsic::nvvm_ll2d_rz:
1734 case Intrinsic::nvvm_ll2f_rz:
1735 return {Instruction::SIToFP};
1736 case Intrinsic::nvvm_ui2d_rz:
1737 case Intrinsic::nvvm_ui2f_rz:
1738 case Intrinsic::nvvm_ull2d_rz:
1739 case Intrinsic::nvvm_ull2f_rz:
1740 return {Instruction::UIToFP};
1743 case Intrinsic::nvvm_add_rn_d:
1744 return {Instruction::FAdd, FTZ_Any};
1745 case Intrinsic::nvvm_add_rn_f:
1746 return {Instruction::FAdd, FTZ_MustBeOff};
1747 case Intrinsic::nvvm_add_rn_ftz_f:
1748 return {Instruction::FAdd, FTZ_MustBeOn};
1749 case Intrinsic::nvvm_mul_rn_d:
1750 return {Instruction::FMul, FTZ_Any};
1751 case Intrinsic::nvvm_mul_rn_f:
1752 return {Instruction::FMul, FTZ_MustBeOff};
1753 case Intrinsic::nvvm_mul_rn_ftz_f:
1754 return {Instruction::FMul, FTZ_MustBeOn};
1755 case Intrinsic::nvvm_div_rn_d:
1756 return {Instruction::FDiv, FTZ_Any};
1757 case Intrinsic::nvvm_div_rn_f:
1758 return {Instruction::FDiv, FTZ_MustBeOff};
1759 case Intrinsic::nvvm_div_rn_ftz_f:
1760 return {Instruction::FDiv, FTZ_MustBeOn};
1767 case Intrinsic::nvvm_rcp_rn_d:
1768 return {SPC_Reciprocal, FTZ_Any};
1769 case Intrinsic::nvvm_rcp_rn_f:
1770 return {SPC_Reciprocal, FTZ_MustBeOff};
1771 case Intrinsic::nvvm_rcp_rn_ftz_f:
1772 return {SPC_Reciprocal, FTZ_MustBeOn};
1803 if (Action.FtzRequirement != FTZ_Any) {
1808 if (FtzEnabled != (Action.FtzRequirement == FTZ_MustBeOn))
1823 if (Action.BinaryOp)
1833 if (!Action.Special)
1836 switch (*Action.Special) {
1837 case SPC_Reciprocal:
1843 llvm_unreachable(
"All SpecialCase enumerators should be handled in switch.");
1862 Args.end(), SQ.getWithInstruction(&CI)))
1863 return replaceInstUsesWith(CI, V);
1866 return visitFree(CI);
1876 if (!II)
return visitCallSite(&CI);
1881 bool Changed =
false;
1884 if (
Constant *NumBytes = dyn_cast<Constant>(MI->getLength())) {
1885 if (NumBytes->isNullValue())
1886 return eraseInstFromFunction(CI);
1888 if (
ConstantInt *CI = dyn_cast<ConstantInt>(NumBytes))
1889 if (CI->getZExtValue() == 1) {
1897 if (MI->isVolatile())
1903 if (
MemMoveInst *MMI = dyn_cast<MemMoveInst>(MI)) {
1904 if (
GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
1905 if (GVSrc->isConstant()) {
1918 if (MTI->getSource() == MTI->getDest())
1919 return eraseInstFromFunction(CI);
1924 if (isa<MemTransferInst>(MI)) {
1927 }
else if (
MemSetInst *MSI = dyn_cast<MemSetInst>(MI)) {
1932 if (Changed)
return II;
1935 if (
auto *AMI = dyn_cast<ElementUnorderedAtomicMemCpyInst>(II)) {
1937 if (
C->isNullValue())
1938 return eraseInstFromFunction(*AMI);
1940 if (
Instruction *
I = SimplifyElementUnorderedAtomicMemCpy(AMI))
1947 auto SimplifyDemandedVectorEltsLow = [
this](
Value *
Op,
unsigned Width,
1948 unsigned DemandedWidth) {
1949 APInt UndefElts(Width, 0);
1951 return SimplifyDemandedVectorElts(Op, DemandedElts, UndefElts);
1956 case Intrinsic::objectsize:
1959 return replaceInstUsesWith(CI,
N);
1962 case Intrinsic::bswap: {
1969 return replaceInstUsesWith(CI, X);
1976 Value *V = Builder.CreateLShr(X, CV);
1982 case Intrinsic::bitreverse: {
1989 return replaceInstUsesWith(CI, X);
1993 case Intrinsic::masked_load:
1995 return replaceInstUsesWith(CI, SimplifiedMaskedOp);
1997 case Intrinsic::masked_store:
1999 case Intrinsic::masked_gather:
2001 case Intrinsic::masked_scatter:
2004 case Intrinsic::powi:
2007 if (Power->isZero())
2013 if (Power->isMinusOne())
2019 case Intrinsic::cttz:
2020 case Intrinsic::ctlz:
2025 case Intrinsic::ctpop:
2030 case Intrinsic::uadd_with_overflow:
2031 case Intrinsic::sadd_with_overflow:
2032 case Intrinsic::umul_with_overflow:
2033 case Intrinsic::smul_with_overflow:
2044 case Intrinsic::usub_with_overflow:
2045 case Intrinsic::ssub_with_overflow: {
2050 Value *OperationResult =
nullptr;
2054 return CreateOverflowTuple(II, OperationResult, OverflowResult);
2064 if (isa<ConstantFP>(Arg0) && !isa<ConstantFP>(Arg1)) {
2070 return replaceInstUsesWith(*II, V);
2073 case Intrinsic::fmuladd: {
2082 return replaceInstUsesWith(*II, Add);
2087 case Intrinsic::fma: {
2092 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
2098 Value *LHS =
nullptr;
2099 Value *RHS =
nullptr;
2110 if (
match(Src0, m_Intrinsic<Intrinsic::fabs>(
m_Value(LHS))) &&
2111 match(Src1, m_Intrinsic<Intrinsic::fabs>(
m_Value(RHS))) && LHS == RHS) {
2126 case Intrinsic::fabs: {
2138 case Intrinsic::ceil:
2139 case Intrinsic::floor:
2141 case Intrinsic::nearbyint:
2142 case Intrinsic::rint:
2143 case Intrinsic::trunc: {
2150 CallInst *NewFabs = Builder.CreateCall(F, ExtSrc);
2152 NewFabs->takeName(II);
2158 case Intrinsic::cos:
2159 case Intrinsic::amdgcn_cos: {
2163 match(Src, m_Intrinsic<Intrinsic::fabs>(
m_Value(SrcSrc)))) {
2172 case Intrinsic::ppc_altivec_lvx:
2173 case Intrinsic::ppc_altivec_lvxl:
2177 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2182 case Intrinsic::ppc_vsx_lxvw4x:
2183 case Intrinsic::ppc_vsx_lxvd2x: {
2185 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2189 case Intrinsic::ppc_altivec_stvx:
2190 case Intrinsic::ppc_altivec_stvxl:
2196 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2200 case Intrinsic::ppc_vsx_stxvw4x:
2201 case Intrinsic::ppc_vsx_stxvd2x: {
2204 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2205 return new StoreInst(II->getArgOperand(0),
Ptr,
false, 1);
2207 case Intrinsic::ppc_qpx_qvlfs:
2212 II->getType()->getVectorNumElements());
2213 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2215 Value *Load = Builder.CreateLoad(Ptr);
2219 case Intrinsic::ppc_qpx_qvlfd:
2223 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2228 case Intrinsic::ppc_qpx_qvstfs:
2233 II->getArgOperand(0)->getType()->getVectorNumElements());
2234 Value *TOp = Builder.CreateFPTrunc(II->getArgOperand(0), VTy);
2236 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2240 case Intrinsic::ppc_qpx_qvstfd:
2246 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2251 case Intrinsic::x86_vcvtph2ps_128:
2252 case Intrinsic::x86_vcvtph2ps_256: {
2253 auto Arg = II->getArgOperand(0);
2254 auto ArgType = cast<VectorType>(Arg->getType());
2255 auto RetType = cast<VectorType>(II->getType());
2256 unsigned ArgWidth = ArgType->getNumElements();
2257 unsigned RetWidth = RetType->getNumElements();
2258 assert(RetWidth <= ArgWidth &&
"Unexpected input/return vector widths");
2259 assert(ArgType->isIntOrIntVectorTy() &&
2260 ArgType->getScalarSizeInBits() == 16 &&
2261 "CVTPH2PS input type should be 16-bit integer vector");
2262 assert(RetType->getScalarType()->isFloatTy() &&
2263 "CVTPH2PS output type should be 32-bit float vector");
2266 if (isa<ConstantAggregateZero>(Arg))
2269 if (isa<ConstantDataVector>(Arg)) {
2270 auto VectorHalfAsShorts = Arg;
2271 if (RetWidth < ArgWidth) {
2273 for (
unsigned i = 0; i != RetWidth; ++i)
2275 VectorHalfAsShorts = Builder.CreateShuffleVector(
2279 auto VectorHalfType =
2282 Builder.CreateBitCast(VectorHalfAsShorts, VectorHalfType);
2283 auto VectorFloats = Builder.CreateFPExt(VectorHalfs, RetType);
2284 return replaceInstUsesWith(*II, VectorFloats);
2288 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg, ArgWidth, RetWidth)) {
2289 II->setArgOperand(0, V);
2295 case Intrinsic::x86_sse_cvtss2si:
2296 case Intrinsic::x86_sse_cvtss2si64:
2297 case Intrinsic::x86_sse_cvttss2si:
2298 case Intrinsic::x86_sse_cvttss2si64:
2299 case Intrinsic::x86_sse2_cvtsd2si:
2300 case Intrinsic::x86_sse2_cvtsd2si64:
2301 case Intrinsic::x86_sse2_cvttsd2si:
2302 case Intrinsic::x86_sse2_cvttsd2si64:
2303 case Intrinsic::x86_avx512_vcvtss2si32:
2304 case Intrinsic::x86_avx512_vcvtss2si64:
2305 case Intrinsic::x86_avx512_vcvtss2usi32:
2306 case Intrinsic::x86_avx512_vcvtss2usi64:
2307 case Intrinsic::x86_avx512_vcvtsd2si32:
2308 case Intrinsic::x86_avx512_vcvtsd2si64:
2309 case Intrinsic::x86_avx512_vcvtsd2usi32:
2310 case Intrinsic::x86_avx512_vcvtsd2usi64:
2311 case Intrinsic::x86_avx512_cvttss2si:
2312 case Intrinsic::x86_avx512_cvttss2si64:
2313 case Intrinsic::x86_avx512_cvttss2usi:
2314 case Intrinsic::x86_avx512_cvttss2usi64:
2315 case Intrinsic::x86_avx512_cvttsd2si:
2316 case Intrinsic::x86_avx512_cvttsd2si64:
2317 case Intrinsic::x86_avx512_cvttsd2usi:
2318 case Intrinsic::x86_avx512_cvttsd2usi64: {
2321 Value *Arg = II->getArgOperand(0);
2323 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg, VWidth, 1)) {
2324 II->setArgOperand(0, V);
2330 case Intrinsic::x86_mmx_pmovmskb:
2331 case Intrinsic::x86_sse_movmsk_ps:
2332 case Intrinsic::x86_sse2_movmsk_pd:
2333 case Intrinsic::x86_sse2_pmovmskb_128:
2334 case Intrinsic::x86_avx_movmsk_pd_256:
2335 case Intrinsic::x86_avx_movmsk_ps_256:
2336 case Intrinsic::x86_avx2_pmovmskb: {
2338 return replaceInstUsesWith(*II, V);
2342 case Intrinsic::x86_sse_comieq_ss:
2343 case Intrinsic::x86_sse_comige_ss:
2344 case Intrinsic::x86_sse_comigt_ss:
2345 case Intrinsic::x86_sse_comile_ss:
2346 case Intrinsic::x86_sse_comilt_ss:
2347 case Intrinsic::x86_sse_comineq_ss:
2348 case Intrinsic::x86_sse_ucomieq_ss:
2349 case Intrinsic::x86_sse_ucomige_ss:
2350 case Intrinsic::x86_sse_ucomigt_ss:
2351 case Intrinsic::x86_sse_ucomile_ss:
2352 case Intrinsic::x86_sse_ucomilt_ss:
2353 case Intrinsic::x86_sse_ucomineq_ss:
2354 case Intrinsic::x86_sse2_comieq_sd:
2355 case Intrinsic::x86_sse2_comige_sd:
2356 case Intrinsic::x86_sse2_comigt_sd:
2357 case Intrinsic::x86_sse2_comile_sd:
2358 case Intrinsic::x86_sse2_comilt_sd:
2359 case Intrinsic::x86_sse2_comineq_sd:
2360 case Intrinsic::x86_sse2_ucomieq_sd:
2361 case Intrinsic::x86_sse2_ucomige_sd:
2362 case Intrinsic::x86_sse2_ucomigt_sd:
2363 case Intrinsic::x86_sse2_ucomile_sd:
2364 case Intrinsic::x86_sse2_ucomilt_sd:
2365 case Intrinsic::x86_sse2_ucomineq_sd:
2366 case Intrinsic::x86_avx512_vcomi_ss:
2367 case Intrinsic::x86_avx512_vcomi_sd:
2368 case Intrinsic::x86_avx512_mask_cmp_ss:
2369 case Intrinsic::x86_avx512_mask_cmp_sd: {
2372 bool MadeChange =
false;
2373 Value *Arg0 = II->getArgOperand(0);
2374 Value *Arg1 = II->getArgOperand(1);
2376 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg0, VWidth, 1)) {
2377 II->setArgOperand(0, V);
2380 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, 1)) {
2381 II->setArgOperand(1, V);
2388 case Intrinsic::x86_avx512_mask_cmp_pd_128:
2389 case Intrinsic::x86_avx512_mask_cmp_pd_256:
2390 case Intrinsic::x86_avx512_mask_cmp_pd_512:
2391 case Intrinsic::x86_avx512_mask_cmp_ps_128:
2392 case Intrinsic::x86_avx512_mask_cmp_ps_256:
2393 case Intrinsic::x86_avx512_mask_cmp_ps_512: {
2395 Value *Arg0 = II->getArgOperand(0);
2396 Value *Arg1 = II->getArgOperand(1);
2410 cast<Instruction>(Arg0)->getFastMathFlags().noInfs())) {
2413 II->setArgOperand(0, A);
2414 II->setArgOperand(1, B);
2420 case Intrinsic::x86_avx512_mask_add_ps_512:
2421 case Intrinsic::x86_avx512_mask_div_ps_512:
2422 case Intrinsic::x86_avx512_mask_mul_ps_512:
2423 case Intrinsic::x86_avx512_mask_sub_ps_512:
2424 case Intrinsic::x86_avx512_mask_add_pd_512:
2425 case Intrinsic::x86_avx512_mask_div_pd_512:
2426 case Intrinsic::x86_avx512_mask_mul_pd_512:
2427 case Intrinsic::x86_avx512_mask_sub_pd_512:
2430 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(4))) {
2431 if (R->getValue() == 4) {
2432 Value *Arg0 = II->getArgOperand(0);
2433 Value *Arg1 = II->getArgOperand(1);
2436 switch (II->getIntrinsicID()) {
2438 case Intrinsic::x86_avx512_mask_add_ps_512:
2439 case Intrinsic::x86_avx512_mask_add_pd_512:
2440 V = Builder.CreateFAdd(Arg0, Arg1);
2442 case Intrinsic::x86_avx512_mask_sub_ps_512:
2443 case Intrinsic::x86_avx512_mask_sub_pd_512:
2444 V = Builder.CreateFSub(Arg0, Arg1);
2446 case Intrinsic::x86_avx512_mask_mul_ps_512:
2447 case Intrinsic::x86_avx512_mask_mul_pd_512:
2448 V = Builder.CreateFMul(Arg0, Arg1);
2450 case Intrinsic::x86_avx512_mask_div_ps_512:
2451 case Intrinsic::x86_avx512_mask_div_pd_512:
2452 V = Builder.CreateFDiv(Arg0, Arg1);
2459 return replaceInstUsesWith(*II, V);
2464 case Intrinsic::x86_avx512_mask_add_ss_round:
2465 case Intrinsic::x86_avx512_mask_div_ss_round:
2466 case Intrinsic::x86_avx512_mask_mul_ss_round:
2467 case Intrinsic::x86_avx512_mask_sub_ss_round:
2468 case Intrinsic::x86_avx512_mask_add_sd_round:
2469 case Intrinsic::x86_avx512_mask_div_sd_round:
2470 case Intrinsic::x86_avx512_mask_mul_sd_round:
2471 case Intrinsic::x86_avx512_mask_sub_sd_round:
2474 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(4))) {
2475 if (R->getValue() == 4) {
2477 Value *Arg0 = II->getArgOperand(0);
2478 Value *Arg1 = II->getArgOperand(1);
2479 Value *LHS = Builder.CreateExtractElement(Arg0, (uint64_t)0);
2480 Value *RHS = Builder.CreateExtractElement(Arg1, (uint64_t)0);
2483 switch (II->getIntrinsicID()) {
2485 case Intrinsic::x86_avx512_mask_add_ss_round:
2486 case Intrinsic::x86_avx512_mask_add_sd_round:
2487 V = Builder.CreateFAdd(LHS, RHS);
2489 case Intrinsic::x86_avx512_mask_sub_ss_round:
2490 case Intrinsic::x86_avx512_mask_sub_sd_round:
2491 V = Builder.CreateFSub(LHS, RHS);
2493 case Intrinsic::x86_avx512_mask_mul_ss_round:
2494 case Intrinsic::x86_avx512_mask_mul_sd_round:
2495 V = Builder.CreateFMul(LHS, RHS);
2497 case Intrinsic::x86_avx512_mask_div_ss_round:
2498 case Intrinsic::x86_avx512_mask_div_sd_round:
2499 V = Builder.CreateFDiv(LHS, RHS);
2507 if (!
C || !
C->getValue()[0]) {
2511 Mask = Builder.CreateBitCast(Mask, MaskTy);
2512 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
2514 Value *Passthru = Builder.CreateExtractElement(II->getArgOperand(2),
2516 V = Builder.CreateSelect(Mask, V, Passthru);
2520 V = Builder.CreateInsertElement(Arg0, V, (uint64_t)0);
2522 return replaceInstUsesWith(*II, V);
2528 case Intrinsic::x86_avx512_mask_max_ss_round:
2529 case Intrinsic::x86_avx512_mask_min_ss_round:
2530 case Intrinsic::x86_avx512_mask_max_sd_round:
2531 case Intrinsic::x86_avx512_mask_min_sd_round:
2532 case Intrinsic::x86_avx512_mask_vfmadd_ss:
2533 case Intrinsic::x86_avx512_mask_vfmadd_sd:
2534 case Intrinsic::x86_avx512_maskz_vfmadd_ss:
2535 case Intrinsic::x86_avx512_maskz_vfmadd_sd:
2536 case Intrinsic::x86_avx512_mask3_vfmadd_ss:
2537 case Intrinsic::x86_avx512_mask3_vfmadd_sd:
2538 case Intrinsic::x86_avx512_mask3_vfmsub_ss:
2539 case Intrinsic::x86_avx512_mask3_vfmsub_sd:
2540 case Intrinsic::x86_avx512_mask3_vfnmsub_ss:
2541 case Intrinsic::x86_avx512_mask3_vfnmsub_sd:
2542 case Intrinsic::x86_fma_vfmadd_ss:
2543 case Intrinsic::x86_fma_vfmsub_ss:
2544 case Intrinsic::x86_fma_vfnmadd_ss:
2545 case Intrinsic::x86_fma_vfnmsub_ss:
2546 case Intrinsic::x86_fma_vfmadd_sd:
2547 case Intrinsic::x86_fma_vfmsub_sd:
2548 case Intrinsic::x86_fma_vfnmadd_sd:
2549 case Intrinsic::x86_fma_vfnmsub_sd:
2550 case Intrinsic::x86_sse_cmp_ss:
2551 case Intrinsic::x86_sse_min_ss:
2552 case Intrinsic::x86_sse_max_ss:
2553 case Intrinsic::x86_sse2_cmp_sd:
2554 case Intrinsic::x86_sse2_min_sd:
2555 case Intrinsic::x86_sse2_max_sd:
2556 case Intrinsic::x86_sse41_round_ss:
2557 case Intrinsic::x86_sse41_round_sd:
2558 case Intrinsic::x86_xop_vfrcz_ss:
2559 case Intrinsic::x86_xop_vfrcz_sd: {
2560 unsigned VWidth = II->getType()->getVectorNumElements();
2561 APInt UndefElts(VWidth, 0);
2563 if (
Value *V = SimplifyDemandedVectorElts(II, AllOnesEltMask, UndefElts)) {
2565 return replaceInstUsesWith(*II, V);
2574 case Intrinsic::x86_sse2_psrai_d:
2575 case Intrinsic::x86_sse2_psrai_w:
2576 case Intrinsic::x86_avx2_psrai_d:
2577 case Intrinsic::x86_avx2_psrai_w:
2578 case Intrinsic::x86_avx512_psrai_q_128:
2579 case Intrinsic::x86_avx512_psrai_q_256:
2580 case Intrinsic::x86_avx512_psrai_d_512:
2581 case Intrinsic::x86_avx512_psrai_q_512:
2582 case Intrinsic::x86_avx512_psrai_w_512:
2583 case Intrinsic::x86_sse2_psrli_d:
2584 case Intrinsic::x86_sse2_psrli_q:
2585 case Intrinsic::x86_sse2_psrli_w:
2586 case Intrinsic::x86_avx2_psrli_d:
2587 case Intrinsic::x86_avx2_psrli_q:
2588 case Intrinsic::x86_avx2_psrli_w:
2589 case Intrinsic::x86_avx512_psrli_d_512:
2590 case Intrinsic::x86_avx512_psrli_q_512:
2591 case Intrinsic::x86_avx512_psrli_w_512:
2592 case Intrinsic::x86_sse2_pslli_d:
2593 case Intrinsic::x86_sse2_pslli_q:
2594 case Intrinsic::x86_sse2_pslli_w:
2595 case Intrinsic::x86_avx2_pslli_d:
2596 case Intrinsic::x86_avx2_pslli_q:
2597 case Intrinsic::x86_avx2_pslli_w:
2598 case Intrinsic::x86_avx512_pslli_d_512:
2599 case Intrinsic::x86_avx512_pslli_q_512:
2600 case Intrinsic::x86_avx512_pslli_w_512:
2602 return replaceInstUsesWith(*II, V);
2605 case Intrinsic::x86_sse2_psra_d:
2606 case Intrinsic::x86_sse2_psra_w:
2607 case Intrinsic::x86_avx2_psra_d:
2608 case Intrinsic::x86_avx2_psra_w:
2609 case Intrinsic::x86_avx512_psra_q_128:
2610 case Intrinsic::x86_avx512_psra_q_256:
2611 case Intrinsic::x86_avx512_psra_d_512:
2612 case Intrinsic::x86_avx512_psra_q_512:
2613 case Intrinsic::x86_avx512_psra_w_512:
2614 case Intrinsic::x86_sse2_psrl_d:
2615 case Intrinsic::x86_sse2_psrl_q:
2616 case Intrinsic::x86_sse2_psrl_w:
2617 case Intrinsic::x86_avx2_psrl_d:
2618 case Intrinsic::x86_avx2_psrl_q:
2619 case Intrinsic::x86_avx2_psrl_w:
2620 case Intrinsic::x86_avx512_psrl_d_512:
2621 case Intrinsic::x86_avx512_psrl_q_512:
2622 case Intrinsic::x86_avx512_psrl_w_512:
2623 case Intrinsic::x86_sse2_psll_d:
2624 case Intrinsic::x86_sse2_psll_q:
2625 case Intrinsic::x86_sse2_psll_w:
2626 case Intrinsic::x86_avx2_psll_d:
2627 case Intrinsic::x86_avx2_psll_q:
2628 case Intrinsic::x86_avx2_psll_w:
2629 case Intrinsic::x86_avx512_psll_d_512:
2630 case Intrinsic::x86_avx512_psll_q_512:
2631 case Intrinsic::x86_avx512_psll_w_512: {
2633 return replaceInstUsesWith(*II, V);
2637 Value *Arg1 = II->getArgOperand(1);
2639 "Unexpected packed shift size");
2642 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, VWidth / 2)) {
2643 II->setArgOperand(1, V);
2649 case Intrinsic::x86_avx2_psllv_d:
2650 case Intrinsic::x86_avx2_psllv_d_256:
2651 case Intrinsic::x86_avx2_psllv_q:
2652 case Intrinsic::x86_avx2_psllv_q_256:
2653 case Intrinsic::x86_avx512_psllv_d_512:
2654 case Intrinsic::x86_avx512_psllv_q_512:
2655 case Intrinsic::x86_avx512_psllv_w_128:
2656 case Intrinsic::x86_avx512_psllv_w_256:
2657 case Intrinsic::x86_avx512_psllv_w_512:
2658 case Intrinsic::x86_avx2_psrav_d:
2659 case Intrinsic::x86_avx2_psrav_d_256:
2660 case Intrinsic::x86_avx512_psrav_q_128:
2661 case Intrinsic::x86_avx512_psrav_q_256:
2662 case Intrinsic::x86_avx512_psrav_d_512:
2663 case Intrinsic::x86_avx512_psrav_q_512:
2664 case Intrinsic::x86_avx512_psrav_w_128:
2665 case Intrinsic::x86_avx512_psrav_w_256:
2666 case Intrinsic::x86_avx512_psrav_w_512:
2667 case Intrinsic::x86_avx2_psrlv_d:
2668 case Intrinsic::x86_avx2_psrlv_d_256:
2669 case Intrinsic::x86_avx2_psrlv_q:
2670 case Intrinsic::x86_avx2_psrlv_q_256:
2671 case Intrinsic::x86_avx512_psrlv_d_512:
2672 case Intrinsic::x86_avx512_psrlv_q_512:
2673 case Intrinsic::x86_avx512_psrlv_w_128:
2674 case Intrinsic::x86_avx512_psrlv_w_256:
2675 case Intrinsic::x86_avx512_psrlv_w_512:
2677 return replaceInstUsesWith(*II, V);
2680 case Intrinsic::x86_sse2_pmulu_dq:
2681 case Intrinsic::x86_sse41_pmuldq:
2682 case Intrinsic::x86_avx2_pmul_dq:
2683 case Intrinsic::x86_avx2_pmulu_dq:
2684 case Intrinsic::x86_avx512_pmul_dq_512:
2685 case Intrinsic::x86_avx512_pmulu_dq_512: {
2687 return replaceInstUsesWith(*II, V);
2689 unsigned VWidth = II->getType()->getVectorNumElements();
2690 APInt UndefElts(VWidth, 0);
2692 if (
Value *V = SimplifyDemandedVectorElts(II, DemandedElts, UndefElts)) {
2694 return replaceInstUsesWith(*II, V);
2700 case Intrinsic::x86_sse2_packssdw_128:
2701 case Intrinsic::x86_sse2_packsswb_128:
2702 case Intrinsic::x86_avx2_packssdw:
2703 case Intrinsic::x86_avx2_packsswb:
2704 case Intrinsic::x86_avx512_packssdw_512:
2705 case Intrinsic::x86_avx512_packsswb_512:
2707 return replaceInstUsesWith(*II, V);
2710 case Intrinsic::x86_sse2_packuswb_128:
2711 case Intrinsic::x86_sse41_packusdw:
2712 case Intrinsic::x86_avx2_packusdw:
2713 case Intrinsic::x86_avx2_packuswb:
2714 case Intrinsic::x86_avx512_packusdw_512:
2715 case Intrinsic::x86_avx512_packuswb_512:
2717 return replaceInstUsesWith(*II, V);
2720 case Intrinsic::x86_pclmulqdq: {
2721 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
2722 unsigned Imm =
C->getZExtValue();
2724 bool MadeChange =
false;
2725 Value *Arg0 = II->getArgOperand(0);
2726 Value *Arg1 = II->getArgOperand(1);
2728 APInt DemandedElts(VWidth, 0);
2730 APInt UndefElts1(VWidth, 0);
2731 DemandedElts = (Imm & 0x01) ? 2 : 1;
2732 if (
Value *V = SimplifyDemandedVectorElts(Arg0, DemandedElts,
2734 II->setArgOperand(0, V);
2738 APInt UndefElts2(VWidth, 0);
2739 DemandedElts = (Imm & 0x10) ? 2 : 1;
2740 if (
Value *V = SimplifyDemandedVectorElts(Arg1, DemandedElts,
2742 II->setArgOperand(1, V);
2747 if (UndefElts1[(Imm & 0x01) ? 1 : 0] ||
2748 UndefElts2[(Imm & 0x10) ? 1 : 0])
2749 return replaceInstUsesWith(*II,
2758 case Intrinsic::x86_sse41_insertps:
2760 return replaceInstUsesWith(*II, V);
2763 case Intrinsic::x86_sse4a_extrq: {
2764 Value *Op0 = II->getArgOperand(0);
2765 Value *Op1 = II->getArgOperand(1);
2770 VWidth1 == 16 &&
"Unexpected operand sizes");
2775 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)0))
2778 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
2783 return replaceInstUsesWith(*II, V);
2787 bool MadeChange =
false;
2788 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
2789 II->setArgOperand(0, V);
2792 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 2)) {
2793 II->setArgOperand(1, V);
2801 case Intrinsic::x86_sse4a_extrqi: {
2804 Value *Op0 = II->getArgOperand(0);
2807 "Unexpected operand size");
2815 return replaceInstUsesWith(*II, V);
2819 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
2820 II->setArgOperand(0, V);
2826 case Intrinsic::x86_sse4a_insertq: {
2827 Value *Op0 = II->getArgOperand(0);
2828 Value *Op1 = II->getArgOperand(1);
2833 "Unexpected operand size");
2838 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
2843 const APInt &V11 = CI11->getValue();
2847 return replaceInstUsesWith(*II, V);
2852 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
2853 II->setArgOperand(0, V);
2859 case Intrinsic::x86_sse4a_insertqi: {
2863 Value *Op0 = II->getArgOperand(0);
2864 Value *Op1 = II->getArgOperand(1);
2869 VWidth1 == 2 &&
"Unexpected operand sizes");
2876 if (CILength && CIIndex) {
2877 APInt Len = CILength->getValue().zextOrTrunc(6);
2880 return replaceInstUsesWith(*II, V);
2885 bool MadeChange =
false;
2886 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
2887 II->setArgOperand(0, V);
2890 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 1)) {
2891 II->setArgOperand(1, V);
2899 case Intrinsic::x86_sse41_pblendvb:
2900 case Intrinsic::x86_sse41_blendvps:
2901 case Intrinsic::x86_sse41_blendvpd:
2902 case Intrinsic::x86_avx_blendv_ps_256:
2903 case Intrinsic::x86_avx_blendv_pd_256:
2904 case Intrinsic::x86_avx2_pblendvb: {
2910 Value *Op0 = II->getArgOperand(0);
2911 Value *Op1 = II->getArgOperand(1);
2916 return replaceInstUsesWith(CI, Op0);
2919 if (isa<ConstantAggregateZero>(Mask))
2920 return replaceInstUsesWith(CI, Op0);
2923 if (
auto *ConstantMask = dyn_cast<ConstantDataVector>(Mask)) {
2930 case Intrinsic::x86_ssse3_pshuf_b_128:
2931 case Intrinsic::x86_avx2_pshuf_b:
2932 case Intrinsic::x86_avx512_pshuf_b_512:
2934 return replaceInstUsesWith(*II, V);
2937 case Intrinsic::x86_avx_vpermilvar_ps:
2938 case Intrinsic::x86_avx_vpermilvar_ps_256:
2939 case Intrinsic::x86_avx512_vpermilvar_ps_512:
2940 case Intrinsic::x86_avx_vpermilvar_pd:
2941 case Intrinsic::x86_avx_vpermilvar_pd_256:
2942 case Intrinsic::x86_avx512_vpermilvar_pd_512:
2944 return replaceInstUsesWith(*II, V);
2947 case Intrinsic::x86_avx2_permd:
2948 case Intrinsic::x86_avx2_permps:
2950 return replaceInstUsesWith(*II, V);
2953 case Intrinsic::x86_avx512_mask_permvar_df_256:
2954 case Intrinsic::x86_avx512_mask_permvar_df_512:
2955 case Intrinsic::x86_avx512_mask_permvar_di_256:
2956 case Intrinsic::x86_avx512_mask_permvar_di_512:
2957 case Intrinsic::x86_avx512_mask_permvar_hi_128:
2958 case Intrinsic::x86_avx512_mask_permvar_hi_256:
2959 case Intrinsic::x86_avx512_mask_permvar_hi_512:
2960 case Intrinsic::x86_avx512_mask_permvar_qi_128:
2961 case Intrinsic::x86_avx512_mask_permvar_qi_256:
2962 case Intrinsic::x86_avx512_mask_permvar_qi_512:
2963 case Intrinsic::x86_avx512_mask_permvar_sf_256:
2964 case Intrinsic::x86_avx512_mask_permvar_sf_512:
2965 case Intrinsic::x86_avx512_mask_permvar_si_256:
2966 case Intrinsic::x86_avx512_mask_permvar_si_512:
2971 return replaceInstUsesWith(*II, V);
2975 case Intrinsic::x86_avx_vperm2f128_pd_256:
2976 case Intrinsic::x86_avx_vperm2f128_ps_256:
2977 case Intrinsic::x86_avx_vperm2f128_si_256:
2978 case Intrinsic::x86_avx2_vperm2i128:
2980 return replaceInstUsesWith(*II, V);
2983 case Intrinsic::x86_avx_maskload_ps:
2984 case Intrinsic::x86_avx_maskload_pd:
2985 case Intrinsic::x86_avx_maskload_ps_256:
2986 case Intrinsic::x86_avx_maskload_pd_256:
2987 case Intrinsic::x86_avx2_maskload_d:
2988 case Intrinsic::x86_avx2_maskload_q:
2989 case Intrinsic::x86_avx2_maskload_d_256:
2990 case Intrinsic::x86_avx2_maskload_q_256:
2995 case Intrinsic::x86_sse2_maskmov_dqu:
2996 case Intrinsic::x86_avx_maskstore_ps:
2997 case Intrinsic::x86_avx_maskstore_pd:
2998 case Intrinsic::x86_avx_maskstore_ps_256:
2999 case Intrinsic::x86_avx_maskstore_pd_256:
3000 case Intrinsic::x86_avx2_maskstore_d:
3001 case Intrinsic::x86_avx2_maskstore_q:
3002 case Intrinsic::x86_avx2_maskstore_d_256:
3003 case Intrinsic::x86_avx2_maskstore_q_256:
3008 case Intrinsic::x86_xop_vpcomb:
3009 case Intrinsic::x86_xop_vpcomd:
3010 case Intrinsic::x86_xop_vpcomq:
3011 case Intrinsic::x86_xop_vpcomw:
3013 return replaceInstUsesWith(*II, V);
3016 case Intrinsic::x86_xop_vpcomub:
3017 case Intrinsic::x86_xop_vpcomud:
3018 case Intrinsic::x86_xop_vpcomuq:
3019 case Intrinsic::x86_xop_vpcomuw:
3021 return replaceInstUsesWith(*II, V);
3024 case Intrinsic::ppc_altivec_vperm:
3031 if (
Constant *
Mask = dyn_cast<Constant>(II->getArgOperand(2))) {
3032 assert(
Mask->getType()->getVectorNumElements() == 16 &&
3033 "Bad type for intrinsic!");
3036 bool AllEltsOk =
true;
3037 for (
unsigned i = 0; i != 16; ++i) {
3039 if (!Elt || !(isa<ConstantInt>(Elt) || isa<UndefValue>(Elt))) {
3047 Value *Op0 = Builder.CreateBitCast(II->getArgOperand(0),
3049 Value *Op1 = Builder.CreateBitCast(II->getArgOperand(1),
3054 Value *ExtractedElts[32];
3055 memset(ExtractedElts, 0,
sizeof(ExtractedElts));
3057 for (
unsigned i = 0; i != 16; ++i) {
3058 if (isa<UndefValue>(
Mask->getAggregateElement(i)))
3061 cast<ConstantInt>(
Mask->getAggregateElement(i))->getZExtValue();
3066 if (!ExtractedElts[Idx]) {
3069 ExtractedElts[Idx] =
3070 Builder.CreateExtractElement(Idx < 16 ? Op0ToUse : Op1ToUse,
3071 Builder.getInt32(Idx&15));
3075 Result = Builder.CreateInsertElement(Result, ExtractedElts[Idx],
3076 Builder.getInt32(i));
3083 case Intrinsic::arm_neon_vld1:
3084 case Intrinsic::arm_neon_vld2:
3085 case Intrinsic::arm_neon_vld3:
3086 case Intrinsic::arm_neon_vld4:
3087 case Intrinsic::arm_neon_vld2lane:
3088 case Intrinsic::arm_neon_vld3lane:
3089 case Intrinsic::arm_neon_vld4lane:
3090 case Intrinsic::arm_neon_vst1:
3091 case Intrinsic::arm_neon_vst2:
3092 case Intrinsic::arm_neon_vst3:
3093 case Intrinsic::arm_neon_vst4:
3094 case Intrinsic::arm_neon_vst2lane:
3095 case Intrinsic::arm_neon_vst3lane:
3096 case Intrinsic::arm_neon_vst4lane: {
3099 unsigned AlignArg = II->getNumArgOperands() - 1;
3101 if (IntrAlign && IntrAlign->
getZExtValue() < MemAlign) {
3102 II->setArgOperand(AlignArg,
3110 case Intrinsic::arm_neon_vmulls:
3111 case Intrinsic::arm_neon_vmullu:
3112 case Intrinsic::aarch64_neon_smull:
3113 case Intrinsic::aarch64_neon_umull: {
3114 Value *Arg0 = II->getArgOperand(0);
3115 Value *Arg1 = II->getArgOperand(1);
3118 if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
3123 bool Zext = (II->getIntrinsicID() == Intrinsic::arm_neon_vmullu ||
3124 II->getIntrinsicID() == Intrinsic::aarch64_neon_umull);
3125 VectorType *NewVT = cast<VectorType>(II->getType());
3126 if (
Constant *CV0 = dyn_cast<Constant>(Arg0)) {
3127 if (
Constant *CV1 = dyn_cast<Constant>(Arg1)) {
3139 if (
Constant *CV1 = dyn_cast<Constant>(Arg1))
3141 dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
3148 case Intrinsic::amdgcn_rcp: {
3149 Value *Src = II->getArgOperand(0);
3152 if (isa<UndefValue>(Src))
3153 return replaceInstUsesWith(CI, Src);
3155 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3156 const APFloat &ArgVal =
C->getValueAPF();
3163 return replaceInstUsesWith(CI,
ConstantFP::get(II->getContext(), Val));
3168 case Intrinsic::amdgcn_rsq: {
3169 Value *Src = II->getArgOperand(0);
3172 if (isa<UndefValue>(Src))
3173 return replaceInstUsesWith(CI, Src);
3176 case Intrinsic::amdgcn_frexp_mant:
3177 case Intrinsic::amdgcn_frexp_exp: {
3178 Value *Src = II->getArgOperand(0);
3179 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3184 if (II->getIntrinsicID() == Intrinsic::amdgcn_frexp_mant) {
3196 if (isa<UndefValue>(Src))
3201 case Intrinsic::amdgcn_class: {
3218 Value *Src0 = II->getArgOperand(0);
3219 Value *Src1 = II->getArgOperand(1);
3222 if (isa<UndefValue>(Src0))
3225 if (isa<UndefValue>(Src1))
3233 if ((Mask & FullMask) == FullMask)
3236 if ((Mask & FullMask) == 0)
3241 Value *FCmp = Builder.CreateFCmpUNO(Src0, Src0);
3243 return replaceInstUsesWith(*II, FCmp);
3248 if (isa<UndefValue>(Src0))
3252 if ((Mask & FullMask) !=
Mask) {
3253 CallInst *NewCall = Builder.CreateCall(II->getCalledFunction(),
3258 return replaceInstUsesWith(*II, NewCall);
3280 case Intrinsic::amdgcn_cvt_pkrtz: {
3281 Value *Src0 = II->getArgOperand(0);
3282 Value *Src1 = II->getArgOperand(1);
3283 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3284 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3286 = II->getType()->getScalarType()->getFltSemantics();
3288 APFloat Val0 = C0->getValueAPF();
3289 APFloat Val1 = C1->getValueAPF();
3296 return replaceInstUsesWith(*II, Folded);
3300 if (isa<UndefValue>(Src0) && isa<UndefValue>(Src1))
3305 case Intrinsic::amdgcn_ubfe:
3306 case Intrinsic::amdgcn_sbfe: {
3308 Value *Src = II->getArgOperand(0);
3309 if (isa<UndefValue>(Src))
3310 return replaceInstUsesWith(*II, Src);
3313 Type *Ty = II->getType();
3319 if ((Width & (IntSize - 1)) == 0)
3322 if (Width >= IntSize) {
3325 Width & (IntSize - 1)));
3334 if (Offset >= IntSize) {
3336 Offset & (IntSize - 1)));
3341 bool Signed = II->getIntrinsicID() == Intrinsic::amdgcn_sbfe;
3344 if (!CWidth && COffset && Offset == 0) {
3346 Value *ShiftVal = Builder.CreateSub(KSize, II->getArgOperand(2));
3347 ShiftVal = Builder.CreateZExt(ShiftVal, II->getType());
3349 Value *Shl = Builder.CreateShl(Src, ShiftVal);
3350 Value *RightShift = Signed ? Builder.CreateAShr(Shl, ShiftVal)
3351 : Builder.CreateLShr(Shl, ShiftVal);
3353 return replaceInstUsesWith(*II, RightShift);
3356 if (!CWidth || !COffset)
3361 if (Offset + Width < IntSize) {
3362 Value *Shl = Builder.CreateShl(Src, IntSize - Offset - Width);
3363 Value *RightShift = Signed ? Builder.CreateAShr(Shl, IntSize - Width)
3364 : Builder.CreateLShr(Shl, IntSize - Width);
3366 return replaceInstUsesWith(*II, RightShift);
3369 Value *RightShift = Signed ? Builder.CreateAShr(Src, Offset)
3370 : Builder.CreateLShr(Src, Offset);
3373 return replaceInstUsesWith(*II, RightShift);
3375 case Intrinsic::amdgcn_exp:
3376 case Intrinsic::amdgcn_exp_compr: {
3385 bool IsCompr = II->getIntrinsicID() == Intrinsic::amdgcn_exp_compr;
3386 bool Changed =
false;
3387 for (
int I = 0;
I < (IsCompr ? 2 : 4); ++
I) {
3388 if ((!IsCompr && (EnBits & (1 <<
I)) == 0) ||
3389 (IsCompr && ((EnBits & (0x3 << (2 *
I))) == 0))) {
3390 Value *Src = II->getArgOperand(
I + 2);
3391 if (!isa<UndefValue>(Src)) {
3404 case Intrinsic::amdgcn_fmed3: {
3408 Value *Src0 = II->getArgOperand(0);
3409 Value *Src1 = II->getArgOperand(1);
3410 Value *Src2 = II->getArgOperand(2);
3416 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3421 if (isa<Constant>(Src1) && !isa<Constant>(Src2)) {
3426 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3432 II->setArgOperand(0, Src0);
3433 II->setArgOperand(1, Src1);
3434 II->setArgOperand(2, Src2);
3438 if (
match(Src2,
m_NaN()) || isa<UndefValue>(Src2)) {
3439 CallInst *NewCall = Builder.CreateMinNum(Src0, Src1);
3442 return replaceInstUsesWith(*II, NewCall);
3445 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3446 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3447 if (
const ConstantFP *C2 = dyn_cast<ConstantFP>(Src2)) {
3450 return replaceInstUsesWith(*II,
3458 case Intrinsic::amdgcn_icmp:
3459 case Intrinsic::amdgcn_fcmp: {
3466 bool IsInteger = II->getIntrinsicID() == Intrinsic::amdgcn_icmp;
3473 Value *Src0 = II->getArgOperand(0);
3474 Value *Src1 = II->getArgOperand(1);
3476 if (
auto *CSrc0 = dyn_cast<Constant>(Src0)) {
3477 if (
auto *CSrc1 = dyn_cast<Constant>(Src1)) {
3480 return replaceInstUsesWith(
3490 II->getModule(), Intrinsic::read_register, II->getType());
3494 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3497 NewCall->takeName(II);
3498 return replaceInstUsesWith(*II, NewCall);
3504 II->setArgOperand(0, Src1);
3505 II->setArgOperand(1, Src0);
3507 static_cast<int>(SwapPred)));
3550 Intrinsic::amdgcn_fcmp : Intrinsic::amdgcn_icmp;
3556 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3558 return replaceInstUsesWith(*II, NewCall);
3563 case Intrinsic::stackrestore: {
3566 if (
IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
3567 if (SS->getIntrinsicID() == Intrinsic::stacksave) {
3568 if (&*++SS->getIterator() == II)
3569 return eraseInstFromFunction(CI);
3577 bool CannotRemove =
false;
3578 for (++BI; &*BI != TI; ++BI) {
3579 if (isa<AllocaInst>(BI)) {
3580 CannotRemove =
true;
3583 if (
CallInst *BCI = dyn_cast<CallInst>(BI)) {
3586 if (II->getIntrinsicID() == Intrinsic::stackrestore)
3587 return eraseInstFromFunction(CI);
3591 if (II->mayHaveSideEffects()) {
3592 CannotRemove =
true;
3598 CannotRemove =
true;
3607 if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI)))
3608 return eraseInstFromFunction(CI);
3611 case Intrinsic::lifetime_start:
3614 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress))
3618 Intrinsic::lifetime_end, *
this))
3621 case Intrinsic::assume: {
3622 Value *IIOperand = II->getArgOperand(0);
3624 if (
match(II->getNextNode(),
3625 m_Intrinsic<Intrinsic::assume>(
m_Specific(IIOperand))))
3626 return eraseInstFromFunction(CI);
3631 Value *AssumeIntrinsic = II->getCalledValue(), *
A, *
B;
3633 Builder.CreateCall(AssumeIntrinsic,
A, II->getName());
3634 Builder.CreateCall(AssumeIntrinsic, B, II->
getName());
3635 return eraseInstFromFunction(*II);
3639 Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(
A), II->
getName());
3640 Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(B), II->
getName());
3641 return eraseInstFromFunction(*II);
3654 return eraseInstFromFunction(*II);
3665 return eraseInstFromFunction(*II);
3669 AC.updateAffectedValues(II);
3672 case Intrinsic::experimental_gc_relocate: {
3676 Value *DerivedPtr = cast<GCRelocateInst>(II)->getDerivedPtr();
3680 if (II->use_empty())
3681 return eraseInstFromFunction(*II);
3687 if (isa<UndefValue>(DerivedPtr))
3691 if (
auto *PT = dyn_cast<PointerType>(II->getType())) {
3695 if (isa<ConstantPointerNull>(DerivedPtr))
3711 case Intrinsic::experimental_guard: {
3714 Value *NextCond =
nullptr;
3716 m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(NextCond)))) {
3717 Value *CurrCond = II->getArgOperand(0);
3720 if (CurrCond == NextCond)
3721 return eraseInstFromFunction(*NextInst);
3724 II->setArgOperand(0, Builder.CreateAnd(CurrCond, NextCond));
3725 return eraseInstFromFunction(*NextInst);
3730 return visitCallSite(II);
3736 if (
auto *NFI = dyn_cast<FenceInst>(FI.
getNextNode()))
3738 return eraseInstFromFunction(FI);
3745 return visitCallSite(&II);
3773 Type* DstTy = cast<PointerType>(CI->
getType())->getElementType();
3785 replaceInstUsesWith(*From, With);
3788 if (
Value *With = Simplifier.optimizeCall(CI)) {
3790 return CI->
use_empty() ? CI : replaceInstUsesWith(*CI, With);
3800 if (Underlying != TrampMem &&
3803 if (!isa<AllocaInst>(Underlying))
3815 InitTrampoline = II;
3825 if (!InitTrampoline)
3829 if (InitTrampoline->
getOperand(0) != TrampMem)
3832 return InitTrampoline;
3844 if (II->getIntrinsicID() == Intrinsic::init_trampoline &&
3845 II->getOperand(0) == TrampMem)
3878 bool Changed =
false;
3887 if (V->getType()->isPointerTy() &&
3896 if (!ArgNos.
empty()) {
3908 if (!isa<Function>(Callee) && transformConstExprCastCall(CS))
3911 if (
Function *CalleeF = dyn_cast<Function>(Callee)) {
3914 !CalleeF->isIntrinsic()) {
3915 DEBUG(
dbgs() <<
"Removing convergent attr from instr "
3927 !CalleeF->isDeclaration()) {
3936 if (isa<CallInst>(OldCall))
3937 return eraseInstFromFunction(*OldCall);
3941 cast<InvokeInst>(OldCall)->setCalledFunction(
3947 if (isa<ConstantPointerNull>(Callee) || isa<UndefValue>(Callee)) {
3970 return transformCallThroughTrampoline(CS, II);
3974 if (FTy->isVarArg()) {
4001 if (I)
return eraseInstFromFunction(*I);
4009 bool InstCombiner::transformConstExprCastCall(
CallSite CS) {
4015 if (Callee->hasFnAttribute(
"thunk"))
4030 if (OldRetTy != NewRetTy) {
4036 if (Callee->isDeclaration())
4056 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller))
4058 if (
PHINode *PN = dyn_cast<PHINode>(U))
4059 if (PN->getParent() == II->getNormalDest() ||
4060 PN->getParent() == II->getUnwindDest())
4064 unsigned NumActualArgs = CS.
arg_size();
4075 if (Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) ||
4076 Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal))
4080 for (
unsigned i = 0, e = NumCommonArgs; i != e; ++i, ++AI) {
4082 Type *ActTy = (*AI)->getType();
4108 if (Callee->isDeclaration()) {
4146 ArgAttrs.
reserve(NumActualArgs);
4156 for (
unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
4159 Value *NewArg = *AI;
4160 if ((*AI)->getType() != ParamTy)
4161 NewArg = Builder.CreateBitOrPointerCast(*AI, ParamTy);
4170 for (
unsigned i = NumCommonArgs; i != FT->
getNumParams(); ++i) {
4180 for (
unsigned i = FT->
getNumParams(); i != NumActualArgs; ++i, ++AI) {
4182 Value *NewArg = *AI;
4183 if (PTy != (*AI)->getType()) {
4187 NewArg = Builder.CreateCast(opcode, *AI, PTy);
4203 "missing argument attributes");
4212 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4213 NewCS = Builder.CreateInvoke(Callee, II->getNormalDest(),
4214 II->getUnwindDest(),
Args, OpBundles);
4216 NewCS = Builder.CreateCall(Callee, Args, OpBundles);
4218 ->setTailCallKind(cast<CallInst>(Caller)->getTailCallKind());
4220 NewCS->takeName(Caller);
4228 NewCS->setProfWeight(W);
4240 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4242 InsertNewInstBefore(NC, *I);
4245 InsertNewInstBefore(NC, *Caller);
4247 Worklist.AddUsersToWorkList(*Caller);
4254 replaceInstUsesWith(*Caller, NV);
4256 if (OldRetTy == NV->
getType())
4264 eraseInstFromFunction(*Caller);
4271 InstCombiner::transformCallThroughTrampoline(
CallSite CS,
4280 if (Attrs.hasAttrSomewhere(Attribute::Nest))
4284 "transformCallThroughTrampoline called with incorrect CallSite.");
4290 if (!NestAttrs.isEmpty()) {
4291 unsigned NestArgNo = 0;
4292 Type *NestTy =
nullptr;
4297 E = NestFTy->param_end();
4298 I !=
E; ++NestArgNo, ++
I) {
4310 std::vector<Value*> NewArgs;
4311 std::vector<AttributeSet> NewArgAttrs;
4312 NewArgs.reserve(CS.
arg_size() + 1);
4313 NewArgAttrs.reserve(CS.
arg_size());
4322 if (ArgNo == NestArgNo) {
4325 if (NestVal->
getType() != NestTy)
4326 NestVal = Builder.CreateBitCast(NestVal, NestTy,
"nest");
4327 NewArgs.push_back(NestVal);
4328 NewArgAttrs.push_back(NestAttr);
4335 NewArgs.push_back(*I);
4336 NewArgAttrs.push_back(Attrs.getParamAttributes(ArgNo));
4347 std::vector<Type*> NewTypes;
4348 NewTypes.reserve(FTy->getNumParams()+1);
4355 E = FTy->param_end();
4358 if (ArgNo == NestArgNo)
4360 NewTypes.push_back(NestTy);
4366 NewTypes.push_back(*I);
4383 Attrs.getRetAttributes(), NewArgAttrs);
4389 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4391 II->getNormalDest(), II->getUnwindDest(),
4392 NewArgs, OpBundles);
4393 cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv());
4394 cast<InvokeInst>(NewCaller)->setAttributes(NewPAL);
4397 cast<CallInst>(NewCaller)->setTailCallKind(
4398 cast<CallInst>(Caller)->getTailCallKind());
4399 cast<CallInst>(NewCaller)->setCallingConv(
4400 cast<CallInst>(Caller)->getCallingConv());
4401 cast<CallInst>(NewCaller)->setAttributes(NewPAL);
4412 NestF->
getType() == PTy ? NestF :
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7")))
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
LibCallSimplifier - This class implements a collection of optimizations that replace well formed call...
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Value * getRawSource() const
Return the arguments to the instruction.
void push_back(const T &Elt)
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
A parsed version of the target data layout string in and methods for querying it. ...
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static void ValueIsDeleted(Value *V)
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static IntegerType * getInt1Ty(LLVMContext &C)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
static Value * simplifyX86immShift(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
uint64_t getZExtValue() const
Get zero extended value.
DiagnosticInfoOptimizationBase::Argument NV
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
STATISTIC(NumFunctions,"Total number of functions")
A Module instance is used to store all the information related to an LLVM module. ...
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Instruction * visitCallInst(CallInst &CI)
CallInst simplification.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
An instruction for ordering other memory operations.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
match_zero m_Zero()
Match an arbitrary zero/null constant.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
static MDString * get(LLVMContext &Context, StringRef Str)
Instruction * visitVACopyInst(VACopyInst &I)
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static ConstantAggregateZero * get(Type *Ty)
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Type * getValueType() const
static bool simplifyX86MaskedStore(IntrinsicInst &II, InstCombiner &IC)
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
This class represents a function call, abstracting a target machine's calling convention.
bool isConvergent() const
Determine if the call is convergent.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this load instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
static uint64_t round(uint64_t Acc, uint64_t Input)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
const DataLayout & getDataLayout() const
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
static Instruction * foldCttzCtlz(IntrinsicInst &II, InstCombiner &IC)
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
This class wraps the llvm.memset intrinsic.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic, I, at the point in the control-flow identified by the context instruction, CxtI.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
static OverflowCheckFlavor IntrinsicIDToOverflowCheckFlavor(unsigned ID)
Returns the OverflowCheckFlavor corresponding to a overflow_with_op intrinsic.
fneg_match< LHS > m_FNeg(const LHS &L)
Match a floating point negate.
Type * getElementType() const
void reserve(size_type N)
bool isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
static Instruction * simplifyMaskedStore(IntrinsicInst &II, InstCombiner &IC)
Instruction * visitVAStartInst(VAStartInst &I)
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
bool isGCRelocate(ImmutableCallSite CS)
Type * getPointerElementType() const
unsigned arg_size() const
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op...
iterator begin()
Instruction iterator methods.
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isNegative() const
Determine sign of this APInt.
opStatus divide(const APFloat &RHS, roundingMode RM)
static Instruction * SimplifyNVVMIntrinsic(IntrinsicInst *II, InstCombiner &IC)
bool match(Val *V, const Pattern &P)
Value * getRawDest() const
Instruction * visitInvokeInst(InvokeInst &II)
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static APFloat fmed3AMDGCN(const APFloat &Src0, const APFloat &Src1, const APFloat &Src2)
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
bool doesNotThrow() const
Determine if the function cannot unwind.
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
OverflowCheckFlavor
Specific patterns of overflow check idioms that we match.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
This class wraps the llvm.memmove intrinsic.
Value * SimplifyCall(ImmutableCallSite CS, Value *V, User::op_iterator ArgBegin, User::op_iterator ArgEnd, const SimplifyQuery &Q)
Given a function and iterators over arguments, fold the result or return null.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
unsigned getNumArgOperands() const
Return the number of call arguments.
Instruction * eraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The core instruction combiner logic.
static bool isSafeToEliminateVarargsCast(const CallSite CS, const DataLayout &DL, const CastInst *const CI, const int ix)
If this cast does not affect the value passed through the varargs area, we can eliminate the use of t...
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
void setName(const Twine &Name)
Change the name of the value.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
uint32_t getElementSizeInBytes() const
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
This file implements a class to represent arbitrary precision integral constant values and operations...
not_match< LHS > m_Not(const LHS &L)
LLVM_NODISCARD bool empty() const
bool doesNotThrow() const
Determine if the call cannot unwind.
All zero aggregate value.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static Value * simplifyX86vpermv(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert vpermd/vpermps to shufflevector if the mask is constant.
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
APInt shl(unsigned shiftAmt) const
Left-shift function.
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
This represents the llvm.va_start intrinsic.
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
Matches FPExt.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
bool isLittleEndian() const
Layout endianness...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static Value * simplifyX86pack(IntrinsicInst &II, bool IsSigned)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
static void ValueIsRAUWd(Value *Old, Value *New)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
static Value * simplifyX86vpcom(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder, bool IsSigned)
Decode XOP integer vector comparison intrinsics.
void takeName(Value *V)
Transfer the name from V to this value.
static Value * simplifyX86movmsk(const IntrinsicInst &II)
This class represents a truncation of integer types.
static unsigned getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Class to represent pointers.
static Value * simplifyX86vperm2(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
The shuffle mask for a perm2*128 selects any two halves of two 256-bit source vectors, unless a zero bit is set.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
OneUse_match< T > m_OneUse(const T &SubPattern)
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
Type * getParamType(unsigned i) const
Parameter type accessors.
Instruction * visitFenceInst(FenceInst &FI)
initializer< Ty > init(const Ty &Val)
bool isLosslessCast() const
A lossless cast is one that does not alter the basic value.
bool isAllOnes() const
Returns true if value is all one bits.
iterator_range< IterTy > args() const
static Instruction * simplifyMaskedScatter(IntrinsicInst &II, InstCombiner &IC)
Subclasses of this class are all able to terminate a basic block.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
APInt trunc(unsigned width) const
Truncate to new width.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
ConstantInt * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to .objectsize into an integer value of the given Type.
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
This is an important class for using LLVM in a threaded context.
ConstantInt * getTrue()
Get the constant value for i1 true.
bool isVectorTy() const
True if this is an instance of VectorType.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
This is an important base class in LLVM.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
ConstantFP - Floating Point Values [float, double].
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
std::underlying_type< E >::type Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
static IntrinsicInst * findInitTrampolineFromBB(IntrinsicInst *AdjustTramp, Value *TrampMem)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const unsigned End
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
bool isGCResult(ImmutableCallSite CS)
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
AttributeList getAttributes() const
Get the parameter attributes of the call.
self_iterator getIterator()
unsigned getIntegerBitWidth() const
Class to represent integer types.
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
void setAlignment(unsigned Align)
DominatorTree & getDominatorTree() const
static Value * simplifyX86varShift(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
static Value * simplifyX86muldq(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
static Value * simplifyX86extrq(IntrinsicInst &II, Value *Op0, ConstantInt *CILength, ConstantInt *CIIndex, InstCombiner::BuilderTy &Builder)
Attempt to simplify SSE4A EXTRQ/EXTRQI instructions using constant folding or conversion to a shuffle...
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
static Type * getHalfTy(LLVMContext &C)
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
This is the common base class for memset/memcpy/memmove.
Iterator for intrusive lists based on ilist_node.
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
This is the shared class of boolean and integer constants.
InstrTy * getInstruction() const
static Value * simplifyX86vpermilvar(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert vpermilvar* to shufflevector if the mask is constant.
bool isEmpty() const
Return true if there are no attributes.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions that feed it, giving the original input.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static IntrinsicInst * findInitTrampolineFromAlloca(Value *TrampMem)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Type::subtype_iterator param_iterator
static Instruction * simplifyMaskedGather(IntrinsicInst &II, InstCombiner &IC)
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask)
Create a call to Masked Store intrinsic.
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
CallInst * CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
AttributeSet getFnAttributes() const
The function attributes are returned.
static ConstantInt * getTrue(LLVMContext &Context)
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This class represents atomic memcpy intrinsic TODO: Integrate this class into MemIntrinsic hierarchy;...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Class to represent vector types.
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Class for arbitrary precision integers.
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
iterator_range< user_iterator > users()
unsigned countMinPopulation() const
Returns the number of bits known to be one.
unsigned getVectorNumElements() const
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static Value * simplifyX86pshufb(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert pshufb* to shufflevector if the mask is constant.
static cl::opt< bool > FtzEnabled("nvptx-f32ftz", cl::ZeroOrMore, cl::Hidden, cl::desc("NVPTX Specific: Flush f32 subnormals to sign-preserving zero."), cl::init(false))
bool isFPPredicate() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
bool isStructTy() const
True if this is an instance of StructType.
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
void setOrdering(AtomicOrdering Ordering)
Sets the ordering constraint of this store instruction.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
opStatus
IEEE-754R 7: Default exception handling.
static Value * simplifyMinnumMaxnum(const IntrinsicInst &II)
PointerType * getType() const
Global values are always pointers.
void setCalledFunction(Value *Fn)
Set the function called.
This class wraps the llvm.memcpy/memmove intrinsics.
static Value * simplifyMaskedLoad(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
static Instruction * simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC)
static bool maskIsAllOneOrUndef(Value *Mask)
static IntegerType * getInt32Ty(LLVMContext &C)
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
unsigned greater or equal
match_one m_One()
Match an integer 1 or a vector with all elements equal to 1.
AssumptionCache & getAssumptionCache() const
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
void setArgOperand(unsigned i, Value *v)
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
unsigned getNumElements() const
Return the number of elements in the array or vector.
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static bool removeTriviallyEmptyRange(IntrinsicInst &I, unsigned StartID, unsigned EndID, InstCombiner &IC)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isKnownNonNullAt(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this pointer couldn't possibly be null.
static IntrinsicInst * findInitTrampoline(Value *Callee)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
static PointerType * getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS=0)
const APFloat & getValueAPF() const
static Value * simplifyX86insertq(IntrinsicInst &II, Value *Op0, Value *Op1, APInt APLength, APInt APIndex, InstCombiner::BuilderTy &Builder)
Attempt to simplify SSE4A INSERTQ/INSERTQI instructions using constant folding or conversion to a shu...
bool isStatepoint(ImmutableCallSite CS)
static Constant * getNegativeIsTrueBoolVec(ConstantDataVector *V)
Return a constant boolean vector that has true elements in all positions where the input constant dat...
Type * getElementType() const
Return the element type of the array/vector.
iterator_range< op_iterator > arg_operands()
Iteration adapter for range-for loops.
StringRef getValueAsString() const
Return the attribute's value as a string.
static Value * emitX86MaskSelect(Value *Mask, Value *Op0, Value *Op1, InstCombiner::BuilderTy &Builder)
This represents the llvm.va_copy intrinsic.
Type * getReturnType() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
match_all_ones m_AllOnes()
Match an integer or vector with all bits set to true.
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
static Instruction * foldCtpop(IntrinsicInst &II, InstCombiner &IC)
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
void setAlignment(unsigned Align)
Value * getLength() const
This file provides internal interfaces used to implement the InstCombine.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
cmpResult compare(const APFloat &RHS) const
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
bool isNullValue() const
Determine if all bits are clear.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static APInt getNullValue(unsigned numBits)
Get the '0' value.
match_nan m_NaN()
Match an arbitrary NaN constant. This includes quiet and signalling nans.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static cl::opt< unsigned > UnfoldElementAtomicMemcpyMaxElements("unfold-element-atomic-memcpy-max-elements", cl::init(16), cl::desc("Maximum number of elements in atomic memcpy the optimizer is ""allowed to unfold"))
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Value * simplifyX86insertps(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
This class represents an extension of floating point types.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static IntegerType * getInt8Ty(LLVMContext &C)
void setCalledFunction(Value *V)
Set the callee to the specified value.
const fltSemantics & getSemantics() const
static Type * getPromotedType(Type *Ty)
Return the specified type promoted as it would be to pass though a va_arg area.
const BasicBlock * getParent() const
bool doesNotThrow() const
Determine if the call cannot unwind.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
A wrapper class for inspecting calls to intrinsic functions.
bool isVoidTy() const
Return true if this is 'void'.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)