72 #define DEBUG_TYPE "instcombine" 74 STATISTIC(NumSimplified,
"Number of library calls simplified");
77 "instcombine-guard-widening-window",
79 cl::desc(
"How wide an instruction window to bypass looking for " 86 if (ITy->getBitWidth() < 32)
99 assert((isa<ConstantInt>(Elt) || isa<ConstantFP>(Elt)) &&
100 "Unexpected constant data vector element type");
102 ? cast<ConstantInt>(Elt)->isNegative()
103 : cast<ConstantFP>(Elt)->isNegative();
111 unsigned CopyDstAlign = MI->getDestAlignment();
112 if (CopyDstAlign < DstAlign){
113 MI->setDestAlignment(DstAlign);
118 unsigned CopySrcAlign = MI->getSourceAlignment();
119 if (CopySrcAlign < SrcAlign) {
120 MI->setSourceAlignment(SrcAlign);
127 if (!MemOpLength)
return nullptr;
134 assert(Size &&
"0-sized memory transferring should be removed already.");
136 if (Size > 8 || (Size&(Size-1)))
141 cast<PointerType>(MI->getArgOperand(1)->getType())->getAddressSpace();
143 cast<PointerType>(MI->getArgOperand(0)->getType())->getAddressSpace();
155 if (M->getNumOperands() == 3 && M->getOperand(0) &&
156 mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
157 mdconst::extract<ConstantInt>(M->getOperand(0))->
isZero() &&
159 mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
160 mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
162 M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
163 CopyMD = cast<MDNode>(M->getOperand(2));
166 Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
167 Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
168 LoadInst *L = Builder.CreateLoad(Src);
173 MDNode *LoopMemParallelMD =
175 if (LoopMemParallelMD)
178 StoreInst *S = Builder.CreateStore(L, Dest);
183 if (LoopMemParallelMD)
186 if (
auto *MT = dyn_cast<MemTransferInst>(MI)) {
191 if (isa<AtomicMemTransferInst>(MI)) {
204 if (MI->getDestAlignment() < Alignment) {
205 MI->setDestAlignment(Alignment);
215 Alignment = MI->getDestAlignment();
216 assert(Len &&
"0-sized memory setting should be removed already.");
222 Value *Dest = MI->getDest();
223 unsigned DstAddrSp = cast<PointerType>(Dest->getType())->getAddressSpace();
225 Dest = Builder.CreateBitCast(Dest, NewDstPtrTy);
228 if (Alignment == 0) Alignment = 1;
231 uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL;
235 if (isa<AtomicMemSetInst>(MI))
248 bool LogicalShift =
false;
249 bool ShiftLeft =
false;
253 case Intrinsic::x86_sse2_psra_d:
254 case Intrinsic::x86_sse2_psra_w:
255 case Intrinsic::x86_sse2_psrai_d:
256 case Intrinsic::x86_sse2_psrai_w:
257 case Intrinsic::x86_avx2_psra_d:
258 case Intrinsic::x86_avx2_psra_w:
259 case Intrinsic::x86_avx2_psrai_d:
260 case Intrinsic::x86_avx2_psrai_w:
261 case Intrinsic::x86_avx512_psra_q_128:
262 case Intrinsic::x86_avx512_psrai_q_128:
263 case Intrinsic::x86_avx512_psra_q_256:
264 case Intrinsic::x86_avx512_psrai_q_256:
265 case Intrinsic::x86_avx512_psra_d_512:
266 case Intrinsic::x86_avx512_psra_q_512:
267 case Intrinsic::x86_avx512_psra_w_512:
268 case Intrinsic::x86_avx512_psrai_d_512:
269 case Intrinsic::x86_avx512_psrai_q_512:
270 case Intrinsic::x86_avx512_psrai_w_512:
271 LogicalShift =
false; ShiftLeft =
false;
273 case Intrinsic::x86_sse2_psrl_d:
274 case Intrinsic::x86_sse2_psrl_q:
275 case Intrinsic::x86_sse2_psrl_w:
276 case Intrinsic::x86_sse2_psrli_d:
277 case Intrinsic::x86_sse2_psrli_q:
278 case Intrinsic::x86_sse2_psrli_w:
279 case Intrinsic::x86_avx2_psrl_d:
280 case Intrinsic::x86_avx2_psrl_q:
281 case Intrinsic::x86_avx2_psrl_w:
282 case Intrinsic::x86_avx2_psrli_d:
283 case Intrinsic::x86_avx2_psrli_q:
284 case Intrinsic::x86_avx2_psrli_w:
285 case Intrinsic::x86_avx512_psrl_d_512:
286 case Intrinsic::x86_avx512_psrl_q_512:
287 case Intrinsic::x86_avx512_psrl_w_512:
288 case Intrinsic::x86_avx512_psrli_d_512:
289 case Intrinsic::x86_avx512_psrli_q_512:
290 case Intrinsic::x86_avx512_psrli_w_512:
291 LogicalShift =
true; ShiftLeft =
false;
293 case Intrinsic::x86_sse2_psll_d:
294 case Intrinsic::x86_sse2_psll_q:
295 case Intrinsic::x86_sse2_psll_w:
296 case Intrinsic::x86_sse2_pslli_d:
297 case Intrinsic::x86_sse2_pslli_q:
298 case Intrinsic::x86_sse2_pslli_w:
299 case Intrinsic::x86_avx2_psll_d:
300 case Intrinsic::x86_avx2_psll_q:
301 case Intrinsic::x86_avx2_psll_w:
302 case Intrinsic::x86_avx2_pslli_d:
303 case Intrinsic::x86_avx2_pslli_q:
304 case Intrinsic::x86_avx2_pslli_w:
305 case Intrinsic::x86_avx512_psll_d_512:
306 case Intrinsic::x86_avx512_psll_q_512:
307 case Intrinsic::x86_avx512_psll_w_512:
308 case Intrinsic::x86_avx512_pslli_d_512:
309 case Intrinsic::x86_avx512_pslli_q_512:
310 case Intrinsic::x86_avx512_pslli_w_512:
311 LogicalShift =
true; ShiftLeft =
true;
314 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
321 if (!CAZ && !CDV && !CInt)
328 auto VT = cast<VectorType>(CDV->getType());
329 unsigned BitWidth = VT->getElementType()->getPrimitiveSizeInBits();
330 assert((64 % BitWidth) == 0 &&
"Unexpected packed shift size");
331 unsigned NumSubElts = 64 / BitWidth;
334 for (
unsigned i = 0; i != NumSubElts; ++i) {
335 unsigned SubEltIdx = (NumSubElts - 1) - i;
336 auto SubElt = cast<ConstantInt>(CDV->getElementAsConstant(SubEltIdx));
342 Count = CInt->getValue();
345 auto VT = cast<VectorType>(Vec->getType());
346 auto SVT = VT->getElementType();
347 unsigned VWidth = VT->getNumElements();
348 unsigned BitWidth = SVT->getPrimitiveSizeInBits();
355 if (Count.
uge(BitWidth)) {
361 Count =
APInt(64, BitWidth - 1);
382 bool LogicalShift =
false;
383 bool ShiftLeft =
false;
387 case Intrinsic::x86_avx2_psrav_d:
388 case Intrinsic::x86_avx2_psrav_d_256:
389 case Intrinsic::x86_avx512_psrav_q_128:
390 case Intrinsic::x86_avx512_psrav_q_256:
391 case Intrinsic::x86_avx512_psrav_d_512:
392 case Intrinsic::x86_avx512_psrav_q_512:
393 case Intrinsic::x86_avx512_psrav_w_128:
394 case Intrinsic::x86_avx512_psrav_w_256:
395 case Intrinsic::x86_avx512_psrav_w_512:
396 LogicalShift =
false;
399 case Intrinsic::x86_avx2_psrlv_d:
400 case Intrinsic::x86_avx2_psrlv_d_256:
401 case Intrinsic::x86_avx2_psrlv_q:
402 case Intrinsic::x86_avx2_psrlv_q_256:
403 case Intrinsic::x86_avx512_psrlv_d_512:
404 case Intrinsic::x86_avx512_psrlv_q_512:
405 case Intrinsic::x86_avx512_psrlv_w_128:
406 case Intrinsic::x86_avx512_psrlv_w_256:
407 case Intrinsic::x86_avx512_psrlv_w_512:
411 case Intrinsic::x86_avx2_psllv_d:
412 case Intrinsic::x86_avx2_psllv_d_256:
413 case Intrinsic::x86_avx2_psllv_q:
414 case Intrinsic::x86_avx2_psllv_q_256:
415 case Intrinsic::x86_avx512_psllv_d_512:
416 case Intrinsic::x86_avx512_psllv_q_512:
417 case Intrinsic::x86_avx512_psllv_w_128:
418 case Intrinsic::x86_avx512_psllv_w_256:
419 case Intrinsic::x86_avx512_psllv_w_512:
424 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
432 auto VT = cast<VectorType>(II.
getType());
433 auto SVT = VT->getVectorElementType();
434 int NumElts = VT->getNumElements();
435 int BitWidth = SVT->getIntegerBitWidth();
439 bool AnyOutOfRange =
false;
441 for (
int I = 0;
I < NumElts; ++
I) {
442 auto *CElt = CShift->getAggregateElement(
I);
443 if (CElt && isa<UndefValue>(CElt)) {
448 auto *COp = dyn_cast_or_null<ConstantInt>(CElt);
455 APInt ShiftVal = COp->getValue();
456 if (ShiftVal.
uge(BitWidth)) {
457 AnyOutOfRange = LogicalShift;
458 ShiftAmts.
push_back(LogicalShift ? BitWidth : BitWidth - 1);
467 auto OutOfRange = [&](
int Idx) {
return (Idx < 0) || (BitWidth <= Idx); };
470 for (
int Idx : ShiftAmts) {
474 assert(LogicalShift &&
"Logical shift expected");
487 for (
int Idx : ShiftAmts) {
510 if (isa<UndefValue>(Arg0) && isa<UndefValue>(Arg1))
517 assert(NumDstElts == (2 * NumSrcElts) &&
"Unexpected packing types");
519 unsigned NumDstEltsPerLane = NumDstElts / NumLanes;
520 unsigned NumSrcEltsPerLane = NumSrcElts / NumLanes;
523 "Unexpected packing types");
532 for (
unsigned Lane = 0; Lane != NumLanes; ++Lane) {
533 for (
unsigned Elt = 0; Elt != NumDstEltsPerLane; ++Elt) {
534 unsigned SrcIdx = Lane * NumSrcEltsPerLane + Elt % NumSrcEltsPerLane;
535 auto *Cst = (Elt >= NumSrcEltsPerLane) ? Cst1 : Cst0;
536 auto *COp = Cst->getAggregateElement(SrcIdx);
537 if (COp && isa<UndefValue>(COp)) {
542 auto *CInt = dyn_cast_or_null<ConstantInt>(COp);
546 APInt Val = CInt->getValue();
548 "Unexpected constant bitwidth");
555 Val = Val.
trunc(DstScalarSizeInBits);
564 if (Val.
isIntN(DstScalarSizeInBits))
565 Val = Val.
trunc(DstScalarSizeInBits);
585 if (IntrinsicID == Intrinsic::x86_sse41_round_ss ||
586 IntrinsicID == Intrinsic::x86_sse41_round_sd)
588 else if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ss ||
589 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_sd)
599 if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ps_512 ||
600 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_pd_512)
602 else if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ss ||
603 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_sd)
610 SAE = Arg->getZExtValue();
613 if (SAE != 4 || (RoundControl != 2 && RoundControl != 1 ))
617 bool IsScalar =
false;
618 if (IntrinsicID == Intrinsic::x86_sse41_round_ss ||
619 IntrinsicID == Intrinsic::x86_sse41_round_sd ||
620 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ss ||
621 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_sd) {
623 if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ss ||
624 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_sd) {
635 if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ps_128 ||
636 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ps_256 ||
637 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ps_512 ||
638 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_pd_128 ||
639 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_pd_256 ||
640 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_pd_512) {
650 Intrinsic::ID ID = (RoundControl == 2) ? Intrinsic::ceil : Intrinsic::floor;
653 if (
auto *
C = dyn_cast<Constant>(Mask))
654 if (
C->isAllOnesValue())
660 if (MaskTy->getVectorNumElements() > Width) {
662 for (
unsigned i = 0; i != Width; ++i)
669 if (IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_ss ||
670 IntrinsicID == Intrinsic::x86_avx512_mask_rndscale_sd) {
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)) {
1101 if (
auto *CInt = dyn_cast<ConstantInt>(II.
getArgOperand(2))) {
1102 uint64_t Imm = CInt->getZExtValue() & 0x7;
1147 if (C1 && C1->isNaN())
1154 if (isa<UndefValue>(Arg0))
1158 if (isa<UndefValue>(Arg1))
1167 if (Arg0 == X || Arg0 == Y)
1174 if (Arg1 == X || Arg1 == Y)
1180 if (C1 && C1->isInfinity()) {
1182 if (C1->isNegative())
1190 if (Arg0 == X || Arg0 == Y)
1197 if (Arg1 == X || Arg1 == Y)
1203 if (C1 && C1->isInfinity()) {
1205 if (!C1->isNegative())
1216 if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
1218 for (
unsigned I = 0,
E = ConstMask->getType()->getVectorNumElements();
I !=
E;
1220 if (
auto *MaskElt = ConstMask->getAggregateElement(
I))
1221 if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
1234 unsigned Alignment = cast<ConstantInt>(II.
getArgOperand(1))->getZExtValue();
1247 if (ConstMask->isNullValue())
1251 if (ConstMask->isAllOnesValue()) {
1253 unsigned Alignment = cast<ConstantInt>(II.
getArgOperand(2))->getZExtValue();
1263 if (ConstMask && ConstMask->isNullValue())
1282 if (StrippedArg == StrippedInvariantGroupsArg)
1289 else if (II.
getIntrinsicID() == Intrinsic::strip_invariant_group)
1293 "simplifyInvariantGroupIntrinsic only handles launder and strip");
1300 return cast<Instruction>(Result);
1306 if (ConstMask && ConstMask->isNullValue())
1315 "Expected cttz or ctlz intrinsic");
1331 if (PossibleZeros == DefiniteZeros) {
1365 "Expected ctpop intrinsic");
1372 unsigned BitWidth =
IT->getBitWidth();
1402 if (isa<ConstantAggregateZero>(Mask))
1414 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1438 if (isa<ConstantAggregateZero>(Mask)) {
1457 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1483 return maxnum(Src1, Src2);
1488 return maxnum(Src0, Src2);
1490 return maxnum(Src0, Src1);
1504 auto *VecTy = cast<VectorType>(II.
getType());
1505 unsigned NumElts = VecTy->getNumElements();
1508 if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8)
1513 for (
unsigned I = 0;
I < NumElts; ++
I) {
1516 if (!COp || !isa<ConstantInt>(COp))
1519 Indexes[
I] = cast<ConstantInt>(COp)->getLimitedValue();
1522 if (Indexes[
I] >= NumElts)
1545 MemAlign : IntrAlign->getLimitedValue();
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 {
1654 case Intrinsic::nvvm_ceil_d:
1655 return {Intrinsic::ceil, FTZ_Any};
1656 case Intrinsic::nvvm_ceil_f:
1657 return {Intrinsic::ceil, FTZ_MustBeOff};
1658 case Intrinsic::nvvm_ceil_ftz_f:
1659 return {Intrinsic::ceil, FTZ_MustBeOn};
1660 case Intrinsic::nvvm_fabs_d:
1661 return {Intrinsic::fabs, FTZ_Any};
1662 case Intrinsic::nvvm_fabs_f:
1663 return {Intrinsic::fabs, FTZ_MustBeOff};
1664 case Intrinsic::nvvm_fabs_ftz_f:
1665 return {Intrinsic::fabs, FTZ_MustBeOn};
1666 case Intrinsic::nvvm_floor_d:
1667 return {Intrinsic::floor, FTZ_Any};
1668 case Intrinsic::nvvm_floor_f:
1669 return {Intrinsic::floor, FTZ_MustBeOff};
1670 case Intrinsic::nvvm_floor_ftz_f:
1671 return {Intrinsic::floor, FTZ_MustBeOn};
1672 case Intrinsic::nvvm_fma_rn_d:
1673 return {Intrinsic::fma, FTZ_Any};
1674 case Intrinsic::nvvm_fma_rn_f:
1675 return {Intrinsic::fma, FTZ_MustBeOff};
1676 case Intrinsic::nvvm_fma_rn_ftz_f:
1677 return {Intrinsic::fma, FTZ_MustBeOn};
1678 case Intrinsic::nvvm_fmax_d:
1680 case Intrinsic::nvvm_fmax_f:
1682 case Intrinsic::nvvm_fmax_ftz_f:
1684 case Intrinsic::nvvm_fmin_d:
1686 case Intrinsic::nvvm_fmin_f:
1688 case Intrinsic::nvvm_fmin_ftz_f:
1690 case Intrinsic::nvvm_round_d:
1692 case Intrinsic::nvvm_round_f:
1694 case Intrinsic::nvvm_round_ftz_f:
1696 case Intrinsic::nvvm_sqrt_rn_d:
1697 return {Intrinsic::sqrt, FTZ_Any};
1698 case Intrinsic::nvvm_sqrt_f:
1703 return {Intrinsic::sqrt, FTZ_Any};
1704 case Intrinsic::nvvm_sqrt_rn_f:
1705 return {Intrinsic::sqrt, FTZ_MustBeOff};
1706 case Intrinsic::nvvm_sqrt_rn_ftz_f:
1707 return {Intrinsic::sqrt, FTZ_MustBeOn};
1708 case Intrinsic::nvvm_trunc_d:
1709 return {Intrinsic::trunc, FTZ_Any};
1710 case Intrinsic::nvvm_trunc_f:
1711 return {Intrinsic::trunc, FTZ_MustBeOff};
1712 case Intrinsic::nvvm_trunc_ftz_f:
1713 return {Intrinsic::trunc, FTZ_MustBeOn};
1720 case Intrinsic::nvvm_d2i_rz:
1721 case Intrinsic::nvvm_f2i_rz:
1722 case Intrinsic::nvvm_d2ll_rz:
1723 case Intrinsic::nvvm_f2ll_rz:
1724 return {Instruction::FPToSI};
1725 case Intrinsic::nvvm_d2ui_rz:
1726 case Intrinsic::nvvm_f2ui_rz:
1727 case Intrinsic::nvvm_d2ull_rz:
1728 case Intrinsic::nvvm_f2ull_rz:
1729 return {Instruction::FPToUI};
1730 case Intrinsic::nvvm_i2d_rz:
1731 case Intrinsic::nvvm_i2f_rz:
1732 case Intrinsic::nvvm_ll2d_rz:
1733 case Intrinsic::nvvm_ll2f_rz:
1734 return {Instruction::SIToFP};
1735 case Intrinsic::nvvm_ui2d_rz:
1736 case Intrinsic::nvvm_ui2f_rz:
1737 case Intrinsic::nvvm_ull2d_rz:
1738 case Intrinsic::nvvm_ull2f_rz:
1739 return {Instruction::UIToFP};
1742 case Intrinsic::nvvm_add_rn_d:
1743 return {Instruction::FAdd, FTZ_Any};
1744 case Intrinsic::nvvm_add_rn_f:
1745 return {Instruction::FAdd, FTZ_MustBeOff};
1746 case Intrinsic::nvvm_add_rn_ftz_f:
1747 return {Instruction::FAdd, FTZ_MustBeOn};
1748 case Intrinsic::nvvm_mul_rn_d:
1749 return {Instruction::FMul, FTZ_Any};
1750 case Intrinsic::nvvm_mul_rn_f:
1751 return {Instruction::FMul, FTZ_MustBeOff};
1752 case Intrinsic::nvvm_mul_rn_ftz_f:
1753 return {Instruction::FMul, FTZ_MustBeOn};
1754 case Intrinsic::nvvm_div_rn_d:
1755 return {Instruction::FDiv, FTZ_Any};
1756 case Intrinsic::nvvm_div_rn_f:
1757 return {Instruction::FDiv, FTZ_MustBeOff};
1758 case Intrinsic::nvvm_div_rn_ftz_f:
1759 return {Instruction::FDiv, FTZ_MustBeOn};
1766 case Intrinsic::nvvm_rcp_rn_d:
1767 return {SPC_Reciprocal, FTZ_Any};
1768 case Intrinsic::nvvm_rcp_rn_f:
1769 return {SPC_Reciprocal, FTZ_MustBeOff};
1770 case Intrinsic::nvvm_rcp_rn_ftz_f:
1771 return {SPC_Reciprocal, FTZ_MustBeOn};
1802 if (Action.FtzRequirement != FTZ_Any) {
1807 if (FtzEnabled != (Action.FtzRequirement == FTZ_MustBeOn))
1822 if (Action.BinaryOp)
1832 if (!Action.Special)
1835 switch (*Action.Special) {
1836 case SPC_Reciprocal:
1842 llvm_unreachable(
"All SpecialCase enumerators should be handled in switch.");
1860 return replaceInstUsesWith(CI, V);
1863 return visitFree(CI);
1873 if (!II)
return visitCallSite(&CI);
1877 if (
auto *MI = dyn_cast<AnyMemIntrinsic>(II)) {
1878 bool Changed =
false;
1882 if (NumBytes->isNullValue())
1883 return eraseInstFromFunction(CI);
1885 if (
ConstantInt *CI = dyn_cast<ConstantInt>(NumBytes))
1886 if (CI->getZExtValue() == 1) {
1894 if (
auto *M = dyn_cast<MemIntrinsic>(MI))
1895 if (M->isVolatile())
1901 if (
auto *MMI = dyn_cast<AnyMemMoveInst>(MI)) {
1902 if (
GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
1903 if (GVSrc->isConstant()) {
1906 isa<AtomicMemMoveInst>(MMI)
1907 ? Intrinsic::memcpy_element_unordered_atomic
1908 : Intrinsic::memcpy;
1919 if (MTI->getSource() == MTI->getDest())
1920 return eraseInstFromFunction(CI);
1925 if (
auto *MTI = dyn_cast<AnyMemTransferInst>(MI)) {
1928 }
else if (
auto *MSI = dyn_cast<AnyMemSetInst>(MI)) {
1933 if (Changed)
return II;
1939 auto SimplifyDemandedVectorEltsLow = [
this](
Value *
Op,
unsigned Width,
1940 unsigned DemandedWidth) {
1941 APInt UndefElts(Width, 0);
1943 return SimplifyDemandedVectorElts(Op, DemandedElts, UndefElts);
1948 case Intrinsic::objectsize:
1951 return replaceInstUsesWith(CI,
N);
1953 case Intrinsic::bswap: {
1962 Value *V = Builder.CreateLShr(X, CV);
1967 case Intrinsic::masked_load:
1969 return replaceInstUsesWith(CI, SimplifiedMaskedOp);
1971 case Intrinsic::masked_store:
1973 case Intrinsic::masked_gather:
1975 case Intrinsic::masked_scatter:
1977 case Intrinsic::launder_invariant_group:
1978 case Intrinsic::strip_invariant_group:
1980 return replaceInstUsesWith(*II, SkippedBarrier);
1982 case Intrinsic::powi:
1987 if (Power->isMinusOne())
1991 if (Power->equalsInt(2))
1997 case Intrinsic::cttz:
1998 case Intrinsic::ctlz:
2003 case Intrinsic::ctpop:
2008 case Intrinsic::uadd_with_overflow:
2009 case Intrinsic::sadd_with_overflow:
2010 case Intrinsic::umul_with_overflow:
2011 case Intrinsic::smul_with_overflow:
2022 case Intrinsic::usub_with_overflow:
2023 case Intrinsic::ssub_with_overflow: {
2028 Value *OperationResult =
nullptr;
2032 return CreateOverflowTuple(II, OperationResult, OverflowResult);
2042 if (isa<ConstantFP>(Arg0) && !isa<ConstantFP>(Arg1)) {
2050 return replaceInstUsesWith(*II, V);
2060 Value *NewCall = Builder.CreateIntrinsic(NewIID, {
X, Y }, II);
2067 case Intrinsic::fmuladd: {
2076 return replaceInstUsesWith(*II, Add);
2081 case Intrinsic::fma: {
2086 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
2110 auto *FAdd = BinaryOperator::CreateFAdd(Src0, II->
getArgOperand(2));
2117 case Intrinsic::fabs: {
2129 case Intrinsic::ceil:
2130 case Intrinsic::floor:
2132 case Intrinsic::nearbyint:
2133 case Intrinsic::rint:
2134 case Intrinsic::trunc: {
2144 case Intrinsic::cos:
2145 case Intrinsic::amdgcn_cos: {
2158 case Intrinsic::ppc_altivec_lvx:
2159 case Intrinsic::ppc_altivec_lvxl:
2163 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2168 case Intrinsic::ppc_vsx_lxvw4x:
2169 case Intrinsic::ppc_vsx_lxvd2x: {
2171 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2175 case Intrinsic::ppc_altivec_stvx:
2176 case Intrinsic::ppc_altivec_stvxl:
2182 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2183 return new StoreInst(II->getArgOperand(0), Ptr);
2186 case Intrinsic::ppc_vsx_stxvw4x:
2187 case Intrinsic::ppc_vsx_stxvd2x: {
2190 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2191 return new StoreInst(II->getArgOperand(0), Ptr,
false, 1);
2193 case Intrinsic::ppc_qpx_qvlfs:
2198 II->getType()->getVectorNumElements());
2199 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2205 case Intrinsic::ppc_qpx_qvlfd:
2209 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2214 case Intrinsic::ppc_qpx_qvstfs:
2219 II->getArgOperand(0)->getType()->getVectorNumElements());
2220 Value *TOp = Builder.CreateFPTrunc(II->getArgOperand(0), VTy);
2222 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2226 case Intrinsic::ppc_qpx_qvstfd:
2232 Value *
Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2233 return new StoreInst(II->getArgOperand(0), Ptr);
2237 case Intrinsic::x86_bmi_bextr_32:
2238 case Intrinsic::x86_bmi_bextr_64:
2239 case Intrinsic::x86_tbm_bextri_u32:
2240 case Intrinsic::x86_tbm_bextri_u64:
2242 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2243 uint64_t Shift =
C->getZExtValue();
2244 uint64_t Length = (Shift >> 8) & 0xff;
2248 if (Length == 0 || Shift >= BitWidth)
2251 if (
auto *InC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2252 uint64_t
Result = InC->getZExtValue() >> Shift;
2253 if (Length > BitWidth)
2255 Result &= maskTrailingOnes<uint64_t>(Length);
2263 case Intrinsic::x86_bmi_bzhi_32:
2264 case Intrinsic::x86_bmi_bzhi_64:
2266 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2267 uint64_t
Index =
C->getZExtValue() & 0xff;
2269 if (Index >= BitWidth)
2274 if (
auto *InC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2275 uint64_t
Result = InC->getZExtValue();
2276 Result &= maskTrailingOnes<uint64_t>(
Index);
2283 case Intrinsic::x86_vcvtph2ps_128:
2284 case Intrinsic::x86_vcvtph2ps_256: {
2285 auto Arg = II->getArgOperand(0);
2286 auto ArgType = cast<VectorType>(
Arg->
getType());
2287 auto RetType = cast<VectorType>(II->getType());
2288 unsigned ArgWidth = ArgType->getNumElements();
2289 unsigned RetWidth = RetType->getNumElements();
2290 assert(RetWidth <= ArgWidth &&
"Unexpected input/return vector widths");
2291 assert(ArgType->isIntOrIntVectorTy() &&
2292 ArgType->getScalarSizeInBits() == 16 &&
2293 "CVTPH2PS input type should be 16-bit integer vector");
2294 assert(RetType->getScalarType()->isFloatTy() &&
2295 "CVTPH2PS output type should be 32-bit float vector");
2298 if (isa<ConstantAggregateZero>(
Arg))
2301 if (isa<ConstantDataVector>(
Arg)) {
2302 auto VectorHalfAsShorts =
Arg;
2303 if (RetWidth < ArgWidth) {
2305 for (
unsigned i = 0; i != RetWidth; ++i)
2307 VectorHalfAsShorts = Builder.CreateShuffleVector(
2311 auto VectorHalfType =
2314 Builder.CreateBitCast(VectorHalfAsShorts, VectorHalfType);
2315 auto VectorFloats = Builder.CreateFPExt(VectorHalfs, RetType);
2316 return replaceInstUsesWith(*II, VectorFloats);
2320 if (
Value *V = SimplifyDemandedVectorEltsLow(
Arg, ArgWidth, RetWidth)) {
2321 II->setArgOperand(0, V);
2327 case Intrinsic::x86_sse_cvtss2si:
2328 case Intrinsic::x86_sse_cvtss2si64:
2329 case Intrinsic::x86_sse_cvttss2si:
2330 case Intrinsic::x86_sse_cvttss2si64:
2331 case Intrinsic::x86_sse2_cvtsd2si:
2332 case Intrinsic::x86_sse2_cvtsd2si64:
2333 case Intrinsic::x86_sse2_cvttsd2si:
2334 case Intrinsic::x86_sse2_cvttsd2si64:
2335 case Intrinsic::x86_avx512_vcvtss2si32:
2336 case Intrinsic::x86_avx512_vcvtss2si64:
2337 case Intrinsic::x86_avx512_vcvtss2usi32:
2338 case Intrinsic::x86_avx512_vcvtss2usi64:
2339 case Intrinsic::x86_avx512_vcvtsd2si32:
2340 case Intrinsic::x86_avx512_vcvtsd2si64:
2341 case Intrinsic::x86_avx512_vcvtsd2usi32:
2342 case Intrinsic::x86_avx512_vcvtsd2usi64:
2343 case Intrinsic::x86_avx512_cvttss2si:
2344 case Intrinsic::x86_avx512_cvttss2si64:
2345 case Intrinsic::x86_avx512_cvttss2usi:
2346 case Intrinsic::x86_avx512_cvttss2usi64:
2347 case Intrinsic::x86_avx512_cvttsd2si:
2348 case Intrinsic::x86_avx512_cvttsd2si64:
2349 case Intrinsic::x86_avx512_cvttsd2usi:
2350 case Intrinsic::x86_avx512_cvttsd2usi64: {
2355 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg, VWidth, 1)) {
2356 II->setArgOperand(0, V);
2362 case Intrinsic::x86_sse41_round_ps:
2363 case Intrinsic::x86_sse41_round_pd:
2364 case Intrinsic::x86_avx_round_ps_256:
2365 case Intrinsic::x86_avx_round_pd_256:
2366 case Intrinsic::x86_avx512_mask_rndscale_ps_128:
2367 case Intrinsic::x86_avx512_mask_rndscale_ps_256:
2368 case Intrinsic::x86_avx512_mask_rndscale_ps_512:
2369 case Intrinsic::x86_avx512_mask_rndscale_pd_128:
2370 case Intrinsic::x86_avx512_mask_rndscale_pd_256:
2371 case Intrinsic::x86_avx512_mask_rndscale_pd_512:
2372 case Intrinsic::x86_avx512_mask_rndscale_ss:
2373 case Intrinsic::x86_avx512_mask_rndscale_sd:
2375 return replaceInstUsesWith(*II, V);
2378 case Intrinsic::x86_mmx_pmovmskb:
2379 case Intrinsic::x86_sse_movmsk_ps:
2380 case Intrinsic::x86_sse2_movmsk_pd:
2381 case Intrinsic::x86_sse2_pmovmskb_128:
2382 case Intrinsic::x86_avx_movmsk_pd_256:
2383 case Intrinsic::x86_avx_movmsk_ps_256:
2384 case Intrinsic::x86_avx2_pmovmskb:
2386 return replaceInstUsesWith(*II, V);
2389 case Intrinsic::x86_sse_comieq_ss:
2390 case Intrinsic::x86_sse_comige_ss:
2391 case Intrinsic::x86_sse_comigt_ss:
2392 case Intrinsic::x86_sse_comile_ss:
2393 case Intrinsic::x86_sse_comilt_ss:
2394 case Intrinsic::x86_sse_comineq_ss:
2395 case Intrinsic::x86_sse_ucomieq_ss:
2396 case Intrinsic::x86_sse_ucomige_ss:
2397 case Intrinsic::x86_sse_ucomigt_ss:
2398 case Intrinsic::x86_sse_ucomile_ss:
2399 case Intrinsic::x86_sse_ucomilt_ss:
2400 case Intrinsic::x86_sse_ucomineq_ss:
2401 case Intrinsic::x86_sse2_comieq_sd:
2402 case Intrinsic::x86_sse2_comige_sd:
2403 case Intrinsic::x86_sse2_comigt_sd:
2404 case Intrinsic::x86_sse2_comile_sd:
2405 case Intrinsic::x86_sse2_comilt_sd:
2406 case Intrinsic::x86_sse2_comineq_sd:
2407 case Intrinsic::x86_sse2_ucomieq_sd:
2408 case Intrinsic::x86_sse2_ucomige_sd:
2409 case Intrinsic::x86_sse2_ucomigt_sd:
2410 case Intrinsic::x86_sse2_ucomile_sd:
2411 case Intrinsic::x86_sse2_ucomilt_sd:
2412 case Intrinsic::x86_sse2_ucomineq_sd:
2413 case Intrinsic::x86_avx512_vcomi_ss:
2414 case Intrinsic::x86_avx512_vcomi_sd:
2415 case Intrinsic::x86_avx512_mask_cmp_ss:
2416 case Intrinsic::x86_avx512_mask_cmp_sd: {
2419 bool MadeChange =
false;
2420 Value *Arg0 = II->getArgOperand(0);
2421 Value *Arg1 = II->getArgOperand(1);
2423 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg0, VWidth, 1)) {
2424 II->setArgOperand(0, V);
2427 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, 1)) {
2428 II->setArgOperand(1, V);
2435 case Intrinsic::x86_avx512_cmp_pd_128:
2436 case Intrinsic::x86_avx512_cmp_pd_256:
2437 case Intrinsic::x86_avx512_cmp_pd_512:
2438 case Intrinsic::x86_avx512_cmp_ps_128:
2439 case Intrinsic::x86_avx512_cmp_ps_256:
2440 case Intrinsic::x86_avx512_cmp_ps_512: {
2442 Value *Arg0 = II->getArgOperand(0);
2443 Value *Arg1 = II->getArgOperand(1);
2457 cast<Instruction>(Arg0)->getFastMathFlags().noInfs())) {
2460 II->setArgOperand(0, A);
2461 II->setArgOperand(1, B);
2467 case Intrinsic::x86_avx512_add_ps_512:
2468 case Intrinsic::x86_avx512_div_ps_512:
2469 case Intrinsic::x86_avx512_mul_ps_512:
2470 case Intrinsic::x86_avx512_sub_ps_512:
2471 case Intrinsic::x86_avx512_add_pd_512:
2472 case Intrinsic::x86_avx512_div_pd_512:
2473 case Intrinsic::x86_avx512_mul_pd_512:
2474 case Intrinsic::x86_avx512_sub_pd_512:
2477 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
2478 if (R->getValue() == 4) {
2479 Value *Arg0 = II->getArgOperand(0);
2480 Value *Arg1 = II->getArgOperand(1);
2483 switch (II->getIntrinsicID()) {
2485 case Intrinsic::x86_avx512_add_ps_512:
2486 case Intrinsic::x86_avx512_add_pd_512:
2487 V = Builder.CreateFAdd(Arg0, Arg1);
2489 case Intrinsic::x86_avx512_sub_ps_512:
2490 case Intrinsic::x86_avx512_sub_pd_512:
2491 V = Builder.CreateFSub(Arg0, Arg1);
2493 case Intrinsic::x86_avx512_mul_ps_512:
2494 case Intrinsic::x86_avx512_mul_pd_512:
2495 V = Builder.CreateFMul(Arg0, Arg1);
2497 case Intrinsic::x86_avx512_div_ps_512:
2498 case Intrinsic::x86_avx512_div_pd_512:
2499 V = Builder.CreateFDiv(Arg0, Arg1);
2503 return replaceInstUsesWith(*II, V);
2508 case Intrinsic::x86_avx512_mask_add_ss_round:
2509 case Intrinsic::x86_avx512_mask_div_ss_round:
2510 case Intrinsic::x86_avx512_mask_mul_ss_round:
2511 case Intrinsic::x86_avx512_mask_sub_ss_round:
2512 case Intrinsic::x86_avx512_mask_add_sd_round:
2513 case Intrinsic::x86_avx512_mask_div_sd_round:
2514 case Intrinsic::x86_avx512_mask_mul_sd_round:
2515 case Intrinsic::x86_avx512_mask_sub_sd_round:
2518 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(4))) {
2519 if (R->getValue() == 4) {
2521 Value *Arg0 = II->getArgOperand(0);
2522 Value *Arg1 = II->getArgOperand(1);
2523 Value *LHS = Builder.CreateExtractElement(Arg0, (uint64_t)0);
2524 Value *RHS = Builder.CreateExtractElement(Arg1, (uint64_t)0);
2527 switch (II->getIntrinsicID()) {
2529 case Intrinsic::x86_avx512_mask_add_ss_round:
2530 case Intrinsic::x86_avx512_mask_add_sd_round:
2531 V = Builder.CreateFAdd(LHS, RHS);
2533 case Intrinsic::x86_avx512_mask_sub_ss_round:
2534 case Intrinsic::x86_avx512_mask_sub_sd_round:
2535 V = Builder.CreateFSub(LHS, RHS);
2537 case Intrinsic::x86_avx512_mask_mul_ss_round:
2538 case Intrinsic::x86_avx512_mask_mul_sd_round:
2539 V = Builder.CreateFMul(LHS, RHS);
2541 case Intrinsic::x86_avx512_mask_div_ss_round:
2542 case Intrinsic::x86_avx512_mask_div_sd_round:
2543 V = Builder.CreateFDiv(LHS, RHS);
2551 if (!
C || !
C->getValue()[0]) {
2555 Mask = Builder.CreateBitCast(Mask, MaskTy);
2556 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
2558 Value *Passthru = Builder.CreateExtractElement(II->getArgOperand(2),
2560 V = Builder.CreateSelect(Mask, V, Passthru);
2564 V = Builder.CreateInsertElement(Arg0, V, (uint64_t)0);
2566 return replaceInstUsesWith(*II, V);
2572 case Intrinsic::x86_avx512_mask_max_ss_round:
2573 case Intrinsic::x86_avx512_mask_min_ss_round:
2574 case Intrinsic::x86_avx512_mask_max_sd_round:
2575 case Intrinsic::x86_avx512_mask_min_sd_round:
2576 case Intrinsic::x86_sse_cmp_ss:
2577 case Intrinsic::x86_sse_min_ss:
2578 case Intrinsic::x86_sse_max_ss:
2579 case Intrinsic::x86_sse2_cmp_sd:
2580 case Intrinsic::x86_sse2_min_sd:
2581 case Intrinsic::x86_sse2_max_sd:
2582 case Intrinsic::x86_xop_vfrcz_ss:
2583 case Intrinsic::x86_xop_vfrcz_sd: {
2584 unsigned VWidth = II->getType()->getVectorNumElements();
2585 APInt UndefElts(VWidth, 0);
2587 if (
Value *V = SimplifyDemandedVectorElts(II, AllOnesEltMask, UndefElts)) {
2589 return replaceInstUsesWith(*II, V);
2594 case Intrinsic::x86_sse41_round_ss:
2595 case Intrinsic::x86_sse41_round_sd: {
2596 unsigned VWidth = II->getType()->getVectorNumElements();
2597 APInt UndefElts(VWidth, 0);
2599 if (
Value *V = SimplifyDemandedVectorElts(II, AllOnesEltMask, UndefElts)) {
2601 return replaceInstUsesWith(*II, V);
2604 return replaceInstUsesWith(*II, V);
2611 case Intrinsic::x86_sse2_psrai_d:
2612 case Intrinsic::x86_sse2_psrai_w:
2613 case Intrinsic::x86_avx2_psrai_d:
2614 case Intrinsic::x86_avx2_psrai_w:
2615 case Intrinsic::x86_avx512_psrai_q_128:
2616 case Intrinsic::x86_avx512_psrai_q_256:
2617 case Intrinsic::x86_avx512_psrai_d_512:
2618 case Intrinsic::x86_avx512_psrai_q_512:
2619 case Intrinsic::x86_avx512_psrai_w_512:
2620 case Intrinsic::x86_sse2_psrli_d:
2621 case Intrinsic::x86_sse2_psrli_q:
2622 case Intrinsic::x86_sse2_psrli_w:
2623 case Intrinsic::x86_avx2_psrli_d:
2624 case Intrinsic::x86_avx2_psrli_q:
2625 case Intrinsic::x86_avx2_psrli_w:
2626 case Intrinsic::x86_avx512_psrli_d_512:
2627 case Intrinsic::x86_avx512_psrli_q_512:
2628 case Intrinsic::x86_avx512_psrli_w_512:
2629 case Intrinsic::x86_sse2_pslli_d:
2630 case Intrinsic::x86_sse2_pslli_q:
2631 case Intrinsic::x86_sse2_pslli_w:
2632 case Intrinsic::x86_avx2_pslli_d:
2633 case Intrinsic::x86_avx2_pslli_q:
2634 case Intrinsic::x86_avx2_pslli_w:
2635 case Intrinsic::x86_avx512_pslli_d_512:
2636 case Intrinsic::x86_avx512_pslli_q_512:
2637 case Intrinsic::x86_avx512_pslli_w_512:
2639 return replaceInstUsesWith(*II, V);
2642 case Intrinsic::x86_sse2_psra_d:
2643 case Intrinsic::x86_sse2_psra_w:
2644 case Intrinsic::x86_avx2_psra_d:
2645 case Intrinsic::x86_avx2_psra_w:
2646 case Intrinsic::x86_avx512_psra_q_128:
2647 case Intrinsic::x86_avx512_psra_q_256:
2648 case Intrinsic::x86_avx512_psra_d_512:
2649 case Intrinsic::x86_avx512_psra_q_512:
2650 case Intrinsic::x86_avx512_psra_w_512:
2651 case Intrinsic::x86_sse2_psrl_d:
2652 case Intrinsic::x86_sse2_psrl_q:
2653 case Intrinsic::x86_sse2_psrl_w:
2654 case Intrinsic::x86_avx2_psrl_d:
2655 case Intrinsic::x86_avx2_psrl_q:
2656 case Intrinsic::x86_avx2_psrl_w:
2657 case Intrinsic::x86_avx512_psrl_d_512:
2658 case Intrinsic::x86_avx512_psrl_q_512:
2659 case Intrinsic::x86_avx512_psrl_w_512:
2660 case Intrinsic::x86_sse2_psll_d:
2661 case Intrinsic::x86_sse2_psll_q:
2662 case Intrinsic::x86_sse2_psll_w:
2663 case Intrinsic::x86_avx2_psll_d:
2664 case Intrinsic::x86_avx2_psll_q:
2665 case Intrinsic::x86_avx2_psll_w:
2666 case Intrinsic::x86_avx512_psll_d_512:
2667 case Intrinsic::x86_avx512_psll_q_512:
2668 case Intrinsic::x86_avx512_psll_w_512: {
2670 return replaceInstUsesWith(*II, V);
2674 Value *Arg1 = II->getArgOperand(1);
2676 "Unexpected packed shift size");
2679 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, VWidth / 2)) {
2680 II->setArgOperand(1, V);
2686 case Intrinsic::x86_avx2_psllv_d:
2687 case Intrinsic::x86_avx2_psllv_d_256:
2688 case Intrinsic::x86_avx2_psllv_q:
2689 case Intrinsic::x86_avx2_psllv_q_256:
2690 case Intrinsic::x86_avx512_psllv_d_512:
2691 case Intrinsic::x86_avx512_psllv_q_512:
2692 case Intrinsic::x86_avx512_psllv_w_128:
2693 case Intrinsic::x86_avx512_psllv_w_256:
2694 case Intrinsic::x86_avx512_psllv_w_512:
2695 case Intrinsic::x86_avx2_psrav_d:
2696 case Intrinsic::x86_avx2_psrav_d_256:
2697 case Intrinsic::x86_avx512_psrav_q_128:
2698 case Intrinsic::x86_avx512_psrav_q_256:
2699 case Intrinsic::x86_avx512_psrav_d_512:
2700 case Intrinsic::x86_avx512_psrav_q_512:
2701 case Intrinsic::x86_avx512_psrav_w_128:
2702 case Intrinsic::x86_avx512_psrav_w_256:
2703 case Intrinsic::x86_avx512_psrav_w_512:
2704 case Intrinsic::x86_avx2_psrlv_d:
2705 case Intrinsic::x86_avx2_psrlv_d_256:
2706 case Intrinsic::x86_avx2_psrlv_q:
2707 case Intrinsic::x86_avx2_psrlv_q_256:
2708 case Intrinsic::x86_avx512_psrlv_d_512:
2709 case Intrinsic::x86_avx512_psrlv_q_512:
2710 case Intrinsic::x86_avx512_psrlv_w_128:
2711 case Intrinsic::x86_avx512_psrlv_w_256:
2712 case Intrinsic::x86_avx512_psrlv_w_512:
2714 return replaceInstUsesWith(*II, V);
2717 case Intrinsic::x86_sse2_packssdw_128:
2718 case Intrinsic::x86_sse2_packsswb_128:
2719 case Intrinsic::x86_avx2_packssdw:
2720 case Intrinsic::x86_avx2_packsswb:
2721 case Intrinsic::x86_avx512_packssdw_512:
2722 case Intrinsic::x86_avx512_packsswb_512:
2724 return replaceInstUsesWith(*II, V);
2727 case Intrinsic::x86_sse2_packuswb_128:
2728 case Intrinsic::x86_sse41_packusdw:
2729 case Intrinsic::x86_avx2_packusdw:
2730 case Intrinsic::x86_avx2_packuswb:
2731 case Intrinsic::x86_avx512_packusdw_512:
2732 case Intrinsic::x86_avx512_packuswb_512:
2734 return replaceInstUsesWith(*II, V);
2737 case Intrinsic::x86_pclmulqdq:
2738 case Intrinsic::x86_pclmulqdq_256:
2739 case Intrinsic::x86_pclmulqdq_512: {
2740 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
2741 unsigned Imm =
C->getZExtValue();
2743 bool MadeChange =
false;
2744 Value *Arg0 = II->getArgOperand(0);
2745 Value *Arg1 = II->getArgOperand(1);
2748 APInt UndefElts1(VWidth, 0);
2750 APInt(2, (Imm & 0x01) ? 2 : 1));
2751 if (
Value *V = SimplifyDemandedVectorElts(Arg0, DemandedElts1,
2753 II->setArgOperand(0, V);
2757 APInt UndefElts2(VWidth, 0);
2759 APInt(2, (Imm & 0x10) ? 2 : 1));
2760 if (
Value *V = SimplifyDemandedVectorElts(Arg1, DemandedElts2,
2762 II->setArgOperand(1, V);
2769 return replaceInstUsesWith(*II,
2778 case Intrinsic::x86_sse41_insertps:
2780 return replaceInstUsesWith(*II, V);
2783 case Intrinsic::x86_sse4a_extrq: {
2784 Value *Op0 = II->getArgOperand(0);
2785 Value *Op1 = II->getArgOperand(1);
2790 VWidth1 == 16 &&
"Unexpected operand sizes");
2795 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)0))
2798 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
2803 return replaceInstUsesWith(*II, V);
2807 bool MadeChange =
false;
2808 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
2809 II->setArgOperand(0, V);
2812 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 2)) {
2813 II->setArgOperand(1, V);
2821 case Intrinsic::x86_sse4a_extrqi: {
2824 Value *Op0 = II->getArgOperand(0);
2827 "Unexpected operand size");
2835 return replaceInstUsesWith(*II, V);
2839 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
2840 II->setArgOperand(0, V);
2846 case Intrinsic::x86_sse4a_insertq: {
2847 Value *Op0 = II->getArgOperand(0);
2848 Value *Op1 = II->getArgOperand(1);
2853 "Unexpected operand size");
2858 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
2863 const APInt &V11 = CI11->getValue();
2867 return replaceInstUsesWith(*II, V);
2872 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
2873 II->setArgOperand(0, V);
2879 case Intrinsic::x86_sse4a_insertqi: {
2883 Value *Op0 = II->getArgOperand(0);
2884 Value *Op1 = II->getArgOperand(1);
2889 VWidth1 == 2 &&
"Unexpected operand sizes");
2896 if (CILength && CIIndex) {
2900 return replaceInstUsesWith(*II, V);
2905 bool MadeChange =
false;
2906 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
2907 II->setArgOperand(0, V);
2910 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 1)) {
2911 II->setArgOperand(1, V);
2919 case Intrinsic::x86_sse41_pblendvb:
2920 case Intrinsic::x86_sse41_blendvps:
2921 case Intrinsic::x86_sse41_blendvpd:
2922 case Intrinsic::x86_avx_blendv_ps_256:
2923 case Intrinsic::x86_avx_blendv_pd_256:
2924 case Intrinsic::x86_avx2_pblendvb: {
2930 Value *Op0 = II->getArgOperand(0);
2931 Value *Op1 = II->getArgOperand(1);
2936 return replaceInstUsesWith(CI, Op0);
2939 if (isa<ConstantAggregateZero>(Mask))
2940 return replaceInstUsesWith(CI, Op0);
2943 if (
auto *ConstantMask = dyn_cast<ConstantDataVector>(Mask)) {
2950 case Intrinsic::x86_ssse3_pshuf_b_128:
2951 case Intrinsic::x86_avx2_pshuf_b:
2952 case Intrinsic::x86_avx512_pshuf_b_512:
2954 return replaceInstUsesWith(*II, V);
2957 case Intrinsic::x86_avx_vpermilvar_ps:
2958 case Intrinsic::x86_avx_vpermilvar_ps_256:
2959 case Intrinsic::x86_avx512_vpermilvar_ps_512:
2960 case Intrinsic::x86_avx_vpermilvar_pd:
2961 case Intrinsic::x86_avx_vpermilvar_pd_256:
2962 case Intrinsic::x86_avx512_vpermilvar_pd_512:
2964 return replaceInstUsesWith(*II, V);
2967 case Intrinsic::x86_avx2_permd:
2968 case Intrinsic::x86_avx2_permps:
2969 case Intrinsic::x86_avx512_permvar_df_256:
2970 case Intrinsic::x86_avx512_permvar_df_512:
2971 case Intrinsic::x86_avx512_permvar_di_256:
2972 case Intrinsic::x86_avx512_permvar_di_512:
2973 case Intrinsic::x86_avx512_permvar_hi_128:
2974 case Intrinsic::x86_avx512_permvar_hi_256:
2975 case Intrinsic::x86_avx512_permvar_hi_512:
2976 case Intrinsic::x86_avx512_permvar_qi_128:
2977 case Intrinsic::x86_avx512_permvar_qi_256:
2978 case Intrinsic::x86_avx512_permvar_qi_512:
2979 case Intrinsic::x86_avx512_permvar_sf_512:
2980 case Intrinsic::x86_avx512_permvar_si_512:
2982 return replaceInstUsesWith(*II, V);
2985 case Intrinsic::x86_avx_maskload_ps:
2986 case Intrinsic::x86_avx_maskload_pd:
2987 case Intrinsic::x86_avx_maskload_ps_256:
2988 case Intrinsic::x86_avx_maskload_pd_256:
2989 case Intrinsic::x86_avx2_maskload_d:
2990 case Intrinsic::x86_avx2_maskload_q:
2991 case Intrinsic::x86_avx2_maskload_d_256:
2992 case Intrinsic::x86_avx2_maskload_q_256:
2997 case Intrinsic::x86_sse2_maskmov_dqu:
2998 case Intrinsic::x86_avx_maskstore_ps:
2999 case Intrinsic::x86_avx_maskstore_pd:
3000 case Intrinsic::x86_avx_maskstore_ps_256:
3001 case Intrinsic::x86_avx_maskstore_pd_256:
3002 case Intrinsic::x86_avx2_maskstore_d:
3003 case Intrinsic::x86_avx2_maskstore_q:
3004 case Intrinsic::x86_avx2_maskstore_d_256:
3005 case Intrinsic::x86_avx2_maskstore_q_256:
3010 case Intrinsic::x86_xop_vpcomb:
3011 case Intrinsic::x86_xop_vpcomd:
3012 case Intrinsic::x86_xop_vpcomq:
3013 case Intrinsic::x86_xop_vpcomw:
3015 return replaceInstUsesWith(*II, V);
3018 case Intrinsic::x86_xop_vpcomub:
3019 case Intrinsic::x86_xop_vpcomud:
3020 case Intrinsic::x86_xop_vpcomuq:
3021 case Intrinsic::x86_xop_vpcomuw:
3023 return replaceInstUsesWith(*II, V);
3026 case Intrinsic::ppc_altivec_vperm:
3033 if (
Constant *
Mask = dyn_cast<Constant>(II->getArgOperand(2))) {
3034 assert(
Mask->getType()->getVectorNumElements() == 16 &&
3035 "Bad type for intrinsic!");
3038 bool AllEltsOk =
true;
3039 for (
unsigned i = 0; i != 16; ++i) {
3041 if (!Elt || !(isa<ConstantInt>(Elt) || isa<UndefValue>(Elt))) {
3049 Value *Op0 = Builder.CreateBitCast(II->getArgOperand(0),
3051 Value *Op1 = Builder.CreateBitCast(II->getArgOperand(1),
3056 Value *ExtractedElts[32];
3057 memset(ExtractedElts, 0,
sizeof(ExtractedElts));
3059 for (
unsigned i = 0; i != 16; ++i) {
3060 if (isa<UndefValue>(
Mask->getAggregateElement(i)))
3063 cast<ConstantInt>(
Mask->getAggregateElement(i))->getZExtValue();
3065 if (DL.isLittleEndian())
3068 if (!ExtractedElts[Idx]) {
3069 Value *Op0ToUse = (DL.isLittleEndian()) ? Op1 : Op0;
3070 Value *Op1ToUse = (DL.isLittleEndian()) ? Op0 : Op1;
3071 ExtractedElts[Idx] =
3072 Builder.CreateExtractElement(Idx < 16 ? Op0ToUse : Op1ToUse,
3073 Builder.getInt32(Idx&15));
3077 Result = Builder.CreateInsertElement(Result, ExtractedElts[Idx],
3078 Builder.getInt32(i));
3085 case Intrinsic::arm_neon_vld1: {
3089 return replaceInstUsesWith(*II, V);
3093 case Intrinsic::arm_neon_vld2:
3094 case Intrinsic::arm_neon_vld3:
3095 case Intrinsic::arm_neon_vld4:
3096 case Intrinsic::arm_neon_vld2lane:
3097 case Intrinsic::arm_neon_vld3lane:
3098 case Intrinsic::arm_neon_vld4lane:
3099 case Intrinsic::arm_neon_vst1:
3100 case Intrinsic::arm_neon_vst2:
3101 case Intrinsic::arm_neon_vst3:
3102 case Intrinsic::arm_neon_vst4:
3103 case Intrinsic::arm_neon_vst2lane:
3104 case Intrinsic::arm_neon_vst3lane:
3105 case Intrinsic::arm_neon_vst4lane: {
3108 unsigned AlignArg = II->getNumArgOperands() - 1;
3110 if (IntrAlign && IntrAlign->
getZExtValue() < MemAlign) {
3111 II->setArgOperand(AlignArg,
3119 case Intrinsic::arm_neon_vtbl1:
3120 case Intrinsic::aarch64_neon_tbl1:
3122 return replaceInstUsesWith(*II, V);
3125 case Intrinsic::arm_neon_vmulls:
3126 case Intrinsic::arm_neon_vmullu:
3127 case Intrinsic::aarch64_neon_smull:
3128 case Intrinsic::aarch64_neon_umull: {
3129 Value *Arg0 = II->getArgOperand(0);
3130 Value *Arg1 = II->getArgOperand(1);
3133 if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
3138 bool Zext = (II->getIntrinsicID() == Intrinsic::arm_neon_vmullu ||
3139 II->getIntrinsicID() == Intrinsic::aarch64_neon_umull);
3140 VectorType *NewVT = cast<VectorType>(II->getType());
3141 if (
Constant *CV0 = dyn_cast<Constant>(Arg0)) {
3142 if (
Constant *CV1 = dyn_cast<Constant>(Arg1)) {
3154 if (
Constant *CV1 = dyn_cast<Constant>(Arg1))
3156 dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
3163 case Intrinsic::arm_neon_aesd:
3164 case Intrinsic::arm_neon_aese:
3165 case Intrinsic::aarch64_crypto_aesd:
3166 case Intrinsic::aarch64_crypto_aese: {
3167 Value *DataArg = II->getArgOperand(0);
3168 Value *KeyArg = II->getArgOperand(1);
3174 II->setArgOperand(0, Data);
3175 II->setArgOperand(1, Key);
3180 case Intrinsic::amdgcn_rcp: {
3181 Value *Src = II->getArgOperand(0);
3184 if (isa<UndefValue>(Src))
3185 return replaceInstUsesWith(CI, Src);
3187 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3188 const APFloat &ArgVal =
C->getValueAPF();
3195 return replaceInstUsesWith(CI,
ConstantFP::get(II->getContext(), Val));
3200 case Intrinsic::amdgcn_rsq: {
3201 Value *Src = II->getArgOperand(0);
3204 if (isa<UndefValue>(Src))
3205 return replaceInstUsesWith(CI, Src);
3208 case Intrinsic::amdgcn_frexp_mant:
3209 case Intrinsic::amdgcn_frexp_exp: {
3210 Value *Src = II->getArgOperand(0);
3211 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3216 if (II->getIntrinsicID() == Intrinsic::amdgcn_frexp_mant) {
3228 if (isa<UndefValue>(Src))
3233 case Intrinsic::amdgcn_class: {
3250 Value *Src0 = II->getArgOperand(0);
3251 Value *Src1 = II->getArgOperand(1);
3254 if (isa<UndefValue>(Src0))
3257 if (isa<UndefValue>(Src1))
3265 if ((Mask & FullMask) == FullMask)
3268 if ((Mask & FullMask) == 0)
3273 Value *FCmp = Builder.CreateFCmpUNO(Src0, Src0);
3275 return replaceInstUsesWith(*II, FCmp);
3280 if (isa<UndefValue>(Src0))
3284 if ((Mask & FullMask) !=
Mask) {
3285 CallInst *NewCall = Builder.CreateCall(II->getCalledFunction(),
3290 return replaceInstUsesWith(*II, NewCall);
3312 case Intrinsic::amdgcn_cvt_pkrtz: {
3313 Value *Src0 = II->getArgOperand(0);
3314 Value *Src1 = II->getArgOperand(1);
3315 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3316 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3318 = II->getType()->getScalarType()->getFltSemantics();
3320 APFloat Val0 = C0->getValueAPF();
3321 APFloat Val1 = C1->getValueAPF();
3328 return replaceInstUsesWith(*II, Folded);
3332 if (isa<UndefValue>(Src0) && isa<UndefValue>(Src1))
3337 case Intrinsic::amdgcn_cvt_pknorm_i16:
3338 case Intrinsic::amdgcn_cvt_pknorm_u16:
3339 case Intrinsic::amdgcn_cvt_pk_i16:
3340 case Intrinsic::amdgcn_cvt_pk_u16: {
3341 Value *Src0 = II->getArgOperand(0);
3342 Value *Src1 = II->getArgOperand(1);
3344 if (isa<UndefValue>(Src0) && isa<UndefValue>(Src1))
3349 case Intrinsic::amdgcn_ubfe:
3350 case Intrinsic::amdgcn_sbfe: {
3352 Value *Src = II->getArgOperand(0);
3353 if (isa<UndefValue>(Src))
3354 return replaceInstUsesWith(*II, Src);
3357 Type *Ty = II->getType();
3363 if ((Width & (IntSize - 1)) == 0)
3366 if (Width >= IntSize) {
3369 Width & (IntSize - 1)));
3378 if (Offset >= IntSize) {
3380 Offset & (IntSize - 1)));
3385 bool Signed = II->getIntrinsicID() == Intrinsic::amdgcn_sbfe;
3388 if (!CWidth && COffset && Offset == 0) {
3390 Value *ShiftVal = Builder.CreateSub(KSize, II->getArgOperand(2));
3391 ShiftVal = Builder.CreateZExt(ShiftVal, II->getType());
3393 Value *Shl = Builder.CreateShl(Src, ShiftVal);
3394 Value *RightShift = Signed ? Builder.CreateAShr(Shl, ShiftVal)
3395 : Builder.CreateLShr(Shl, ShiftVal);
3397 return replaceInstUsesWith(*II, RightShift);
3400 if (!CWidth || !COffset)
3405 if (Offset + Width < IntSize) {
3406 Value *Shl = Builder.CreateShl(Src, IntSize - Offset - Width);
3407 Value *RightShift = Signed ? Builder.CreateAShr(Shl, IntSize - Width)
3408 : Builder.CreateLShr(Shl, IntSize - Width);
3410 return replaceInstUsesWith(*II, RightShift);
3413 Value *RightShift = Signed ? Builder.CreateAShr(Src, Offset)
3414 : Builder.CreateLShr(Src, Offset);
3417 return replaceInstUsesWith(*II, RightShift);
3419 case Intrinsic::amdgcn_exp:
3420 case Intrinsic::amdgcn_exp_compr: {
3429 bool IsCompr = II->getIntrinsicID() == Intrinsic::amdgcn_exp_compr;
3430 bool Changed =
false;
3431 for (
int I = 0;
I < (IsCompr ? 2 : 4); ++
I) {
3432 if ((!IsCompr && (EnBits & (1 <<
I)) == 0) ||
3433 (IsCompr && ((EnBits & (0x3 << (2 *
I))) == 0))) {
3434 Value *Src = II->getArgOperand(
I + 2);
3435 if (!isa<UndefValue>(Src)) {
3447 case Intrinsic::amdgcn_fmed3: {
3451 Value *Src0 = II->getArgOperand(0);
3452 Value *Src1 = II->getArgOperand(1);
3453 Value *Src2 = II->getArgOperand(2);
3459 if (
match(Src0,
m_NaN()) || isa<UndefValue>(Src0)) {
3460 NewCall = Builder.CreateMinNum(Src1, Src2);
3461 }
else if (
match(Src1,
m_NaN()) || isa<UndefValue>(Src1)) {
3462 NewCall = Builder.CreateMinNum(Src0, Src2);
3463 }
else if (
match(Src2,
m_NaN()) || isa<UndefValue>(Src2)) {
3464 NewCall = Builder.CreateMaxNum(Src0, Src1);
3470 return replaceInstUsesWith(*II, NewCall);
3477 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3482 if (isa<Constant>(Src1) && !isa<Constant>(Src2)) {
3487 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3493 II->setArgOperand(0, Src0);
3494 II->setArgOperand(1, Src1);
3495 II->setArgOperand(2, Src2);
3499 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3500 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3501 if (
const ConstantFP *C2 = dyn_cast<ConstantFP>(Src2)) {
3504 return replaceInstUsesWith(*II,
3512 case Intrinsic::amdgcn_icmp:
3513 case Intrinsic::amdgcn_fcmp: {
3520 bool IsInteger = II->getIntrinsicID() == Intrinsic::amdgcn_icmp;
3527 Value *Src0 = II->getArgOperand(0);
3528 Value *Src1 = II->getArgOperand(1);
3530 if (
auto *CSrc0 = dyn_cast<Constant>(Src0)) {
3531 if (
auto *CSrc1 = dyn_cast<Constant>(Src1)) {
3534 return replaceInstUsesWith(
3544 II->getModule(), Intrinsic::read_register, II->getType());
3548 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3551 NewCall->takeName(II);
3552 return replaceInstUsesWith(*II, NewCall);
3558 II->setArgOperand(0, Src1);
3559 II->setArgOperand(1, Src0);
3561 static_cast<int>(SwapPred)));
3604 Intrinsic::amdgcn_fcmp : Intrinsic::amdgcn_icmp;
3610 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3612 return replaceInstUsesWith(*II, NewCall);
3617 case Intrinsic::amdgcn_wqm_vote: {
3619 if (!isa<Constant>(II->getArgOperand(0)))
3622 return replaceInstUsesWith(*II, II->getArgOperand(0));
3624 case Intrinsic::amdgcn_kill: {
3630 return eraseInstFromFunction(CI);
3632 case Intrinsic::amdgcn_update_dpp: {
3633 Value *Old = II->getArgOperand(0);
3638 if (!BC || !RM || !BM ||
3639 BC->isZeroValue() ||
3640 RM->getZExtValue() != 0xF ||
3641 BM->getZExtValue() != 0xF ||
3642 isa<UndefValue>(Old))
3649 case Intrinsic::stackrestore: {
3652 if (
IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
3653 if (SS->getIntrinsicID() == Intrinsic::stacksave) {
3655 if (SS->getNextNonDebugInstruction() == II) {
3656 return eraseInstFromFunction(CI);
3665 bool CannotRemove =
false;
3666 for (++BI; &*BI != TI; ++BI) {
3667 if (isa<AllocaInst>(BI)) {
3668 CannotRemove =
true;
3671 if (
CallInst *BCI = dyn_cast<CallInst>(BI)) {
3674 if (II->getIntrinsicID() == Intrinsic::stackrestore)
3675 return eraseInstFromFunction(CI);
3679 if (II->mayHaveSideEffects()) {
3680 CannotRemove =
true;
3686 CannotRemove =
true;
3695 if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI)))
3696 return eraseInstFromFunction(CI);
3699 case Intrinsic::lifetime_start:
3702 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
3703 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
3707 Intrinsic::lifetime_end, *
this))
3710 case Intrinsic::assume: {
3711 Value *IIOperand = II->getArgOperand(0);
3716 if (
match(Next, m_Intrinsic<Intrinsic::assume>(
m_Specific(IIOperand))))
3717 return eraseInstFromFunction(CI);
3722 Value *AssumeIntrinsic = II->getCalledValue(), *A, *
B;
3724 Builder.CreateCall(AssumeIntrinsic, A, II->getName());
3725 Builder.CreateCall(AssumeIntrinsic, B, II->
getName());
3726 return eraseInstFromFunction(*II);
3730 Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(A), II->
getName());
3731 Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(B), II->
getName());
3732 return eraseInstFromFunction(*II);
3745 return eraseInstFromFunction(*II);
3756 return eraseInstFromFunction(*II);
3760 AC.updateAffectedValues(II);
3763 case Intrinsic::experimental_gc_relocate: {
3767 Value *DerivedPtr = cast<GCRelocateInst>(II)->getDerivedPtr();
3771 if (II->use_empty())
3772 return eraseInstFromFunction(*II);
3778 if (isa<UndefValue>(DerivedPtr))
3782 if (
auto *PT = dyn_cast<PointerType>(II->getType())) {
3786 if (isa<ConstantPointerNull>(DerivedPtr))
3802 case Intrinsic::experimental_guard: {
3813 Value *NextCond =
nullptr;
3815 m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(NextCond)))) {
3816 Value *CurrCond = II->getArgOperand(0);
3819 if (CurrCond == NextCond)
3820 return eraseInstFromFunction(*NextInst);
3824 while (MoveI != NextInst) {
3829 II->setArgOperand(0, Builder.CreateAnd(CurrCond, NextCond));
3830 return eraseInstFromFunction(*NextInst);
3835 return visitCallSite(II);
3842 if (
auto *NFI = dyn_cast<FenceInst>(Next))
3844 return eraseInstFromFunction(FI);
3850 return visitCallSite(&II);
3878 Type* DstTy = cast<PointerType>(CI->
getType())->getElementType();
3890 replaceInstUsesWith(*From, With);
3895 return CI->
use_empty() ? CI : replaceInstUsesWith(*CI, With);
3905 if (Underlying != TrampMem &&
3908 if (!isa<AllocaInst>(Underlying))
3920 InitTrampoline = II;
3930 if (!InitTrampoline)
3934 if (InitTrampoline->
getOperand(0) != TrampMem)
3937 return InitTrampoline;
3949 if (II->getIntrinsicID() == Intrinsic::init_trampoline &&
3950 II->getOperand(0) == TrampMem)
3982 bool Changed =
false;
3991 if (V->getType()->isPointerTy() &&
4000 if (!ArgNos.
empty()) {
4012 if (!isa<Function>(Callee) && transformConstExprCastCall(CS))
4015 if (
Function *CalleeF = dyn_cast<Function>(Callee)) {
4018 !CalleeF->isIntrinsic()) {
4031 !CalleeF->isDeclaration()) {
4040 if (isa<CallInst>(OldCall))
4041 return eraseInstFromFunction(*OldCall);
4045 cast<InvokeInst>(OldCall)->setCalledFunction(
4051 if ((isa<ConstantPointerNull>(Callee) &&
4053 isa<UndefValue>(
Callee)) {
4076 return transformCallThroughTrampoline(CS, II);
4080 if (FTy->isVarArg()) {
4107 if (I)
return eraseInstFromFunction(*I);
4115 bool InstCombiner::transformConstExprCastCall(
CallSite CS) {
4123 if (
Callee->hasFnAttribute(
"thunk"))
4144 if (OldRetTy != NewRetTy) {
4150 if (
Callee->isDeclaration())
4170 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller))
4172 if (
PHINode *PN = dyn_cast<PHINode>(U))
4173 if (PN->getParent() == II->getNormalDest() ||
4174 PN->getParent() == II->getUnwindDest())
4178 unsigned NumActualArgs = CS.
arg_size();
4179 unsigned NumCommonArgs = std::min(FT->
getNumParams(), NumActualArgs);
4189 if (
Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) ||
4190 Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal))
4194 for (
unsigned i = 0, e = NumCommonArgs; i != e; ++i, ++AI) {
4196 Type *ActTy = (*AI)->getType();
4216 if (DL.getTypeAllocSize(CurElTy) !=
4222 if (
Callee->isDeclaration()) {
4260 ArgAttrs.
reserve(NumActualArgs);
4270 for (
unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
4273 Value *NewArg = *AI;
4274 if ((*AI)->getType() != ParamTy)
4275 NewArg = Builder.CreateBitOrPointerCast(*AI, ParamTy);
4284 for (
unsigned i = NumCommonArgs; i != FT->
getNumParams(); ++i) {
4294 for (
unsigned i = FT->
getNumParams(); i != NumActualArgs; ++i, ++AI) {
4296 Value *NewArg = *AI;
4297 if (PTy != (*AI)->getType()) {
4301 NewArg = Builder.CreateCast(opcode, *AI, PTy);
4317 "missing argument attributes");
4326 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4327 NewCS = Builder.CreateInvoke(
Callee, II->getNormalDest(),
4328 II->getUnwindDest(),
Args, OpBundles);
4330 NewCS = Builder.CreateCall(
Callee, Args, OpBundles);
4332 ->setTailCallKind(cast<CallInst>(Caller)->getTailCallKind());
4334 NewCS->takeName(Caller);
4342 NewCS->setProfWeight(W);
4354 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4356 InsertNewInstBefore(NC, *I);
4359 InsertNewInstBefore(NC, *Caller);
4361 Worklist.AddUsersToWorkList(*Caller);
4368 replaceInstUsesWith(*Caller, NV);
4370 if (OldRetTy == NV->
getType())
4378 eraseInstFromFunction(*Caller);
4385 InstCombiner::transformCallThroughTrampoline(
CallSite CS,
4394 if (Attrs.hasAttrSomewhere(Attribute::Nest))
4398 "transformCallThroughTrampoline called with incorrect CallSite.");
4404 if (!NestAttrs.isEmpty()) {
4405 unsigned NestArgNo = 0;
4406 Type *NestTy =
nullptr;
4411 E = NestFTy->param_end();
4412 I !=
E; ++NestArgNo, ++
I) {
4424 std::vector<Value*> NewArgs;
4425 std::vector<AttributeSet> NewArgAttrs;
4426 NewArgs.reserve(CS.
arg_size() + 1);
4427 NewArgAttrs.reserve(CS.
arg_size());
4436 if (ArgNo == NestArgNo) {
4439 if (NestVal->
getType() != NestTy)
4440 NestVal = Builder.CreateBitCast(NestVal, NestTy,
"nest");
4441 NewArgs.push_back(NestVal);
4442 NewArgAttrs.push_back(NestAttr);
4449 NewArgs.push_back(*I);
4450 NewArgAttrs.push_back(Attrs.getParamAttributes(ArgNo));
4461 std::vector<Type*> NewTypes;
4462 NewTypes.reserve(FTy->getNumParams()+1);
4469 E = FTy->param_end();
4472 if (ArgNo == NestArgNo)
4474 NewTypes.push_back(NestTy);
4480 NewTypes.push_back(*I);
4497 Attrs.getRetAttributes(), NewArgAttrs);
4503 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4505 II->getNormalDest(), II->getUnwindDest(),
4506 NewArgs, OpBundles);
4507 cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv());
4508 cast<InvokeInst>(NewCaller)->setAttributes(NewPAL);
4511 cast<CallInst>(NewCaller)->setTailCallKind(
4512 cast<CallInst>(Caller)->getTailCallKind());
4513 cast<CallInst>(NewCaller)->setCallingConv(
4514 cast<CallInst>(Caller)->getCallingConv());
4515 cast<CallInst>(NewCaller)->setAttributes(NewPAL);
4527 NestF->
getType() == PTy ? NestF :
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
bool isFPPredicate() const
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)
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...
BinaryOp_match< cstfp_pred_ty< is_neg_zero_fp >, RHS, Instruction::FSub > m_FNeg(const RHS &X)
Match 'fneg X' as 'fsub -0.0, X'.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
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 computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Instruction *CxtI) const
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.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
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 GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static IntegerType * getInt1Ty(LLVMContext &C)
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
uint64_t getZExtValue() const
Get zero extended value.
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.
static Value * simplifyX86immShift(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
DiagnosticInfoOptimizationBase::Argument NV
unsigned arg_size() const
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
Atomic ordering constants.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Compute iterated dominance frontiers using a linear time algorithm.
Type * getParamType(unsigned i) const
Parameter type accessors.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
unsigned countMinPopulation() const
Returns the number of bits known to be one.
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
A Module instance is used to store all the information related to an LLVM module. ...
Instruction * visitCallInst(CallInst &CI)
CallInst simplification.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
An instruction for ordering other memory operations.
static MDString * get(LLVMContext &Context, StringRef Str)
Instruction * visitVACopyInst(VACopyInst &I)
static Instruction * simplifyInvariantGroupIntrinsic(IntrinsicInst &II, InstCombiner &IC)
This function transforms launder.invariant.group and strip.invariant.group like: launder(launder(x)) ...
static ConstantAggregateZero * get(Type *Ty)
static bool simplifyX86MaskedStore(IntrinsicInst &II, InstCombiner &IC)
This class represents a function call, abstracting a target machine's calling convention.
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
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.
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...
iterator_range< IterTy > args() const
static uint64_t round(uint64_t Acc, uint64_t Input)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
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)
LLVMContext & getContext() const
All values hold a context through their type.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
APInt trunc(unsigned width) const
Truncate to new width.
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.
STATISTIC(NumFunctions, "Total number of functions")
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const fltSemantics & getSemantics() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
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)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
bool isVectorTy() const
True if this is an instance of VectorType.
static OverflowCheckFlavor IntrinsicIDToOverflowCheckFlavor(unsigned ID)
Returns the OverflowCheckFlavor corresponding to a overflow_with_op intrinsic.
void reserve(size_type N)
Value * getLength() const
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
static Instruction * simplifyMaskedStore(IntrinsicInst &II, InstCombiner &IC)
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
Instruction * visitVAStartInst(VAStartInst &I)
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * CreateLaunderInvariantGroup(Value *Ptr)
Create a launder.invariant.group intrinsic call.
bool isGCRelocate(ImmutableCallSite CS)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
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.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
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...
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions (including addrspacecast) that ...
iterator begin()
Instruction iterator methods.
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
opStatus divide(const APFloat &RHS, roundingMode RM)
static Instruction * SimplifyNVVMIntrinsic(IntrinsicInst *II, InstCombiner &IC)
bool match(Val *V, const Pattern &P)
Instruction * visitInvokeInst(InvokeInst &II)
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
static APFloat fmed3AMDGCN(const APFloat &Src0, const APFloat &Src1, const APFloat &Src2)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
Type * getPointerElementType() const
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
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.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
APInt shl(unsigned shiftAmt) const
Left-shift function.
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
static Value * simplifyNeonTbl1(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Convert a table lookup to shufflevector if the mask is constant.
Instruction * eraseInstFromFunction(Instruction &I)
Combiner aware instruction erasure.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool isIntegerTy() const
True if this is an instance of IntegerType.
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...
This file contains the simple types necessary to represent the attributes associated with functions a...
InstrTy * getInstruction() const
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
void setName(const Twine &Name)
Change the name of the value.
uint64_t getNumElements() 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...
All zero aggregate value.
static Value * simplifyX86vpermv(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert vpermd/vpermps to shufflevector if the mask is constant.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E, unsigned NumOperands)
DominatorTree & getDominatorTree() const
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Type * getType() const
All values are typed, get the type of this value.
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
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)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
static Value * simplifyX86pack(IntrinsicInst &II, bool IsSigned)
AttributeList getAttributes() const
Return the attribute list for this Function.
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
An instruction for storing to memory.
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
static void ValueIsRAUWd(Value *Old, Value *New)
static Value * simplifyX86vpcom(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder, bool IsSigned)
Decode XOP integer vector comparison intrinsics.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
void takeName(Value *V)
Transfer the name from V to this value.
static Value * simplifyX86movmsk(const IntrinsicInst &II)
amdgpu Simplify well known AMD library false Value * Callee
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
This class represents a truncation of integer types.
Type * getElementType() const
Return the element type of the array/vector.
Value * getOperand(unsigned i) const
Class to represent pointers.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Value * getOperand(unsigned i_nocapture) const
const DataLayout & getDataLayout() const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isVoidTy() const
Return true if this is 'void'.
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...
OneUse_match< T > m_OneUse(const T &SubPattern)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
bool isNegative() const
Determine sign of this APInt.
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
bool doesNotThrow() const
Determine if the call cannot unwind.
Instruction * visitFenceInst(FenceInst &FI)
initializer< Ty > init(const Ty &Val)
static Instruction * simplifyMaskedScatter(IntrinsicInst &II, InstCombiner &IC)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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)
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 @llvm.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.
CallInst * CreateIntrinsic(Intrinsic::ID ID, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with no operands.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool isPointerTy() const
True if this is an instance of PointerType.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
ConstantFP - Floating Point Values [float, double].
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
const Instruction * getNextNonDebugInstruction() const
Return a pointer to the next non-debug instruction in the same basic block as 'this', or nullptr if no such instruction exists.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isFast() const
Determine whether all fast-math-flags are set.
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)
void setCalledFunction(Value *Fn)
Set the function called.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
bool isAllOnes() const
Returns true if value is all one bits.
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
bool isGCResult(ImmutableCallSite CS)
This class represents any memset intrinsic.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
void setArgOperand(unsigned i, Value *v)
self_iterator getIterator()
Class to represent integer types.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
const Function * getFunction() const
Return the function this instruction belongs to.
void setAlignment(unsigned Align)
static Constant * getAllOnesValue(Type *Ty)
static Value * simplifyX86varShift(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
iterator_range< User::op_iterator > arg_operands()
Iteration adapter for range-for loops.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
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...
const APFloat & getValueAPF() const
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
bool doesNotThrow() const
Determine if the function cannot unwind.
static BinaryOperator * CreateFNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
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.
Iterator for intrusive lists based on ilist_node.
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
static cl::opt< unsigned > GuardWideningWindow("instcombine-guard-widening-window", cl::init(3), cl::desc("How wide an instruction window to bypass looking for " "another guard"))
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
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.
static Value * simplifyX86vpermilvar(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert vpermilvar* to shufflevector if the mask is constant.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
static IntrinsicInst * findInitTrampolineFromAlloca(Value *TrampMem)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
Type::subtype_iterator param_iterator
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that's in the specified builder.
static Value * simplifyNeonVld1(const IntrinsicInst &II, unsigned MemAlign, InstCombiner::BuilderTy &Builder)
Convert a vector load intrinsic into a simple llvm load instruction.
static Instruction * simplifyMaskedGather(IntrinsicInst &II, InstCombiner &IC)
Type * getReturnType() const
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="")
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.
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 uge(const APInt &RHS) const
Unsigned greater or equal comparison.
const Value * stripPointerCastsAndInvariantGroups() const
Strip off pointer casts, all-zero GEPs, aliases and invariant group info.
Value * SimplifyCall(ImmutableCallSite CS, const SimplifyQuery &Q)
Given a callsite, fold the result or return null.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
void setOperand(unsigned i_nocapture, Value *Val_nocapture)
Class to represent vector types.
void setVolatile(bool V)
Specify whether this is a volatile store or not.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
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()
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))
amdgpu Simplify well known AMD library false Value Value * Arg
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
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")))
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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)
static Value * simplifyMaskedLoad(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
static Instruction * simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static bool maskIsAllOneOrUndef(Value *Mask)
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getIntegerBitWidth() const
LLVM_NODISCARD bool empty() const
unsigned getNumArgOperands() const
Return the number of call arguments.
StringRef getValueAsString() const
Return the attribute's value as a string.
unsigned greater or equal
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
StringRef getName() const
Return a constant reference to the value's name.
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.
bool doesNotThrow() const
Determine if the call cannot unwind.
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...
Value * CreateStripInvariantGroup(Value *Ptr)
Create a strip.invariant.group intrinsic call.
Value * optimizeCall(CallInst *CI)
optimizeCall - Take the given call instruction and return a more optimal value to replace the instruc...
static bool removeTriviallyEmptyRange(IntrinsicInst &I, unsigned StartID, unsigned EndID, InstCombiner &IC)
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.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
static IntrinsicInst * findInitTrampoline(Value *Callee)
bool isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
AssumptionCache & getAssumptionCache() const
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
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...
This represents the llvm.va_copy intrinsic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static Value * simplifyX86round(IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
LoadInst * CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name)
Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' correctly, instead of converting the strin...
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)
This file provides internal interfaces used to implement the InstCombine.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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.
AttributeSet getFnAttributes() const
The function attributes are returned.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
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 hasOneUse() const
Return true if there is exactly one user of this value.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
AttributeList getAttributes() const
Get the parameter attributes of the call.
unsigned getNumElements() const
Return the number of elements in the array or vector.
bool isConvergent() const
Determine if the call is convergent.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
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 Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static Value * simplifyX86insertps(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
This class represents an extension of floating point types.
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
void setVolatile(bool V)
Specify whether this is a volatile load or not.
bool isEmpty() const
Return true if there are no attributes.
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.
Value * getRawDest() const
static Type * getPromotedType(Type *Ty)
Return the specified type promoted as it would be to pass though a va_arg area.
static Constant * get(ArrayRef< Constant *> V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
PointerType * getType() const
Global values are always pointers.
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.
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool isLosslessCast() const
A lossless cast is one that does not alter the basic value.
bool isNullValue() const
Determine if all bits are clear.
bool isStructTy() const
True if this is an instance of StructType.
cmpResult compare(const APFloat &RHS) const
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)