43 #include "llvm/IR/IntrinsicsX86.h" 44 #include "llvm/IR/IntrinsicsARM.h" 45 #include "llvm/IR/IntrinsicsAArch64.h" 46 #include "llvm/IR/IntrinsicsNVPTX.h" 47 #include "llvm/IR/IntrinsicsAMDGPU.h" 48 #include "llvm/IR/IntrinsicsPowerPC.h" 79 #define DEBUG_TYPE "instcombine" 81 STATISTIC(NumSimplified,
"Number of library calls simplified");
84 "instcombine-guard-widening-window",
86 cl::desc(
"How wide an instruction window to bypass looking for " 93 if (ITy->getBitWidth() < 32)
106 assert((isa<ConstantInt>(Elt) || isa<ConstantFP>(Elt)) &&
107 "Unexpected constant data vector element type");
109 ? cast<ConstantInt>(Elt)->isNegative()
110 : cast<ConstantFP>(Elt)->isNegative();
118 unsigned CopyDstAlign = MI->getDestAlignment();
119 if (CopyDstAlign < DstAlign){
120 MI->setDestAlignment(DstAlign);
125 unsigned CopySrcAlign = MI->getSourceAlignment();
126 if (CopySrcAlign < SrcAlign) {
127 MI->setSourceAlignment(SrcAlign);
134 if (AA->pointsToConstantMemory(MI->getDest())) {
143 if (!MemOpLength)
return nullptr;
150 assert(Size &&
"0-sized memory transferring should be removed already.");
152 if (Size > 8 || (Size&(Size-1)))
159 if (isa<AtomicMemTransferInst>(MI))
160 if (CopyDstAlign < Size || CopySrcAlign < Size)
165 cast<PointerType>(MI->getArgOperand(1)->getType())->getAddressSpace();
167 cast<PointerType>(MI->getArgOperand(0)->getType())->getAddressSpace();
176 if (
MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa)) {
178 }
else if (
MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
179 if (M->getNumOperands() == 3 && M->getOperand(0) &&
180 mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
181 mdconst::extract<ConstantInt>(M->getOperand(0))->
isZero() &&
183 mdconst::hasa<ConstantInt>(M->getOperand(1)) &&
184 mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
186 M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
187 CopyMD = cast<MDNode>(M->getOperand(2));
190 Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
191 Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
192 LoadInst *L = Builder.CreateLoad(IntType, Src);
198 MDNode *LoopMemParallelMD =
199 MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
200 if (LoopMemParallelMD)
201 L->
setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
202 MDNode *AccessGroupMD = MI->getMetadata(LLVMContext::MD_access_group);
204 L->
setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
206 StoreInst *S = Builder.CreateStore(L, Dest);
212 if (LoopMemParallelMD)
213 S->
setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
215 S->
setMetadata(LLVMContext::MD_access_group, AccessGroupMD);
217 if (
auto *MT = dyn_cast<MemTransferInst>(MI)) {
222 if (isa<AtomicMemTransferInst>(MI)) {
234 const unsigned KnownAlignment =
236 if (MI->getDestAlignment() < KnownAlignment) {
237 MI->setDestAlignment(KnownAlignment);
244 if (AA->pointsToConstantMemory(MI->getDest())) {
256 assert(Len &&
"0-sized memory setting should be removed already.");
263 if (isa<AtomicMemSetInst>(MI))
271 Value *Dest = MI->getDest();
272 unsigned DstAddrSp = cast<PointerType>(Dest->getType())->getAddressSpace();
274 Dest = Builder.CreateBitCast(Dest, NewDstPtrTy);
277 uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL;
281 if (isa<AtomicMemSetInst>(MI))
294 bool LogicalShift =
false;
295 bool ShiftLeft =
false;
299 case Intrinsic::x86_sse2_psra_d:
300 case Intrinsic::x86_sse2_psra_w:
301 case Intrinsic::x86_sse2_psrai_d:
302 case Intrinsic::x86_sse2_psrai_w:
303 case Intrinsic::x86_avx2_psra_d:
304 case Intrinsic::x86_avx2_psra_w:
305 case Intrinsic::x86_avx2_psrai_d:
306 case Intrinsic::x86_avx2_psrai_w:
307 case Intrinsic::x86_avx512_psra_q_128:
308 case Intrinsic::x86_avx512_psrai_q_128:
309 case Intrinsic::x86_avx512_psra_q_256:
310 case Intrinsic::x86_avx512_psrai_q_256:
311 case Intrinsic::x86_avx512_psra_d_512:
312 case Intrinsic::x86_avx512_psra_q_512:
313 case Intrinsic::x86_avx512_psra_w_512:
314 case Intrinsic::x86_avx512_psrai_d_512:
315 case Intrinsic::x86_avx512_psrai_q_512:
316 case Intrinsic::x86_avx512_psrai_w_512:
317 LogicalShift =
false; ShiftLeft =
false;
319 case Intrinsic::x86_sse2_psrl_d:
320 case Intrinsic::x86_sse2_psrl_q:
321 case Intrinsic::x86_sse2_psrl_w:
322 case Intrinsic::x86_sse2_psrli_d:
323 case Intrinsic::x86_sse2_psrli_q:
324 case Intrinsic::x86_sse2_psrli_w:
325 case Intrinsic::x86_avx2_psrl_d:
326 case Intrinsic::x86_avx2_psrl_q:
327 case Intrinsic::x86_avx2_psrl_w:
328 case Intrinsic::x86_avx2_psrli_d:
329 case Intrinsic::x86_avx2_psrli_q:
330 case Intrinsic::x86_avx2_psrli_w:
331 case Intrinsic::x86_avx512_psrl_d_512:
332 case Intrinsic::x86_avx512_psrl_q_512:
333 case Intrinsic::x86_avx512_psrl_w_512:
334 case Intrinsic::x86_avx512_psrli_d_512:
335 case Intrinsic::x86_avx512_psrli_q_512:
336 case Intrinsic::x86_avx512_psrli_w_512:
337 LogicalShift =
true; ShiftLeft =
false;
339 case Intrinsic::x86_sse2_psll_d:
340 case Intrinsic::x86_sse2_psll_q:
341 case Intrinsic::x86_sse2_psll_w:
342 case Intrinsic::x86_sse2_pslli_d:
343 case Intrinsic::x86_sse2_pslli_q:
344 case Intrinsic::x86_sse2_pslli_w:
345 case Intrinsic::x86_avx2_psll_d:
346 case Intrinsic::x86_avx2_psll_q:
347 case Intrinsic::x86_avx2_psll_w:
348 case Intrinsic::x86_avx2_pslli_d:
349 case Intrinsic::x86_avx2_pslli_q:
350 case Intrinsic::x86_avx2_pslli_w:
351 case Intrinsic::x86_avx512_psll_d_512:
352 case Intrinsic::x86_avx512_psll_q_512:
353 case Intrinsic::x86_avx512_psll_w_512:
354 case Intrinsic::x86_avx512_pslli_d_512:
355 case Intrinsic::x86_avx512_pslli_q_512:
356 case Intrinsic::x86_avx512_pslli_w_512:
357 LogicalShift =
true; ShiftLeft =
true;
360 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
367 if (!CAZ && !CDV && !CInt)
374 auto VT = cast<VectorType>(CDV->getType());
375 unsigned BitWidth = VT->getElementType()->getPrimitiveSizeInBits();
376 assert((64 % BitWidth) == 0 &&
"Unexpected packed shift size");
377 unsigned NumSubElts = 64 / BitWidth;
380 for (
unsigned i = 0; i != NumSubElts; ++i) {
381 unsigned SubEltIdx = (NumSubElts - 1) - i;
382 auto SubElt = cast<ConstantInt>(CDV->getElementAsConstant(SubEltIdx));
388 Count = CInt->getValue();
391 auto VT = cast<VectorType>(Vec->getType());
392 auto SVT = VT->getElementType();
393 unsigned VWidth = VT->getNumElements();
394 unsigned BitWidth = SVT->getPrimitiveSizeInBits();
401 if (Count.
uge(BitWidth)) {
407 Count =
APInt(64, BitWidth - 1);
428 bool LogicalShift =
false;
429 bool ShiftLeft =
false;
433 case Intrinsic::x86_avx2_psrav_d:
434 case Intrinsic::x86_avx2_psrav_d_256:
435 case Intrinsic::x86_avx512_psrav_q_128:
436 case Intrinsic::x86_avx512_psrav_q_256:
437 case Intrinsic::x86_avx512_psrav_d_512:
438 case Intrinsic::x86_avx512_psrav_q_512:
439 case Intrinsic::x86_avx512_psrav_w_128:
440 case Intrinsic::x86_avx512_psrav_w_256:
441 case Intrinsic::x86_avx512_psrav_w_512:
442 LogicalShift =
false;
445 case Intrinsic::x86_avx2_psrlv_d:
446 case Intrinsic::x86_avx2_psrlv_d_256:
447 case Intrinsic::x86_avx2_psrlv_q:
448 case Intrinsic::x86_avx2_psrlv_q_256:
449 case Intrinsic::x86_avx512_psrlv_d_512:
450 case Intrinsic::x86_avx512_psrlv_q_512:
451 case Intrinsic::x86_avx512_psrlv_w_128:
452 case Intrinsic::x86_avx512_psrlv_w_256:
453 case Intrinsic::x86_avx512_psrlv_w_512:
457 case Intrinsic::x86_avx2_psllv_d:
458 case Intrinsic::x86_avx2_psllv_d_256:
459 case Intrinsic::x86_avx2_psllv_q:
460 case Intrinsic::x86_avx2_psllv_q_256:
461 case Intrinsic::x86_avx512_psllv_d_512:
462 case Intrinsic::x86_avx512_psllv_q_512:
463 case Intrinsic::x86_avx512_psllv_w_128:
464 case Intrinsic::x86_avx512_psllv_w_256:
465 case Intrinsic::x86_avx512_psllv_w_512:
470 assert((LogicalShift || !ShiftLeft) &&
"Only logical shifts can shift left");
478 auto VT = cast<VectorType>(II.
getType());
479 auto SVT = VT->getVectorElementType();
480 int NumElts = VT->getNumElements();
481 int BitWidth = SVT->getIntegerBitWidth();
485 bool AnyOutOfRange =
false;
487 for (
int I = 0;
I < NumElts; ++
I) {
488 auto *CElt = CShift->getAggregateElement(
I);
489 if (CElt && isa<UndefValue>(CElt)) {
494 auto *COp = dyn_cast_or_null<ConstantInt>(CElt);
501 APInt ShiftVal = COp->getValue();
502 if (ShiftVal.
uge(BitWidth)) {
503 AnyOutOfRange = LogicalShift;
504 ShiftAmts.
push_back(LogicalShift ? BitWidth : BitWidth - 1);
513 auto OutOfRange = [&](
int Idx) {
return (Idx < 0) || (BitWidth <= Idx); };
516 for (
int Idx : ShiftAmts) {
520 assert(LogicalShift &&
"Logical shift expected");
533 for (
int Idx : ShiftAmts) {
557 if (isa<UndefValue>(Arg0) && isa<UndefValue>(Arg1))
564 "Unexpected packing types");
566 unsigned NumSrcEltsPerLane = NumSrcElts / NumLanes;
569 assert(SrcScalarSizeInBits == (2 * DstScalarSizeInBits) &&
570 "Unexpected packing types");
573 if (!isa<Constant>(Arg0) || !isa<Constant>(Arg1))
578 APInt MinValue, MaxValue;
604 for (
unsigned Lane = 0; Lane != NumLanes; ++Lane) {
605 for (
unsigned Elt = 0; Elt != NumSrcEltsPerLane; ++Elt)
606 PackMask.
push_back(Elt + (Lane * NumSrcEltsPerLane));
607 for (
unsigned Elt = 0; Elt != NumSrcEltsPerLane; ++Elt)
608 PackMask.
push_back(Elt + (Lane * NumSrcEltsPerLane) + NumSrcElts);
623 if (isa<UndefValue>(Arg))
655 "Unexpected types for x86 addcarry");
687 uint8_t Imm = CInt->getZExtValue();
688 uint8_t ZMask = Imm & 0xf;
689 uint8_t DestLane = (Imm >> 4) & 0x3;
690 uint8_t SourceLane = (Imm >> 6) & 0x3;
700 uint32_t ShuffleMask[4] = { 0, 1, 2, 3 };
709 (ZMask & (1 << DestLane))) {
713 ShuffleMask[DestLane] = SourceLane;
715 for (
unsigned i = 0; i < 4; ++i)
716 if ((ZMask >> i) & 0x1)
717 ShuffleMask[i] = i + 4;
724 ShuffleMask[DestLane] = SourceLane + 4;
735 auto LowConstantHighUndef = [&](uint64_t Val) {
749 if (CILength && CIIndex) {
759 unsigned Length = APLength == 0 ? 64 : APLength.
getZExtValue();
763 unsigned End = Index + Length;
774 if ((Length % 8) == 0 && (Index % 8) == 0) {
784 for (
int i = 0; i != (int)Length; ++i)
787 for (
int i = Length; i != 8; ++i)
790 for (
int i = 8; i != 16; ++i)
802 APInt Elt = CI0->getValue();
810 Value *
Args[] = {Op0, CILength, CIIndex};
818 if (CI0 && CI0->isZero())
819 return LowConstantHighUndef(0);
839 unsigned Length = APLength == 0 ? 64 : APLength.
getZExtValue();
843 unsigned End = Index + Length;
854 if ((Length % 8) == 0 && (Index % 8) == 0) {
864 for (
int i = 0; i != (int)Index; ++i)
866 for (
int i = 0; i != (int)Length; ++i)
869 for (
int i = Index + Length; i != 8; ++i)
871 for (
int i = 8; i != 16; ++i)
887 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)0))
892 APInt V00 = CI00->getValue();
893 APInt V10 = CI10->getValue();
897 APInt Val = V00 | V10;
911 Value *
Args[] = {Op0, Op1, CILength, CIIndex};
927 auto *VecTy = cast<VectorType>(II.
getType());
929 unsigned NumElts = VecTy->getNumElements();
930 assert((NumElts == 16 || NumElts == 32 || NumElts == 64) &&
931 "Unexpected number of elements in shuffle mask!");
938 for (
unsigned I = 0;
I < NumElts; ++
I) {
940 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
943 if (isa<UndefValue>(COp)) {
948 int8_t
Index = cast<ConstantInt>(COp)->getValue().getZExtValue();
957 Index = ((Index < 0) ? NumElts : Index & 0x0F) + (
I & 0xF0);
974 auto *VecTy = cast<VectorType>(II.
getType());
977 bool IsPD = VecTy->getScalarType()->isDoubleTy();
978 unsigned NumLaneElts = IsPD ? 2 : 4;
979 assert(NumElts == 16 || NumElts == 8 || NumElts == 4 || NumElts == 2);
985 for (
unsigned I = 0;
I < NumElts; ++
I) {
987 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
990 if (isa<UndefValue>(COp)) {
995 APInt Index = cast<ConstantInt>(COp)->getValue();
1006 Index +=
APInt(32, (
I / NumLaneElts) * NumLaneElts);
1024 auto *VecTy = cast<VectorType>(II.
getType());
1026 unsigned Size = VecTy->getNumElements();
1027 assert((Size == 4 || Size == 8 || Size == 16 || Size == 32 || Size == 64) &&
1028 "Unexpected shuffle mask size");
1033 for (
unsigned I = 0;
I <
Size; ++
I) {
1035 if (!COp || (!isa<UndefValue>(COp) && !isa<ConstantInt>(COp)))
1038 if (isa<UndefValue>(COp)) {
1058 unsigned Alignment = cast<ConstantInt>(II.
getArgOperand(1))->getZExtValue();
1063 return Builder.CreateAlignedLoad(II.
getType(), LoadPtr, Alignment,
1071 Value *LI = Builder.CreateAlignedLoad(II.
getType(), LoadPtr, Alignment,
1088 if (ConstMask->isNullValue())
1089 return eraseInstFromFunction(II);
1092 if (ConstMask->isAllOnesValue()) {
1101 APInt UndefElts(DemandedElts.getBitWidth(), 0);
1103 DemandedElts, UndefElts)) {
1134 if (ConstMask->isNullValue())
1135 return eraseInstFromFunction(II);
1141 DemandedElts, UndefElts)) {
1146 DemandedElts, UndefElts)) {
1165 auto *StrippedArg =
Arg->stripPointerCasts();
1166 auto *StrippedInvariantGroupsArg =
Arg->stripPointerCastsAndInvariantGroups();
1167 if (StrippedArg == StrippedInvariantGroupsArg)
1170 Value *Result =
nullptr;
1174 else if (II.
getIntrinsicID() == Intrinsic::strip_invariant_group)
1178 "simplifyInvariantGroupIntrinsic only handles launder and strip");
1185 return cast<Instruction>(Result);
1191 "Expected cttz or ctlz intrinsic");
1232 if (PossibleZeros == DefiniteZeros) {
1252 if (
IT &&
IT->getBitWidth() != 1 && !II.
getMetadata(LLVMContext::MD_range)) {
1266 "Expected ctpop intrinsic");
1281 unsigned BitWidth =
IT->getBitWidth();
1289 if (
IT->getBitWidth() != 1 && !II.
getMetadata(LLVMContext::MD_range)) {
1311 if (isa<ConstantAggregateZero>(Mask))
1323 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1347 if (isa<ConstantAggregateZero>(Mask)) {
1366 unsigned AddrSpace = cast<PointerType>(Ptr->
getType())->getAddressSpace();
1392 return maxnum(Src1, Src2);
1397 return maxnum(Src0, Src2);
1399 return maxnum(Src0, Src1);
1413 auto *VecTy = cast<VectorType>(II.
getType());
1414 unsigned NumElts = VecTy->getNumElements();
1417 if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8)
1422 for (
unsigned I = 0;
I < NumElts; ++
I) {
1425 if (!COp || !isa<ConstantInt>(COp))
1428 Indexes[
I] = cast<ConstantInt>(COp)->getLimitedValue();
1431 if (Indexes[
I] >= NumElts)
1454 MemAlign : IntrAlign->getLimitedValue();
1467 unsigned NumOperands) {
1470 for (
unsigned i = 0; i < NumOperands; i++)
1488 "Start intrinsic does not have expected ID");
1490 for (++BI; BI != BE; ++BI) {
1491 if (
auto *
E = dyn_cast<IntrinsicInst>(BI)) {
1492 if (isa<DbgInfoIntrinsic>(
E) ||
E->getIntrinsicID() == StartID)
1494 if (
E->getIntrinsicID() == EndID &&
1519 enum FtzRequirementTy {
1533 struct SimplifyAction {
1540 FtzRequirementTy FtzRequirement = FTZ_Any;
1542 SimplifyAction() =
default;
1545 : IID(IID), FtzRequirement(FtzReq) {}
1552 : BinaryOp(BinaryOp), FtzRequirement(FtzReq) {}
1554 SimplifyAction(SpecialCase Special, FtzRequirementTy FtzReq)
1555 : Special(Special), FtzRequirement(FtzReq) {}
1560 const SimplifyAction Action = [II]() -> SimplifyAction {
1563 case Intrinsic::nvvm_ceil_d:
1564 return {Intrinsic::ceil, FTZ_Any};
1565 case Intrinsic::nvvm_ceil_f:
1566 return {Intrinsic::ceil, FTZ_MustBeOff};
1567 case Intrinsic::nvvm_ceil_ftz_f:
1568 return {Intrinsic::ceil, FTZ_MustBeOn};
1569 case Intrinsic::nvvm_fabs_d:
1570 return {Intrinsic::fabs, FTZ_Any};
1571 case Intrinsic::nvvm_fabs_f:
1572 return {Intrinsic::fabs, FTZ_MustBeOff};
1573 case Intrinsic::nvvm_fabs_ftz_f:
1574 return {Intrinsic::fabs, FTZ_MustBeOn};
1575 case Intrinsic::nvvm_floor_d:
1576 return {Intrinsic::floor, FTZ_Any};
1577 case Intrinsic::nvvm_floor_f:
1578 return {Intrinsic::floor, FTZ_MustBeOff};
1579 case Intrinsic::nvvm_floor_ftz_f:
1580 return {Intrinsic::floor, FTZ_MustBeOn};
1581 case Intrinsic::nvvm_fma_rn_d:
1582 return {Intrinsic::fma, FTZ_Any};
1583 case Intrinsic::nvvm_fma_rn_f:
1584 return {Intrinsic::fma, FTZ_MustBeOff};
1585 case Intrinsic::nvvm_fma_rn_ftz_f:
1586 return {Intrinsic::fma, FTZ_MustBeOn};
1587 case Intrinsic::nvvm_fmax_d:
1589 case Intrinsic::nvvm_fmax_f:
1591 case Intrinsic::nvvm_fmax_ftz_f:
1593 case Intrinsic::nvvm_fmin_d:
1595 case Intrinsic::nvvm_fmin_f:
1597 case Intrinsic::nvvm_fmin_ftz_f:
1599 case Intrinsic::nvvm_round_d:
1601 case Intrinsic::nvvm_round_f:
1603 case Intrinsic::nvvm_round_ftz_f:
1605 case Intrinsic::nvvm_sqrt_rn_d:
1606 return {Intrinsic::sqrt, FTZ_Any};
1607 case Intrinsic::nvvm_sqrt_f:
1612 return {Intrinsic::sqrt, FTZ_Any};
1613 case Intrinsic::nvvm_sqrt_rn_f:
1614 return {Intrinsic::sqrt, FTZ_MustBeOff};
1615 case Intrinsic::nvvm_sqrt_rn_ftz_f:
1616 return {Intrinsic::sqrt, FTZ_MustBeOn};
1617 case Intrinsic::nvvm_trunc_d:
1618 return {Intrinsic::trunc, FTZ_Any};
1619 case Intrinsic::nvvm_trunc_f:
1620 return {Intrinsic::trunc, FTZ_MustBeOff};
1621 case Intrinsic::nvvm_trunc_ftz_f:
1622 return {Intrinsic::trunc, FTZ_MustBeOn};
1629 case Intrinsic::nvvm_d2i_rz:
1630 case Intrinsic::nvvm_f2i_rz:
1631 case Intrinsic::nvvm_d2ll_rz:
1632 case Intrinsic::nvvm_f2ll_rz:
1633 return {Instruction::FPToSI};
1634 case Intrinsic::nvvm_d2ui_rz:
1635 case Intrinsic::nvvm_f2ui_rz:
1636 case Intrinsic::nvvm_d2ull_rz:
1637 case Intrinsic::nvvm_f2ull_rz:
1638 return {Instruction::FPToUI};
1639 case Intrinsic::nvvm_i2d_rz:
1640 case Intrinsic::nvvm_i2f_rz:
1641 case Intrinsic::nvvm_ll2d_rz:
1642 case Intrinsic::nvvm_ll2f_rz:
1643 return {Instruction::SIToFP};
1644 case Intrinsic::nvvm_ui2d_rz:
1645 case Intrinsic::nvvm_ui2f_rz:
1646 case Intrinsic::nvvm_ull2d_rz:
1647 case Intrinsic::nvvm_ull2f_rz:
1648 return {Instruction::UIToFP};
1651 case Intrinsic::nvvm_add_rn_d:
1652 return {Instruction::FAdd, FTZ_Any};
1653 case Intrinsic::nvvm_add_rn_f:
1654 return {Instruction::FAdd, FTZ_MustBeOff};
1655 case Intrinsic::nvvm_add_rn_ftz_f:
1656 return {Instruction::FAdd, FTZ_MustBeOn};
1657 case Intrinsic::nvvm_mul_rn_d:
1658 return {Instruction::FMul, FTZ_Any};
1659 case Intrinsic::nvvm_mul_rn_f:
1660 return {Instruction::FMul, FTZ_MustBeOff};
1661 case Intrinsic::nvvm_mul_rn_ftz_f:
1662 return {Instruction::FMul, FTZ_MustBeOn};
1663 case Intrinsic::nvvm_div_rn_d:
1664 return {Instruction::FDiv, FTZ_Any};
1665 case Intrinsic::nvvm_div_rn_f:
1666 return {Instruction::FDiv, FTZ_MustBeOff};
1667 case Intrinsic::nvvm_div_rn_ftz_f:
1668 return {Instruction::FDiv, FTZ_MustBeOn};
1675 case Intrinsic::nvvm_rcp_rn_d:
1676 return {SPC_Reciprocal, FTZ_Any};
1677 case Intrinsic::nvvm_rcp_rn_f:
1678 return {SPC_Reciprocal, FTZ_MustBeOff};
1679 case Intrinsic::nvvm_rcp_rn_ftz_f:
1680 return {SPC_Reciprocal, FTZ_MustBeOn};
1711 if (Action.FtzRequirement != FTZ_Any) {
1716 if (FtzEnabled != (Action.FtzRequirement == FTZ_MustBeOn))
1731 if (Action.BinaryOp)
1741 if (!Action.Special)
1744 switch (*Action.Special) {
1745 case SPC_Reciprocal:
1751 llvm_unreachable(
"All SpecialCase enumerators should be handled in switch.");
1767 if (isa<Constant>(Arg0) && !isa<Constant>(Arg1)) {
1777 Value *OperationResult =
nullptr;
1781 return CreateOverflowTuple(WO, OperationResult, OverflowResult);
1790 return replaceInstUsesWith(CI, V);
1793 return visitFree(CI);
1803 if (!II)
return visitCallBase(CI);
1807 if (
auto *MI = dyn_cast<AnyMemIntrinsic>(II)) {
1808 bool Changed =
false;
1812 if (NumBytes->isNullValue())
1813 return eraseInstFromFunction(CI);
1815 if (
ConstantInt *CI = dyn_cast<ConstantInt>(NumBytes))
1816 if (CI->getZExtValue() == 1) {
1824 if (
auto *M = dyn_cast<MemIntrinsic>(MI))
1825 if (M->isVolatile())
1831 if (
auto *MMI = dyn_cast<AnyMemMoveInst>(MI)) {
1832 if (
GlobalVariable *GVSrc = dyn_cast<GlobalVariable>(MMI->getSource()))
1833 if (GVSrc->isConstant()) {
1836 isa<AtomicMemMoveInst>(MMI)
1837 ? Intrinsic::memcpy_element_unordered_atomic
1838 : Intrinsic::memcpy;
1849 if (MTI->getSource() == MTI->getDest())
1850 return eraseInstFromFunction(CI);
1855 if (
auto *MTI = dyn_cast<AnyMemTransferInst>(MI)) {
1858 }
else if (
auto *MSI = dyn_cast<AnyMemSetInst>(MI)) {
1863 if (Changed)
return II;
1869 APInt UndefElts(VWidth, 0);
1871 if (
Value *V = SimplifyDemandedVectorElts(II, AllOnesEltMask, UndefElts)) {
1873 return replaceInstUsesWith(*II, V);
1881 auto SimplifyDemandedVectorEltsLow = [
this](
Value *
Op,
unsigned Width,
1882 unsigned DemandedWidth) {
1883 APInt UndefElts(Width, 0);
1885 return SimplifyDemandedVectorElts(Op, DemandedElts, UndefElts);
1891 case Intrinsic::objectsize:
1893 return replaceInstUsesWith(CI, V);
1895 case Intrinsic::bswap: {
1904 Value *V = Builder.CreateLShr(X, CV);
1909 case Intrinsic::masked_load:
1910 if (
Value *SimplifiedMaskedOp = simplifyMaskedLoad(*II))
1911 return replaceInstUsesWith(CI, SimplifiedMaskedOp);
1913 case Intrinsic::masked_store:
1914 return simplifyMaskedStore(*II);
1915 case Intrinsic::masked_gather:
1916 return simplifyMaskedGather(*II);
1917 case Intrinsic::masked_scatter:
1918 return simplifyMaskedScatter(*II);
1919 case Intrinsic::launder_invariant_group:
1920 case Intrinsic::strip_invariant_group:
1922 return replaceInstUsesWith(*II, SkippedBarrier);
1924 case Intrinsic::powi:
1929 if (Power->isMinusOne())
1933 if (Power->equalsInt(2))
1939 case Intrinsic::cttz:
1940 case Intrinsic::ctlz:
1945 case Intrinsic::ctpop:
1950 case Intrinsic::fshl:
1951 case Intrinsic::fshr: {
1961 if (ModuloC != ShAmtC) {
1967 "Shift amount expected to be modulo bitwidth");
1972 if (IID == Intrinsic::fshr) {
1979 assert(IID == Intrinsic::fshl &&
1980 "All funnel shifts by simple constants should go left");
1985 return BinaryOperator::CreateShl(Op0, ShAmtC);
1990 return BinaryOperator::CreateLShr(Op1,
2002 if (SimplifyDemandedInstructionBits(*II))
2012 if (SimplifyDemandedBits(II, 2, Op2Demanded, Op2Known))
2016 case Intrinsic::uadd_with_overflow:
2017 case Intrinsic::sadd_with_overflow: {
2020 if (
Instruction *
I = foldIntrinsicWithOverflowCommon(II))
2027 const APInt *C0, *C1;
2030 bool IsSigned = IID == Intrinsic::sadd_with_overflow;
2036 IsSigned ? C1->
sadd_ov(*C0, Overflow) : C1->
uadd_ov(*C0, Overflow);
2038 return replaceInstUsesWith(
2039 *II, Builder.CreateBinaryIntrinsic(
2045 case Intrinsic::umul_with_overflow:
2046 case Intrinsic::smul_with_overflow:
2051 case Intrinsic::usub_with_overflow:
2052 if (
Instruction *
I = foldIntrinsicWithOverflowCommon(II))
2056 case Intrinsic::ssub_with_overflow: {
2057 if (
Instruction *
I = foldIntrinsicWithOverflowCommon(II))
2071 return replaceInstUsesWith(
2072 *II, Builder.CreateBinaryIntrinsic(Intrinsic::sadd_with_overflow,
2079 case Intrinsic::uadd_sat:
2080 case Intrinsic::sadd_sat:
2084 case Intrinsic::usub_sat:
2085 case Intrinsic::ssub_sat: {
2103 unsigned BitWidth = Ty->getScalarSizeInBits();
2108 unsigned BitWidth = Ty->getScalarSizeInBits();
2119 return replaceInstUsesWith(
2120 *II, Builder.CreateBinaryIntrinsic(
2121 Intrinsic::sadd_sat, Arg0, NegVal));
2127 if (
auto *
Other = dyn_cast<IntrinsicInst>(Arg0)) {
2129 const APInt *Val, *Val2;
2132 IID == Intrinsic::uadd_sat || IID == Intrinsic::usub_sat;
2133 if (
Other->getIntrinsicID() == IID &&
2141 NewVal = Val->
sadd_ov(*Val2, Overflow);
2152 return replaceInstUsesWith(
2153 *II, Builder.CreateBinaryIntrinsic(
2191 Value *NewCall = Builder.CreateBinaryIntrinsic(NewIID, X, Y, II);
2199 if (
auto *M = dyn_cast<IntrinsicInst>(Arg0)) {
2222 Instruction *NewCall = Builder.CreateBinaryIntrinsic(
2225 return replaceInstUsesWith(*II, NewCall);
2231 case Intrinsic::fmuladd: {
2240 return replaceInstUsesWith(*II, Add);
2246 SQ.getWithInstruction(II))) {
2247 auto *FAdd = BinaryOperator::CreateFAdd(V, II->
getArgOperand(2));
2248 FAdd->copyFastMathFlags(II);
2254 case Intrinsic::fma: {
2280 SQ.getWithInstruction(II))) {
2281 auto *FAdd = BinaryOperator::CreateFAdd(V, II->
getArgOperand(2));
2288 case Intrinsic::copysign: {
2292 Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs,
2294 return replaceInstUsesWith(*II, Fabs);
2301 Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs,
2303 return replaceInstUsesWith(*II, Builder.CreateFNegFMF(Fabs, II));
2310 m_Intrinsic<Intrinsic::copysign>(
m_Value(),
m_Value(SignArg)))) {
2317 case Intrinsic::fabs: {
2329 case Intrinsic::ceil:
2330 case Intrinsic::floor:
2332 case Intrinsic::nearbyint:
2333 case Intrinsic::rint:
2334 case Intrinsic::trunc: {
2338 Value *NarrowII = Builder.CreateUnaryIntrinsic(IID, ExtSrc, II);
2343 case Intrinsic::cos:
2344 case Intrinsic::amdgcn_cos: {
2355 case Intrinsic::sin: {
2359 Value *NewSin = Builder.CreateUnaryIntrinsic(Intrinsic::sin, X, II);
2366 case Intrinsic::ppc_altivec_lvx:
2367 case Intrinsic::ppc_altivec_lvxl:
2371 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2373 return new LoadInst(II->getType(), Ptr);
2376 case Intrinsic::ppc_vsx_lxvw4x:
2377 case Intrinsic::ppc_vsx_lxvd2x: {
2379 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2383 case Intrinsic::ppc_altivec_stvx:
2384 case Intrinsic::ppc_altivec_stvxl:
2390 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2391 return new StoreInst(II->getArgOperand(0), Ptr);
2394 case Intrinsic::ppc_vsx_stxvw4x:
2395 case Intrinsic::ppc_vsx_stxvd2x: {
2398 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2401 case Intrinsic::ppc_qpx_qvlfs:
2406 II->getType()->getVectorNumElements());
2407 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2409 Value *
Load = Builder.CreateLoad(VTy, Ptr);
2413 case Intrinsic::ppc_qpx_qvlfd:
2417 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(0),
2419 return new LoadInst(II->getType(), Ptr);
2422 case Intrinsic::ppc_qpx_qvstfs:
2427 II->getArgOperand(0)->getType()->getVectorNumElements());
2428 Value *TOp = Builder.CreateFPTrunc(II->getArgOperand(0), VTy);
2430 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2434 case Intrinsic::ppc_qpx_qvstfd:
2440 Value *Ptr = Builder.CreateBitCast(II->getArgOperand(1), OpPtrTy);
2441 return new StoreInst(II->getArgOperand(0), Ptr);
2445 case Intrinsic::x86_bmi_bextr_32:
2446 case Intrinsic::x86_bmi_bextr_64:
2447 case Intrinsic::x86_tbm_bextri_u32:
2448 case Intrinsic::x86_tbm_bextri_u64:
2450 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2451 uint64_t Shift =
C->getZExtValue();
2452 uint64_t Length = (Shift >> 8) & 0xff;
2456 if (Length == 0 || Shift >= BitWidth)
2459 if (
auto *InC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2460 uint64_t Result = InC->getZExtValue() >> Shift;
2461 if (Length > BitWidth)
2463 Result &= maskTrailingOnes<uint64_t>(Length);
2471 case Intrinsic::x86_bmi_bzhi_32:
2472 case Intrinsic::x86_bmi_bzhi_64:
2474 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2475 uint64_t
Index =
C->getZExtValue() & 0xff;
2477 if (Index >= BitWidth)
2482 if (
auto *InC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2483 uint64_t Result = InC->getZExtValue();
2484 Result &= maskTrailingOnes<uint64_t>(
Index);
2490 case Intrinsic::x86_bmi_pext_32:
2491 case Intrinsic::x86_bmi_pext_64:
2492 if (
auto *MaskC = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2493 if (MaskC->isNullValue())
2495 if (MaskC->isAllOnesValue())
2498 if (
auto *SrcC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2499 uint64_t Src = SrcC->getZExtValue();
2500 uint64_t
Mask = MaskC->getZExtValue();
2501 uint64_t Result = 0;
2502 uint64_t BitToSet = 1;
2506 uint64_t BitToTest = Mask & -
Mask;
2507 if (BitToTest & Src)
2519 case Intrinsic::x86_bmi_pdep_32:
2520 case Intrinsic::x86_bmi_pdep_64:
2521 if (
auto *MaskC = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
2522 if (MaskC->isNullValue())
2524 if (MaskC->isAllOnesValue())
2527 if (
auto *SrcC = dyn_cast<ConstantInt>(II->getArgOperand(0))) {
2528 uint64_t Src = SrcC->getZExtValue();
2529 uint64_t
Mask = MaskC->getZExtValue();
2530 uint64_t Result = 0;
2531 uint64_t BitToTest = 1;
2535 uint64_t BitToSet = Mask & -
Mask;
2536 if (BitToTest & Src)
2549 case Intrinsic::x86_vcvtph2ps_128:
2550 case Intrinsic::x86_vcvtph2ps_256: {
2551 auto Arg = II->getArgOperand(0);
2552 auto ArgType = cast<VectorType>(
Arg->getType());
2553 auto RetType = cast<VectorType>(II->getType());
2554 unsigned ArgWidth = ArgType->getNumElements();
2555 unsigned RetWidth = RetType->getNumElements();
2556 assert(RetWidth <= ArgWidth &&
"Unexpected input/return vector widths");
2557 assert(ArgType->isIntOrIntVectorTy() &&
2558 ArgType->getScalarSizeInBits() == 16 &&
2559 "CVTPH2PS input type should be 16-bit integer vector");
2560 assert(RetType->getScalarType()->isFloatTy() &&
2561 "CVTPH2PS output type should be 32-bit float vector");
2564 if (isa<ConstantAggregateZero>(
Arg))
2567 if (isa<ConstantDataVector>(
Arg)) {
2568 auto VectorHalfAsShorts =
Arg;
2569 if (RetWidth < ArgWidth) {
2571 for (
unsigned i = 0; i != RetWidth; ++i)
2573 VectorHalfAsShorts = Builder.CreateShuffleVector(
2577 auto VectorHalfType =
2580 Builder.CreateBitCast(VectorHalfAsShorts, VectorHalfType);
2581 auto VectorFloats = Builder.CreateFPExt(VectorHalfs, RetType);
2582 return replaceInstUsesWith(*II, VectorFloats);
2586 if (
Value *V = SimplifyDemandedVectorEltsLow(
Arg, ArgWidth, RetWidth)) {
2587 II->setArgOperand(0, V);
2593 case Intrinsic::x86_sse_cvtss2si:
2594 case Intrinsic::x86_sse_cvtss2si64:
2595 case Intrinsic::x86_sse_cvttss2si:
2596 case Intrinsic::x86_sse_cvttss2si64:
2597 case Intrinsic::x86_sse2_cvtsd2si:
2598 case Intrinsic::x86_sse2_cvtsd2si64:
2599 case Intrinsic::x86_sse2_cvttsd2si:
2600 case Intrinsic::x86_sse2_cvttsd2si64:
2601 case Intrinsic::x86_avx512_vcvtss2si32:
2602 case Intrinsic::x86_avx512_vcvtss2si64:
2603 case Intrinsic::x86_avx512_vcvtss2usi32:
2604 case Intrinsic::x86_avx512_vcvtss2usi64:
2605 case Intrinsic::x86_avx512_vcvtsd2si32:
2606 case Intrinsic::x86_avx512_vcvtsd2si64:
2607 case Intrinsic::x86_avx512_vcvtsd2usi32:
2608 case Intrinsic::x86_avx512_vcvtsd2usi64:
2609 case Intrinsic::x86_avx512_cvttss2si:
2610 case Intrinsic::x86_avx512_cvttss2si64:
2611 case Intrinsic::x86_avx512_cvttss2usi:
2612 case Intrinsic::x86_avx512_cvttss2usi64:
2613 case Intrinsic::x86_avx512_cvttsd2si:
2614 case Intrinsic::x86_avx512_cvttsd2si64:
2615 case Intrinsic::x86_avx512_cvttsd2usi:
2616 case Intrinsic::x86_avx512_cvttsd2usi64: {
2621 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg, VWidth, 1)) {
2622 II->setArgOperand(0, V);
2628 case Intrinsic::x86_mmx_pmovmskb:
2629 case Intrinsic::x86_sse_movmsk_ps:
2630 case Intrinsic::x86_sse2_movmsk_pd:
2631 case Intrinsic::x86_sse2_pmovmskb_128:
2632 case Intrinsic::x86_avx_movmsk_pd_256:
2633 case Intrinsic::x86_avx_movmsk_ps_256:
2634 case Intrinsic::x86_avx2_pmovmskb:
2636 return replaceInstUsesWith(*II, V);
2639 case Intrinsic::x86_sse_comieq_ss:
2640 case Intrinsic::x86_sse_comige_ss:
2641 case Intrinsic::x86_sse_comigt_ss:
2642 case Intrinsic::x86_sse_comile_ss:
2643 case Intrinsic::x86_sse_comilt_ss:
2644 case Intrinsic::x86_sse_comineq_ss:
2645 case Intrinsic::x86_sse_ucomieq_ss:
2646 case Intrinsic::x86_sse_ucomige_ss:
2647 case Intrinsic::x86_sse_ucomigt_ss:
2648 case Intrinsic::x86_sse_ucomile_ss:
2649 case Intrinsic::x86_sse_ucomilt_ss:
2650 case Intrinsic::x86_sse_ucomineq_ss:
2651 case Intrinsic::x86_sse2_comieq_sd:
2652 case Intrinsic::x86_sse2_comige_sd:
2653 case Intrinsic::x86_sse2_comigt_sd:
2654 case Intrinsic::x86_sse2_comile_sd:
2655 case Intrinsic::x86_sse2_comilt_sd:
2656 case Intrinsic::x86_sse2_comineq_sd:
2657 case Intrinsic::x86_sse2_ucomieq_sd:
2658 case Intrinsic::x86_sse2_ucomige_sd:
2659 case Intrinsic::x86_sse2_ucomigt_sd:
2660 case Intrinsic::x86_sse2_ucomile_sd:
2661 case Intrinsic::x86_sse2_ucomilt_sd:
2662 case Intrinsic::x86_sse2_ucomineq_sd:
2663 case Intrinsic::x86_avx512_vcomi_ss:
2664 case Intrinsic::x86_avx512_vcomi_sd:
2665 case Intrinsic::x86_avx512_mask_cmp_ss:
2666 case Intrinsic::x86_avx512_mask_cmp_sd: {
2669 bool MadeChange =
false;
2670 Value *Arg0 = II->getArgOperand(0);
2671 Value *Arg1 = II->getArgOperand(1);
2673 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg0, VWidth, 1)) {
2674 II->setArgOperand(0, V);
2677 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, 1)) {
2678 II->setArgOperand(1, V);
2685 case Intrinsic::x86_avx512_cmp_pd_128:
2686 case Intrinsic::x86_avx512_cmp_pd_256:
2687 case Intrinsic::x86_avx512_cmp_pd_512:
2688 case Intrinsic::x86_avx512_cmp_ps_128:
2689 case Intrinsic::x86_avx512_cmp_ps_256:
2690 case Intrinsic::x86_avx512_cmp_ps_512: {
2692 Value *Arg0 = II->getArgOperand(0);
2693 Value *Arg1 = II->getArgOperand(1);
2707 cast<Instruction>(Arg0)->getFastMathFlags().noInfs())) {
2710 II->setArgOperand(0, A);
2711 II->setArgOperand(1, B);
2717 case Intrinsic::x86_avx512_add_ps_512:
2718 case Intrinsic::x86_avx512_div_ps_512:
2719 case Intrinsic::x86_avx512_mul_ps_512:
2720 case Intrinsic::x86_avx512_sub_ps_512:
2721 case Intrinsic::x86_avx512_add_pd_512:
2722 case Intrinsic::x86_avx512_div_pd_512:
2723 case Intrinsic::x86_avx512_mul_pd_512:
2724 case Intrinsic::x86_avx512_sub_pd_512:
2727 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
2728 if (R->getValue() == 4) {
2729 Value *Arg0 = II->getArgOperand(0);
2730 Value *Arg1 = II->getArgOperand(1);
2735 case Intrinsic::x86_avx512_add_ps_512:
2736 case Intrinsic::x86_avx512_add_pd_512:
2737 V = Builder.CreateFAdd(Arg0, Arg1);
2739 case Intrinsic::x86_avx512_sub_ps_512:
2740 case Intrinsic::x86_avx512_sub_pd_512:
2741 V = Builder.CreateFSub(Arg0, Arg1);
2743 case Intrinsic::x86_avx512_mul_ps_512:
2744 case Intrinsic::x86_avx512_mul_pd_512:
2745 V = Builder.CreateFMul(Arg0, Arg1);
2747 case Intrinsic::x86_avx512_div_ps_512:
2748 case Intrinsic::x86_avx512_div_pd_512:
2749 V = Builder.CreateFDiv(Arg0, Arg1);
2753 return replaceInstUsesWith(*II, V);
2758 case Intrinsic::x86_avx512_mask_add_ss_round:
2759 case Intrinsic::x86_avx512_mask_div_ss_round:
2760 case Intrinsic::x86_avx512_mask_mul_ss_round:
2761 case Intrinsic::x86_avx512_mask_sub_ss_round:
2762 case Intrinsic::x86_avx512_mask_add_sd_round:
2763 case Intrinsic::x86_avx512_mask_div_sd_round:
2764 case Intrinsic::x86_avx512_mask_mul_sd_round:
2765 case Intrinsic::x86_avx512_mask_sub_sd_round:
2768 if (
auto *R = dyn_cast<ConstantInt>(II->getArgOperand(4))) {
2769 if (R->getValue() == 4) {
2771 Value *Arg0 = II->getArgOperand(0);
2772 Value *Arg1 = II->getArgOperand(1);
2773 Value *LHS = Builder.CreateExtractElement(Arg0, (uint64_t)0);
2774 Value *RHS = Builder.CreateExtractElement(Arg1, (uint64_t)0);
2779 case Intrinsic::x86_avx512_mask_add_ss_round:
2780 case Intrinsic::x86_avx512_mask_add_sd_round:
2781 V = Builder.CreateFAdd(LHS, RHS);
2783 case Intrinsic::x86_avx512_mask_sub_ss_round:
2784 case Intrinsic::x86_avx512_mask_sub_sd_round:
2785 V = Builder.CreateFSub(LHS, RHS);
2787 case Intrinsic::x86_avx512_mask_mul_ss_round:
2788 case Intrinsic::x86_avx512_mask_mul_sd_round:
2789 V = Builder.CreateFMul(LHS, RHS);
2791 case Intrinsic::x86_avx512_mask_div_ss_round:
2792 case Intrinsic::x86_avx512_mask_div_sd_round:
2793 V = Builder.CreateFDiv(LHS, RHS);
2801 if (!
C || !
C->getValue()[0]) {
2805 Mask = Builder.CreateBitCast(Mask, MaskTy);
2806 Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
2808 Value *Passthru = Builder.CreateExtractElement(II->getArgOperand(2),
2810 V = Builder.CreateSelect(Mask, V, Passthru);
2814 V = Builder.CreateInsertElement(Arg0, V, (uint64_t)0);
2816 return replaceInstUsesWith(*II, V);
2824 case Intrinsic::x86_sse2_psrai_d:
2825 case Intrinsic::x86_sse2_psrai_w:
2826 case Intrinsic::x86_avx2_psrai_d:
2827 case Intrinsic::x86_avx2_psrai_w:
2828 case Intrinsic::x86_avx512_psrai_q_128:
2829 case Intrinsic::x86_avx512_psrai_q_256:
2830 case Intrinsic::x86_avx512_psrai_d_512:
2831 case Intrinsic::x86_avx512_psrai_q_512:
2832 case Intrinsic::x86_avx512_psrai_w_512:
2833 case Intrinsic::x86_sse2_psrli_d:
2834 case Intrinsic::x86_sse2_psrli_q:
2835 case Intrinsic::x86_sse2_psrli_w:
2836 case Intrinsic::x86_avx2_psrli_d:
2837 case Intrinsic::x86_avx2_psrli_q:
2838 case Intrinsic::x86_avx2_psrli_w:
2839 case Intrinsic::x86_avx512_psrli_d_512:
2840 case Intrinsic::x86_avx512_psrli_q_512:
2841 case Intrinsic::x86_avx512_psrli_w_512:
2842 case Intrinsic::x86_sse2_pslli_d:
2843 case Intrinsic::x86_sse2_pslli_q:
2844 case Intrinsic::x86_sse2_pslli_w:
2845 case Intrinsic::x86_avx2_pslli_d:
2846 case Intrinsic::x86_avx2_pslli_q:
2847 case Intrinsic::x86_avx2_pslli_w:
2848 case Intrinsic::x86_avx512_pslli_d_512:
2849 case Intrinsic::x86_avx512_pslli_q_512:
2850 case Intrinsic::x86_avx512_pslli_w_512:
2852 return replaceInstUsesWith(*II, V);
2855 case Intrinsic::x86_sse2_psra_d:
2856 case Intrinsic::x86_sse2_psra_w:
2857 case Intrinsic::x86_avx2_psra_d:
2858 case Intrinsic::x86_avx2_psra_w:
2859 case Intrinsic::x86_avx512_psra_q_128:
2860 case Intrinsic::x86_avx512_psra_q_256:
2861 case Intrinsic::x86_avx512_psra_d_512:
2862 case Intrinsic::x86_avx512_psra_q_512:
2863 case Intrinsic::x86_avx512_psra_w_512:
2864 case Intrinsic::x86_sse2_psrl_d:
2865 case Intrinsic::x86_sse2_psrl_q:
2866 case Intrinsic::x86_sse2_psrl_w:
2867 case Intrinsic::x86_avx2_psrl_d:
2868 case Intrinsic::x86_avx2_psrl_q:
2869 case Intrinsic::x86_avx2_psrl_w:
2870 case Intrinsic::x86_avx512_psrl_d_512:
2871 case Intrinsic::x86_avx512_psrl_q_512:
2872 case Intrinsic::x86_avx512_psrl_w_512:
2873 case Intrinsic::x86_sse2_psll_d:
2874 case Intrinsic::x86_sse2_psll_q:
2875 case Intrinsic::x86_sse2_psll_w:
2876 case Intrinsic::x86_avx2_psll_d:
2877 case Intrinsic::x86_avx2_psll_q:
2878 case Intrinsic::x86_avx2_psll_w:
2879 case Intrinsic::x86_avx512_psll_d_512:
2880 case Intrinsic::x86_avx512_psll_q_512:
2881 case Intrinsic::x86_avx512_psll_w_512: {
2883 return replaceInstUsesWith(*II, V);
2887 Value *Arg1 = II->getArgOperand(1);
2889 "Unexpected packed shift size");
2892 if (
Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, VWidth / 2)) {
2893 II->setArgOperand(1, V);
2899 case Intrinsic::x86_avx2_psllv_d:
2900 case Intrinsic::x86_avx2_psllv_d_256:
2901 case Intrinsic::x86_avx2_psllv_q:
2902 case Intrinsic::x86_avx2_psllv_q_256:
2903 case Intrinsic::x86_avx512_psllv_d_512:
2904 case Intrinsic::x86_avx512_psllv_q_512:
2905 case Intrinsic::x86_avx512_psllv_w_128:
2906 case Intrinsic::x86_avx512_psllv_w_256:
2907 case Intrinsic::x86_avx512_psllv_w_512:
2908 case Intrinsic::x86_avx2_psrav_d:
2909 case Intrinsic::x86_avx2_psrav_d_256:
2910 case Intrinsic::x86_avx512_psrav_q_128:
2911 case Intrinsic::x86_avx512_psrav_q_256:
2912 case Intrinsic::x86_avx512_psrav_d_512:
2913 case Intrinsic::x86_avx512_psrav_q_512:
2914 case Intrinsic::x86_avx512_psrav_w_128:
2915 case Intrinsic::x86_avx512_psrav_w_256:
2916 case Intrinsic::x86_avx512_psrav_w_512:
2917 case Intrinsic::x86_avx2_psrlv_d:
2918 case Intrinsic::x86_avx2_psrlv_d_256:
2919 case Intrinsic::x86_avx2_psrlv_q:
2920 case Intrinsic::x86_avx2_psrlv_q_256:
2921 case Intrinsic::x86_avx512_psrlv_d_512:
2922 case Intrinsic::x86_avx512_psrlv_q_512:
2923 case Intrinsic::x86_avx512_psrlv_w_128:
2924 case Intrinsic::x86_avx512_psrlv_w_256:
2925 case Intrinsic::x86_avx512_psrlv_w_512:
2927 return replaceInstUsesWith(*II, V);
2930 case Intrinsic::x86_sse2_packssdw_128:
2931 case Intrinsic::x86_sse2_packsswb_128:
2932 case Intrinsic::x86_avx2_packssdw:
2933 case Intrinsic::x86_avx2_packsswb:
2934 case Intrinsic::x86_avx512_packssdw_512:
2935 case Intrinsic::x86_avx512_packsswb_512:
2937 return replaceInstUsesWith(*II, V);
2940 case Intrinsic::x86_sse2_packuswb_128:
2941 case Intrinsic::x86_sse41_packusdw:
2942 case Intrinsic::x86_avx2_packusdw:
2943 case Intrinsic::x86_avx2_packuswb:
2944 case Intrinsic::x86_avx512_packusdw_512:
2945 case Intrinsic::x86_avx512_packuswb_512:
2947 return replaceInstUsesWith(*II, V);
2950 case Intrinsic::x86_pclmulqdq:
2951 case Intrinsic::x86_pclmulqdq_256:
2952 case Intrinsic::x86_pclmulqdq_512: {
2953 if (
auto *
C = dyn_cast<ConstantInt>(II->getArgOperand(2))) {
2954 unsigned Imm =
C->getZExtValue();
2956 bool MadeChange =
false;
2957 Value *Arg0 = II->getArgOperand(0);
2958 Value *Arg1 = II->getArgOperand(1);
2961 APInt UndefElts1(VWidth, 0);
2963 APInt(2, (Imm & 0x01) ? 2 : 1));
2964 if (
Value *V = SimplifyDemandedVectorElts(Arg0, DemandedElts1,
2966 II->setArgOperand(0, V);
2970 APInt UndefElts2(VWidth, 0);
2972 APInt(2, (Imm & 0x10) ? 2 : 1));
2973 if (
Value *V = SimplifyDemandedVectorElts(Arg1, DemandedElts2,
2975 II->setArgOperand(1, V);
2982 return replaceInstUsesWith(*II,
2991 case Intrinsic::x86_sse41_insertps:
2993 return replaceInstUsesWith(*II, V);
2996 case Intrinsic::x86_sse4a_extrq: {
2997 Value *Op0 = II->getArgOperand(0);
2998 Value *Op1 = II->getArgOperand(1);
3003 VWidth1 == 16 &&
"Unexpected operand sizes");
3008 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)0))
3011 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
3016 return replaceInstUsesWith(*II, V);
3020 bool MadeChange =
false;
3021 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
3022 II->setArgOperand(0, V);
3025 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 2)) {
3026 II->setArgOperand(1, V);
3034 case Intrinsic::x86_sse4a_extrqi: {
3037 Value *Op0 = II->getArgOperand(0);
3040 "Unexpected operand size");
3048 return replaceInstUsesWith(*II, V);
3052 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
3053 II->setArgOperand(0, V);
3059 case Intrinsic::x86_sse4a_insertq: {
3060 Value *Op0 = II->getArgOperand(0);
3061 Value *Op1 = II->getArgOperand(1);
3066 "Unexpected operand size");
3071 C1 ? dyn_cast_or_null<ConstantInt>(C1->getAggregateElement((
unsigned)1))
3076 const APInt &V11 = CI11->getValue();
3080 return replaceInstUsesWith(*II, V);
3085 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
3086 II->setArgOperand(0, V);
3092 case Intrinsic::x86_sse4a_insertqi: {
3096 Value *Op0 = II->getArgOperand(0);
3097 Value *Op1 = II->getArgOperand(1);
3102 VWidth1 == 2 &&
"Unexpected operand sizes");
3109 if (CILength && CIIndex) {
3113 return replaceInstUsesWith(*II, V);
3118 bool MadeChange =
false;
3119 if (
Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
3120 II->setArgOperand(0, V);
3123 if (
Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 1)) {
3124 II->setArgOperand(1, V);
3132 case Intrinsic::x86_sse41_pblendvb:
3133 case Intrinsic::x86_sse41_blendvps:
3134 case Intrinsic::x86_sse41_blendvpd:
3135 case Intrinsic::x86_avx_blendv_ps_256:
3136 case Intrinsic::x86_avx_blendv_pd_256:
3137 case Intrinsic::x86_avx2_pblendvb: {
3139 Value *Op0 = II->getArgOperand(0);
3140 Value *Op1 = II->getArgOperand(1);
3143 return replaceInstUsesWith(CI, Op0);
3146 if (isa<ConstantAggregateZero>(Mask))
3147 return replaceInstUsesWith(CI, Op0);
3150 if (
auto *ConstantMask = dyn_cast<ConstantDataVector>(Mask)) {
3163 II->getType()->getPrimitiveSizeInBits() &&
3164 "Not expecting mask and operands with different sizes");
3167 unsigned NumOperandElts = II->getType()->getVectorNumElements();
3168 if (NumMaskElts == NumOperandElts)
3173 if (NumMaskElts < NumOperandElts) {
3174 Value *CastOp0 = Builder.CreateBitCast(Op0, Mask->
getType());
3175 Value *CastOp1 = Builder.CreateBitCast(Op1, Mask->
getType());
3176 Value *Sel = Builder.CreateSelect(BoolVec, CastOp1, CastOp0);
3184 case Intrinsic::x86_ssse3_pshuf_b_128:
3185 case Intrinsic::x86_avx2_pshuf_b:
3186 case Intrinsic::x86_avx512_pshuf_b_512:
3188 return replaceInstUsesWith(*II, V);
3191 case Intrinsic::x86_avx_vpermilvar_ps:
3192 case Intrinsic::x86_avx_vpermilvar_ps_256:
3193 case Intrinsic::x86_avx512_vpermilvar_ps_512:
3194 case Intrinsic::x86_avx_vpermilvar_pd:
3195 case Intrinsic::x86_avx_vpermilvar_pd_256:
3196 case Intrinsic::x86_avx512_vpermilvar_pd_512:
3198 return replaceInstUsesWith(*II, V);
3201 case Intrinsic::x86_avx2_permd:
3202 case Intrinsic::x86_avx2_permps:
3203 case Intrinsic::x86_avx512_permvar_df_256:
3204 case Intrinsic::x86_avx512_permvar_df_512:
3205 case Intrinsic::x86_avx512_permvar_di_256:
3206 case Intrinsic::x86_avx512_permvar_di_512:
3207 case Intrinsic::x86_avx512_permvar_hi_128:
3208 case Intrinsic::x86_avx512_permvar_hi_256:
3209 case Intrinsic::x86_avx512_permvar_hi_512:
3210 case Intrinsic::x86_avx512_permvar_qi_128:
3211 case Intrinsic::x86_avx512_permvar_qi_256:
3212 case Intrinsic::x86_avx512_permvar_qi_512:
3213 case Intrinsic::x86_avx512_permvar_sf_512:
3214 case Intrinsic::x86_avx512_permvar_si_512:
3216 return replaceInstUsesWith(*II, V);
3219 case Intrinsic::x86_avx_maskload_ps:
3220 case Intrinsic::x86_avx_maskload_pd:
3221 case Intrinsic::x86_avx_maskload_ps_256:
3222 case Intrinsic::x86_avx_maskload_pd_256:
3223 case Intrinsic::x86_avx2_maskload_d:
3224 case Intrinsic::x86_avx2_maskload_q:
3225 case Intrinsic::x86_avx2_maskload_d_256:
3226 case Intrinsic::x86_avx2_maskload_q_256:
3231 case Intrinsic::x86_sse2_maskmov_dqu:
3232 case Intrinsic::x86_avx_maskstore_ps:
3233 case Intrinsic::x86_avx_maskstore_pd:
3234 case Intrinsic::x86_avx_maskstore_ps_256:
3235 case Intrinsic::x86_avx_maskstore_pd_256:
3236 case Intrinsic::x86_avx2_maskstore_d:
3237 case Intrinsic::x86_avx2_maskstore_q:
3238 case Intrinsic::x86_avx2_maskstore_d_256:
3239 case Intrinsic::x86_avx2_maskstore_q_256:
3244 case Intrinsic::x86_addcarry_32:
3245 case Intrinsic::x86_addcarry_64:
3247 return replaceInstUsesWith(*II, V);
3250 case Intrinsic::ppc_altivec_vperm:
3257 if (
Constant *
Mask = dyn_cast<Constant>(II->getArgOperand(2))) {
3258 assert(
Mask->getType()->getVectorNumElements() == 16 &&
3259 "Bad type for intrinsic!");
3262 bool AllEltsOk =
true;
3263 for (
unsigned i = 0; i != 16; ++i) {
3265 if (!Elt || !(isa<ConstantInt>(Elt) || isa<UndefValue>(Elt))) {
3273 Value *Op0 = Builder.CreateBitCast(II->getArgOperand(0),
3275 Value *Op1 = Builder.CreateBitCast(II->getArgOperand(1),
3280 Value *ExtractedElts[32];
3281 memset(ExtractedElts, 0,
sizeof(ExtractedElts));
3283 for (
unsigned i = 0; i != 16; ++i) {
3284 if (isa<UndefValue>(
Mask->getAggregateElement(i)))
3287 cast<ConstantInt>(
Mask->getAggregateElement(i))->getZExtValue();
3289 if (DL.isLittleEndian())
3292 if (!ExtractedElts[Idx]) {
3293 Value *Op0ToUse = (DL.isLittleEndian()) ? Op1 : Op0;
3294 Value *Op1ToUse = (DL.isLittleEndian()) ? Op0 : Op1;
3295 ExtractedElts[Idx] =
3296 Builder.CreateExtractElement(Idx < 16 ? Op0ToUse : Op1ToUse,
3297 Builder.getInt32(Idx&15));
3301 Result = Builder.CreateInsertElement(Result, ExtractedElts[Idx],
3302 Builder.getInt32(i));
3309 case Intrinsic::arm_neon_vld1: {
3313 return replaceInstUsesWith(*II, V);
3317 case Intrinsic::arm_neon_vld2:
3318 case Intrinsic::arm_neon_vld3:
3319 case Intrinsic::arm_neon_vld4:
3320 case Intrinsic::arm_neon_vld2lane:
3321 case Intrinsic::arm_neon_vld3lane:
3322 case Intrinsic::arm_neon_vld4lane:
3323 case Intrinsic::arm_neon_vst1:
3324 case Intrinsic::arm_neon_vst2:
3325 case Intrinsic::arm_neon_vst3:
3326 case Intrinsic::arm_neon_vst4:
3327 case Intrinsic::arm_neon_vst2lane:
3328 case Intrinsic::arm_neon_vst3lane:
3329 case Intrinsic::arm_neon_vst4lane: {
3332 unsigned AlignArg = II->getNumArgOperands() - 1;
3334 if (IntrAlign && IntrAlign->
getZExtValue() < MemAlign) {
3335 II->setArgOperand(AlignArg,
3343 case Intrinsic::arm_neon_vtbl1:
3344 case Intrinsic::aarch64_neon_tbl1:
3346 return replaceInstUsesWith(*II, V);
3349 case Intrinsic::arm_neon_vmulls:
3350 case Intrinsic::arm_neon_vmullu:
3351 case Intrinsic::aarch64_neon_smull:
3352 case Intrinsic::aarch64_neon_umull: {
3353 Value *Arg0 = II->getArgOperand(0);
3354 Value *Arg1 = II->getArgOperand(1);
3357 if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
3362 bool Zext = (IID == Intrinsic::arm_neon_vmullu ||
3363 IID == Intrinsic::aarch64_neon_umull);
3364 VectorType *NewVT = cast<VectorType>(II->getType());
3365 if (
Constant *CV0 = dyn_cast<Constant>(Arg0)) {
3366 if (
Constant *CV1 = dyn_cast<Constant>(Arg1)) {
3378 if (
Constant *CV1 = dyn_cast<Constant>(Arg1))
3380 dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
3387 case Intrinsic::arm_neon_aesd:
3388 case Intrinsic::arm_neon_aese:
3389 case Intrinsic::aarch64_crypto_aesd:
3390 case Intrinsic::aarch64_crypto_aese: {
3391 Value *DataArg = II->getArgOperand(0);
3392 Value *KeyArg = II->getArgOperand(1);
3398 II->setArgOperand(0, Data);
3399 II->setArgOperand(1, Key);
3404 case Intrinsic::arm_mve_pred_i2v: {
3407 if (
match(Arg, m_Intrinsic<Intrinsic::arm_mve_pred_v2i>(
m_Value(ArgArg))) &&
3408 II->getType() == ArgArg->
getType())
3409 return replaceInstUsesWith(*II, ArgArg);
3412 m_Xor(m_Intrinsic<Intrinsic::arm_mve_pred_v2i>(
m_Value(ArgArg)),
3414 II->getType() == ArgArg->
getType()) {
3415 if (
auto *CI = dyn_cast<ConstantInt>(XorMask)) {
3416 if (CI->getValue().trunc(16).isAllOnesValue()) {
3417 auto TrueVector = Builder.CreateVectorSplat(
3418 II->getType()->getVectorNumElements(), Builder.getTrue());
3429 case Intrinsic::arm_mve_pred_v2i: {
3432 if (
match(Arg, m_Intrinsic<Intrinsic::arm_mve_pred_i2v>(
m_Value(ArgArg))))
3433 return replaceInstUsesWith(*II, ArgArg);
3434 if (!II->getMetadata(LLVMContext::MD_range)) {
3440 II->setMetadata(LLVMContext::MD_range,
MDNode::get(II->getContext(), M));
3445 case Intrinsic::arm_mve_vadc:
3446 case Intrinsic::arm_mve_vadc_predicated: {
3448 (II->getIntrinsicID() == Intrinsic::arm_mve_vadc_predicated) ? 3 : 2;
3449 assert(II->getArgOperand(CarryOp)->getType()->getScalarSizeInBits() == 32 &&
3450 "Bad type for intrinsic!");
3458 case Intrinsic::amdgcn_rcp: {
3459 Value *Src = II->getArgOperand(0);
3462 if (isa<UndefValue>(Src))
3463 return replaceInstUsesWith(CI, Src);
3465 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3466 const APFloat &ArgVal =
C->getValueAPF();
3473 return replaceInstUsesWith(CI,
ConstantFP::get(II->getContext(), Val));
3478 case Intrinsic::amdgcn_rsq: {
3479 Value *Src = II->getArgOperand(0);
3482 if (isa<UndefValue>(Src))
3483 return replaceInstUsesWith(CI, Src);
3486 case Intrinsic::amdgcn_frexp_mant:
3487 case Intrinsic::amdgcn_frexp_exp: {
3488 Value *Src = II->getArgOperand(0);
3489 if (
const ConstantFP *
C = dyn_cast<ConstantFP>(Src)) {
3494 if (IID == Intrinsic::amdgcn_frexp_mant) {
3506 if (isa<UndefValue>(Src))
3511 case Intrinsic::amdgcn_class: {
3528 Value *Src0 = II->getArgOperand(0);
3529 Value *Src1 = II->getArgOperand(1);
3532 if (isa<UndefValue>(Src0))
3535 if (isa<UndefValue>(Src1))
3543 if ((Mask & FullMask) == FullMask)
3546 if ((Mask & FullMask) == 0)
3551 Value *FCmp = Builder.CreateFCmpUNO(Src0, Src0);
3553 return replaceInstUsesWith(*II, FCmp);
3558 Value *FCmp = Builder.CreateFCmpOEQ(
3562 return replaceInstUsesWith(*II, FCmp);
3568 Mask & ~(S_NAN |
Q_NAN)));
3574 if (isa<UndefValue>(Src0))
3578 if ((Mask & FullMask) !=
Mask) {
3579 CallInst *NewCall = Builder.CreateCall(II->getCalledFunction(),
3584 return replaceInstUsesWith(*II, NewCall);
3606 case Intrinsic::amdgcn_cvt_pkrtz: {
3607 Value *Src0 = II->getArgOperand(0);
3608 Value *Src1 = II->getArgOperand(1);
3609 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3610 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3612 = II->getType()->getScalarType()->getFltSemantics();
3614 APFloat Val0 = C0->getValueAPF();
3615 APFloat Val1 = C1->getValueAPF();
3622 return replaceInstUsesWith(*II, Folded);
3626 if (isa<UndefValue>(Src0) && isa<UndefValue>(Src1))
3631 case Intrinsic::amdgcn_cvt_pknorm_i16:
3632 case Intrinsic::amdgcn_cvt_pknorm_u16:
3633 case Intrinsic::amdgcn_cvt_pk_i16:
3634 case Intrinsic::amdgcn_cvt_pk_u16: {
3635 Value *Src0 = II->getArgOperand(0);
3636 Value *Src1 = II->getArgOperand(1);
3638 if (isa<UndefValue>(Src0) && isa<UndefValue>(Src1))
3643 case Intrinsic::amdgcn_ubfe:
3644 case Intrinsic::amdgcn_sbfe: {
3646 Value *Src = II->getArgOperand(0);
3647 if (isa<UndefValue>(Src))
3648 return replaceInstUsesWith(*II, Src);
3651 Type *Ty = II->getType();
3657 if ((Width & (IntSize - 1)) == 0)
3660 if (Width >= IntSize) {
3663 Width & (IntSize - 1)));
3672 if (Offset >= IntSize) {
3674 Offset & (IntSize - 1)));
3679 bool Signed = IID == Intrinsic::amdgcn_sbfe;
3681 if (!CWidth || !COffset)
3691 if (Offset + Width < IntSize) {
3692 Value *Shl = Builder.CreateShl(Src, IntSize - Offset - Width);
3693 Value *RightShift = Signed ? Builder.CreateAShr(Shl, IntSize - Width)
3694 : Builder.CreateLShr(Shl, IntSize - Width);
3696 return replaceInstUsesWith(*II, RightShift);
3699 Value *RightShift = Signed ? Builder.CreateAShr(Src, Offset)
3700 : Builder.CreateLShr(Src, Offset);
3703 return replaceInstUsesWith(*II, RightShift);
3705 case Intrinsic::amdgcn_exp:
3706 case Intrinsic::amdgcn_exp_compr: {
3707 ConstantInt *En = cast<ConstantInt>(II->getArgOperand(1));
3712 bool IsCompr = IID == Intrinsic::amdgcn_exp_compr;
3713 bool Changed =
false;
3714 for (
int I = 0;
I < (IsCompr ? 2 : 4); ++
I) {
3715 if ((!IsCompr && (EnBits & (1 <<
I)) == 0) ||
3716 (IsCompr && ((EnBits & (0x3 << (2 *
I))) == 0))) {
3717 Value *Src = II->getArgOperand(
I + 2);
3718 if (!isa<UndefValue>(Src)) {
3730 case Intrinsic::amdgcn_fmed3: {
3734 Value *Src0 = II->getArgOperand(0);
3735 Value *Src1 = II->getArgOperand(1);
3736 Value *Src2 = II->getArgOperand(2);
3742 if (
match(Src0,
m_NaN()) || isa<UndefValue>(Src0)) {
3743 NewCall = Builder.CreateMinNum(Src1, Src2);
3744 }
else if (
match(Src1,
m_NaN()) || isa<UndefValue>(Src1)) {
3745 NewCall = Builder.CreateMinNum(Src0, Src2);
3746 }
else if (
match(Src2,
m_NaN()) || isa<UndefValue>(Src2)) {
3747 NewCall = Builder.CreateMaxNum(Src0, Src1);
3753 return replaceInstUsesWith(*II, NewCall);
3760 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3765 if (isa<Constant>(Src1) && !isa<Constant>(Src2)) {
3770 if (isa<Constant>(Src0) && !isa<Constant>(Src1)) {
3776 II->setArgOperand(0, Src0);
3777 II->setArgOperand(1, Src1);
3778 II->setArgOperand(2, Src2);
3782 if (
const ConstantFP *C0 = dyn_cast<ConstantFP>(Src0)) {
3783 if (
const ConstantFP *C1 = dyn_cast<ConstantFP>(Src1)) {
3784 if (
const ConstantFP *C2 = dyn_cast<ConstantFP>(Src2)) {
3787 return replaceInstUsesWith(*II,
3795 case Intrinsic::amdgcn_icmp:
3796 case Intrinsic::amdgcn_fcmp: {
3797 const ConstantInt *CC = cast<ConstantInt>(II->getArgOperand(2));
3800 bool IsInteger = IID == Intrinsic::amdgcn_icmp;
3807 Value *Src0 = II->getArgOperand(0);
3808 Value *Src1 = II->getArgOperand(1);
3810 if (
auto *CSrc0 = dyn_cast<Constant>(Src0)) {
3811 if (
auto *CSrc1 = dyn_cast<Constant>(Src1)) {
3814 return replaceInstUsesWith(
3824 II->getModule(), Intrinsic::read_register, II->getType());
3828 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3831 NewCall->takeName(II);
3832 return replaceInstUsesWith(*II, NewCall);
3838 II->setArgOperand(0, Src1);
3839 II->setArgOperand(1, Src0);
3841 static_cast<int>(SwapPred)));
3884 Intrinsic::amdgcn_fcmp : Intrinsic::amdgcn_icmp;
3887 if (
auto *CmpType = dyn_cast<IntegerType>(Ty)) {
3889 unsigned Width = CmpType->getBitWidth();
3890 unsigned NewWidth =
Width;
3898 else if (Width <= 32)
3900 else if (Width <= 64)
3902 else if (Width > 64)
3905 if (Width != NewWidth) {
3908 SrcLHS = Builder.CreateSExt(SrcLHS, CmpTy);
3909 SrcRHS = Builder.CreateSExt(SrcRHS, CmpTy);
3911 SrcLHS = Builder.CreateZExt(SrcLHS, CmpTy);
3912 SrcRHS = Builder.CreateZExt(SrcRHS, CmpTy);
3924 CallInst *NewCall = Builder.CreateCall(NewF, Args);
3926 return replaceInstUsesWith(*II, NewCall);
3931 case Intrinsic::amdgcn_wqm_vote: {
3933 if (!isa<Constant>(II->getArgOperand(0)))
3936 return replaceInstUsesWith(*II, II->getArgOperand(0));
3938 case Intrinsic::amdgcn_kill: {
3944 return eraseInstFromFunction(CI);
3946 case Intrinsic::amdgcn_update_dpp: {
3947 Value *Old = II->getArgOperand(0);
3949 auto BC = cast<ConstantInt>(II->getArgOperand(5));
3950 auto RM = cast<ConstantInt>(II->getArgOperand(3));
3951 auto BM = cast<ConstantInt>(II->getArgOperand(4));
3952 if (BC->isZeroValue() ||
3953 RM->getZExtValue() != 0xF ||
3954 BM->getZExtValue() != 0xF ||
3955 isa<UndefValue>(Old))
3962 case Intrinsic::amdgcn_readfirstlane:
3963 case Intrinsic::amdgcn_readlane: {
3965 if (
Constant *
C = dyn_cast<Constant>(II->getArgOperand(0)))
3966 return replaceInstUsesWith(*II,
C);
3970 Value *Src = II->getArgOperand(0);
3977 if (
match(Src, m_Intrinsic<Intrinsic::amdgcn_readfirstlane>()))
3978 return replaceInstUsesWith(*II, Src);
3980 if (IID == Intrinsic::amdgcn_readfirstlane) {
3982 if (
match(Src, m_Intrinsic<Intrinsic::amdgcn_readlane>()))
3983 return replaceInstUsesWith(*II, Src);
3986 if (
match(Src, m_Intrinsic<Intrinsic::amdgcn_readlane>(
3988 return replaceInstUsesWith(*II, Src);
3993 case Intrinsic::stackrestore: {
3996 if (
IntrinsicInst *
SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
3997 if (
SS->getIntrinsicID() == Intrinsic::stacksave) {
3999 if (
SS->getNextNonDebugInstruction() == II) {
4000 return eraseInstFromFunction(CI);
4009 bool CannotRemove =
false;
4010 for (++BI; &*BI != TI; ++BI) {
4011 if (isa<AllocaInst>(BI)) {
4012 CannotRemove =
true;
4015 if (
CallInst *BCI = dyn_cast<CallInst>(BI)) {
4016 if (
auto *II2 = dyn_cast<IntrinsicInst>(BCI)) {
4018 if (II2->getIntrinsicID() == Intrinsic::stackrestore)
4019 return eraseInstFromFunction(CI);
4023 if (II2->mayHaveSideEffects()) {
4024 CannotRemove =
true;
4030 CannotRemove =
true;
4039 if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI)))
4040 return eraseInstFromFunction(CI);
4043 case Intrinsic::lifetime_start:
4046 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
4047 II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
4048 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
4052 Intrinsic::lifetime_end, *
this))
4055 case Intrinsic::assume: {
4056 Value *IIOperand = II->getArgOperand(0);
4061 if (
match(Next, m_Intrinsic<Intrinsic::assume>(
m_Specific(IIOperand))))
4062 return eraseInstFromFunction(CI);
4067 FunctionType *AssumeIntrinsicTy = II->getFunctionType();
4068 Value *AssumeIntrinsic = II->getCalledValue();
4071 Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, A, II->
getName());
4072 Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, B, II->
getName());
4073 return eraseInstFromFunction(*II);
4077 Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
4078 Builder.CreateNot(A), II->
getName());
4079 Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic,
4080 Builder.CreateNot(B), II->
getName());
4081 return eraseInstFromFunction(*II);
4094 return eraseInstFromFunction(*II);
4105 return eraseInstFromFunction(*II);
4109 AC.updateAffectedValues(II);
4112 case Intrinsic::experimental_gc_relocate: {
4113 auto &GCR = *cast<GCRelocateInst>(II);
4117 if (GCR.getBasePtr() == GCR.getDerivedPtr() &&
4118 GCR.getBasePtrIndex() != GCR.getDerivedPtrIndex()) {
4119 auto *OpIntTy = GCR.getOperand(2)->getType();
4127 Value *DerivedPtr = GCR.getDerivedPtr();
4131 if (II->use_empty())
4132 return eraseInstFromFunction(*II);
4138 if (isa<UndefValue>(DerivedPtr))
4142 if (
auto *PT = dyn_cast<PointerType>(II->getType())) {
4146 if (isa<ConstantPointerNull>(DerivedPtr))
4151 if (!II->hasRetAttr(Attribute::NonNull) &&
4165 case Intrinsic::experimental_guard: {
4176 Value *NextCond =
nullptr;
4178 m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(NextCond)))) {
4179 Value *CurrCond = II->getArgOperand(0);
4183 if (CurrCond != NextCond) {
4185 while (MoveI != NextInst) {
4190 II->setArgOperand(0, Builder.CreateAnd(CurrCond, NextCond));
4192 eraseInstFromFunction(*NextInst);
4198 return visitCallBase(*II);
4205 if (
auto *NFI = dyn_cast<FenceInst>(Next))
4207 return eraseInstFromFunction(FI);
4213 return visitCallBase(II);
4218 return visitCallBase(CBI);
4248 : cast<PointerType>(CI->
getType())->getElementType();
4260 replaceInstUsesWith(*From, With);
4263 eraseInstFromFunction(*
I);
4269 return CI->
use_empty() ? CI : replaceInstUsesWith(*CI, With);
4279 if (Underlying != TrampMem &&
4282 if (!isa<AllocaInst>(Underlying))
4294 InitTrampoline = II;
4304 if (!InitTrampoline)
4308 if (InitTrampoline->
getOperand(0) != TrampMem)
4311 return InitTrampoline;
4355 (NumArgs == 1) ?
nullptr : dyn_cast<ConstantInt>(Call.
getOperand(1));
4357 if ((Op0C && Op0C->
isNullValue()) || (Op1C && Op1C->isNullValue()))
4390 else if (NumArgs == 2 && Op1C)
4394 Call.
getContext(), std::min(Len, Op1C->getZExtValue() + 1)));
4404 bool Changed =
false;
4413 if (V->getType()->isPointerTy() &&
4422 if (!ArgNos.
empty()) {
4434 if (!isa<Function>(Callee) && transformConstExprCastCall(Call))
4437 if (
Function *CalleeF = dyn_cast<Function>(Callee)) {
4440 !CalleeF->isIntrinsic()) {
4441 LLVM_DEBUG(
dbgs() <<
"Removing convergent attr from instr " << Call
4453 !CalleeF->isDeclaration()) {
4455 CreateNonTerminatorUnreachable(OldCall);
4460 if (isa<CallInst>(OldCall))
4461 return eraseInstFromFunction(*OldCall);
4465 cast<CallBase>(OldCall)->setCalledFunction(
4466 CalleeF->getFunctionType(),
4472 if ((isa<ConstantPointerNull>(Callee) &&
4474 isa<UndefValue>(Callee)) {
4486 CreateNonTerminatorUnreachable(&Call);
4487 return eraseInstFromFunction(Call);
4491 return transformCallThroughTrampoline(Call, *II);
4495 if (FTy->isVarArg()) {
4500 I !=
E; ++
I, ++ix) {
4527 if (
CallInst *CI = dyn_cast<CallInst>(&Call)) {
4531 if (I)
return eraseInstFromFunction(*I);
4535 return visitAllocSite(Call);
4537 return Changed ? &Call :
nullptr;
4542 bool InstCombiner::transformConstExprCastCall(
CallBase &Call) {
4550 if (
Callee->hasFnAttribute(
"thunk"))
4571 if (OldRetTy != NewRetTy) {
4577 if (
Callee->isDeclaration())
4597 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller))
4599 if (
PHINode *PN = dyn_cast<PHINode>(U))
4600 if (PN->getParent() == II->getNormalDest() ||
4604 if (isa<CallBrInst>(Caller))
4609 unsigned NumActualArgs = Call.
arg_size();
4610 unsigned NumCommonArgs = std::min(FT->
getNumParams(), NumActualArgs);
4620 if (
Callee->getAttributes().hasAttrSomewhere(Attribute::InAlloca) ||
4621 Callee->getAttributes().hasAttrSomewhere(Attribute::ByVal))
4625 for (
unsigned i = 0,
e = NumCommonArgs; i !=
e; ++i, ++AI) {
4627 Type *ActTy = (*AI)->getType();
4647 if (DL.getTypeAllocSize(CurElTy) !=
4653 if (
Callee->isDeclaration()) {
4691 ArgAttrs.
reserve(NumActualArgs);
4702 for (
unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
4705 Value *NewArg = *AI;
4706 if ((*AI)->getType() != ParamTy)
4707 NewArg = Builder.CreateBitOrPointerCast(*AI, ParamTy);
4721 for (
unsigned i = NumCommonArgs; i != FT->
getNumParams(); ++i) {
4731 for (
unsigned i = FT->
getNumParams(); i != NumActualArgs; ++i, ++AI) {
4733 Value *NewArg = *AI;
4734 if (PTy != (*AI)->getType()) {
4738 NewArg = Builder.CreateCast(opcode, *AI, PTy);
4754 "missing argument attributes");
4762 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4763 NewCall = Builder.CreateInvoke(
Callee, II->getNormalDest(),
4764 II->getUnwindDest(),
Args, OpBundles);
4765 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(Caller)) {
4766 NewCall = Builder.CreateCallBr(
Callee, CBI->getDefaultDest(),
4767 CBI->getIndirectDests(),
Args, OpBundles);
4769 NewCall = Builder.CreateCall(
Callee, Args, OpBundles);
4770 cast<CallInst>(NewCall)->setTailCallKind(
4771 cast<CallInst>(Caller)->getTailCallKind());
4793 if (
InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
4795 InsertNewInstBefore(NC, *I);
4796 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(Caller)) {
4798 InsertNewInstBefore(NC, *I);
4801 InsertNewInstBefore(NC, *Caller);
4803 Worklist.AddUsersToWorkList(*Caller);
4810 replaceInstUsesWith(*Caller, NV);
4812 if (OldRetTy == NV->
getType())
4820 eraseInstFromFunction(*Caller);
4827 InstCombiner::transformCallThroughTrampoline(
CallBase &Call,
4844 unsigned NestArgNo = 0;
4845 Type *NestTy =
nullptr;
4850 E = NestFTy->param_end();
4851 I !=
E; ++NestArgNo, ++
I) {
4862 std::vector<Value*> NewArgs;
4863 std::vector<AttributeSet> NewArgAttrs;
4864 NewArgs.reserve(Call.
arg_size() + 1);
4865 NewArgAttrs.reserve(Call.
arg_size());
4874 if (ArgNo == NestArgNo) {
4877 if (NestVal->
getType() != NestTy)
4878 NestVal = Builder.CreateBitCast(NestVal, NestTy,
"nest");
4879 NewArgs.push_back(NestVal);
4880 NewArgAttrs.push_back(NestAttr);
4887 NewArgs.push_back(*
I);
4899 std::vector<Type*> NewTypes;
4910 if (ArgNo == NestArgNo)
4912 NewTypes.push_back(NestTy);
4918 NewTypes.push_back(*I);
4941 if (
InvokeInst *II = dyn_cast<InvokeInst>(&Call)) {
4943 II->getNormalDest(), II->getUnwindDest(),
4944 NewArgs, OpBundles);
4945 cast<InvokeInst>(NewCaller)->setCallingConv(II->
getCallingConv());
4946 cast<InvokeInst>(NewCaller)->setAttributes(NewPAL);
4947 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(&Call)) {
4950 CBI->getIndirectDests(), NewArgs, OpBundles);
4951 cast<CallBrInst>(NewCaller)->setCallingConv(CBI->getCallingConv());
4952 cast<CallBrInst>(NewCaller)->setAttributes(NewPAL);
4955 cast<CallInst>(NewCaller)->setTailCallKind(
4956 cast<CallInst>(Call).getTailCallKind());
4957 cast<CallInst>(NewCaller)->setCallingConv(
4958 cast<CallInst>(Call).getCallingConv());
4959 cast<CallInst>(NewCaller)->setAttributes(NewPAL);
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)
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, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LibCallSimplifier - This class implements a collection of optimizations that replace well formed call...
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
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.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static void ValueIsDeleted(Value *V)
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
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.
APInt sext(unsigned width) const
Sign extend to a new width.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
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
Atomic ordering constants.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
This class represents lattice values for constants.
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.
static Value * simplifyX86pack(IntrinsicInst &II, InstCombiner::BuilderTy &Builder, bool IsSigned)
Represents an op.with.overflow intrinsic.
A Module instance is used to store all the information related to an LLVM module. ...
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
Instruction * visitCallInst(CallInst &CI)
CallInst simplification.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, const char *Name)
Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")' correctly, instead of converting the strin...
bool isConvergent() const
Determine if the invoke is convergent.
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
An instruction for ordering other memory operations.
static MDString * get(LLVMContext &Context, StringRef Str)
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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)) ...
void push_back(const T &Elt)
static ConstantAggregateZero * get(Type *Ty)
void setProfWeight(uint64_t W)
Sets the branch_weights metadata to W for CallInst.
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
APInt uadd_sat(const APInt &RHS) const
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...
static uint64_t round(uint64_t Acc, uint64_t Input)
Optional< std::vector< StOtherPiece > > Other
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.
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, MaybeAlign Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
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)
Always overflows in the direction of signed/unsigned min value.
LLVMContext & getContext() const
All values hold a context through their type.
bool isTerminator() const
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...
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")
void setArgOperand(unsigned i, Value *v)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Type * getStructElementType(unsigned N) const
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
const fltSemantics & getSemantics() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
param_iterator param_end() const
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
An instruction for reading from memory.
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that reallocates memory (e...
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.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
bool isVectorTy() const
True if this is an instance of VectorType.
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
void reserve(size_type N)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
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 CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock *> IndirectDests, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
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.
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. ...
Value * getArgOperand(unsigned i) const
static BinaryOperator * CreateNSW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Value * simplifyX86movmsk(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
This is the base class for all instructions that perform data casts.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
The core instruction combiner logic.
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
void setName(const Twine &Name)
Change the name of the value.
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
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.
static Value * simplifyX86addcarry(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Value * 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.
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.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
bool doesNotThrow() const
Determine if the call cannot unwind.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
static Value * peekThroughBitcast(Value *V, bool OneUseOnly=false)
Return the source operand of a potentially bitcasted value while optionally checking if it has one us...
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.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
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)
bool isStatepoint(const CallBase *Call)
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
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.
This class represents a no-op cast from one type to another.
bool isOpNewLikeFn(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 and throws if an all...
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.
bool maskIsAllOneOrUndef(Value *Mask)
Given a mask vector of the form <Y x="" i1>="">, Return true if all of the elements of this predicate...
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
iterator_range< User::op_iterator > arg_operands()
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
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.
static void ValueIsRAUWd(Value *Old, Value *New)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
void takeName(Value *V)
Transfer the name from V to this value.
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...
const DataLayout & getDataLayout() const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
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)
Instruction * visitFenceInst(FenceInst &FI)
initializer< Ty > init(const Ty &Val)
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")
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
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.
unsigned arg_size() const
Value * getCalledValue() const
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
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.
Value * SimplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for the multiplication of a FMA, fold the result or return null.
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.
bool isSigned() const
Whether the intrinsic is signed or unsigned.
static BinaryOperator * CreateNUW(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name="")
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
FunctionType * getFunctionType() const
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
ConstantFP - Floating Point Values [float, double].
specific_intval m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Instruction * visitCallBrInst(CallBrInst &CBI)
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.
param_iterator param_begin() const
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type...
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)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
void setCallingConv(CallingConv::ID CC)
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.
This class represents any memset intrinsic.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
self_iterator getIterator()
Value * SimplifyCall(CallBase *Call, const SimplifyQuery &Q)
Given a callsite, fold the result or return null.
Class to represent integer types.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
const Function * getFunction() const
Return the function this instruction belongs to.
static Value * simplifyX86varShift(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
bool isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
iterator_range< User::op_iterator > args()
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.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
This struct is a compact representation of a valid (non-zero power of two) alignment.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
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...
bool isGCRelocate(const CallBase *Call)
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.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
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 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 APSInt getMaxValue(uint32_t numBits, bool Unsigned)
getMaxValue - Return the APSInt representing the maximum integer value with the given bit width and s...
BlockVerifier::State From
SelectPatternFlavor Flavor
static Value * simplifyX86vpermilvar(const IntrinsicInst &II, InstCombiner::BuilderTy &Builder)
Attempt to convert vpermilvar* to shufflevector if the mask is constant.
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
getMinValue - Return the APSInt representing the minimum integer value with the given bit width and s...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
static IntrinsicInst * findInitTrampolineFromAlloca(Value *TrampMem)
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SelectPatternFlavor
Specific patterns of select instructions we can match.
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type *> Types, ArrayRef< Value *> Args, Instruction *FMFSource=nullptr, const Twine &Name="")
Create a call to intrinsic ID with args, mangled using Types.
Represents a saturating add/sub intrinsic.
Provides information about what library functions are available for the current target.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
static Instruction * canonicalizeConstantArg0ToArg1(CallInst &Call)
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.
void setAlignment(MaybeAlign Alignment)
static Value * simplifyNeonVld1(const IntrinsicInst &II, unsigned MemAlign, InstCombiner::BuilderTy &Builder)
Convert a vector load intrinsic into a simple llvm load instruction.
Type * getReturnType() const
CallInst * CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, Value *Mask)
Create a call to Masked Store intrinsic.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
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="")
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
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 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.
AttributeList getAttributes() const
Return the parameter attributes for this call.
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)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
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.
amdgpu Simplify well known AMD library false FunctionCallee Callee
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
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()
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
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))
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FMul, fold the result or return null.
bool containsConstantExpression() const
Return true if this is a vector constant that includes any constant expressions.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
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.
APInt possiblyDemandedEltsInMask(Value *Mask)
Given a mask vector of the form <Y x="" i1>="">, return an APInt (of bitwidth Y) for each lane which ...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
opStatus
IEEE-754R 7: Default exception handling.
Always overflows in the direction of signed/unsigned max value.
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
static Instruction * simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC)
unsigned getNumArgOperands() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getIntegerBitWidth() const
LLVM_NODISCARD bool empty() const
StringRef getValueAsString() const
Return the attribute's value as a string.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
CallingConv::ID getCallingConv() const
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
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 isMustTailCall() const
Tests if this call site must be tail call optimized.
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
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.
void setAlignment(MaybeAlign Alignment)
Value * optimizeCall(CallInst *CI)
optimizeCall - Take the given call instruction and return a more optimal value to replace the instruc...
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
static bool removeTriviallyEmptyRange(IntrinsicInst &I, unsigned StartID, unsigned EndID, InstCombiner &IC)
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
FunctionType * getFunctionType()
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)
static IntrinsicInst * findInitTrampoline(Value *Callee)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
AssumptionCache & getAssumptionCache() const
bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
static void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI)
APInt umul_ov(const APInt &RHS, bool &Overflow) const
static Value * simplifyX86insertq(IntrinsicInst &II, Value *Op0, Value *Op1, APInt APLength, APInt APIndex, InstCombiner::BuilderTy &Builder)
Attempt to simplify SSE4A INSERTQ/INSERTQI instructions using constant folding or conversion to a shu...
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.
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.
static Instruction * foldCtpop(IntrinsicInst &II, InstCombiner &IC)
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
static Constant * getURem(Constant *C1, Constant *C2)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
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 isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
bool hasOneUse() const
Return true if there is exactly one user of this value.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
unsigned getNumElements() const
Return the number of elements in the array or vector.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
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.
void setVolatile(bool V)
Specify whether this is a volatile load or not.
bool isEmpty() const
Return true if there are no attributes.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static bool isSafeToEliminateVarargsCast(const CallBase &Call, 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...
bool isStrdupLikeFn(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 (strdup, strndup).
bool isGCResult(const CallBase *Call)
static IntegerType * getInt8Ty(LLVMContext &C)
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.
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
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)