46 #define DEBUG_TYPE "instcombine" 52 if (
Constant *
C = dyn_cast<Constant>(V)) {
53 if (isConstant)
return true;
56 if (
Constant *Op0 =
C->getAggregateElement(0U)) {
59 if (
C->getAggregateElement(i) != Op0)
69 if (I->
getOpcode() == Instruction::InsertElement && isConstant &&
75 if (BO->hasOneUse() &&
79 if (
CmpInst *CI = dyn_cast<CmpInst>(I))
80 if (CI->hasOneUse() &&
98 for (
auto U : PN->
users()) {
104 }
else if (!PHIUser) {
105 PHIUser = cast<Instruction>(U);
123 PHINode *scalarPHI = cast<PHINode>(InsertNewInstWith(
131 if (PHIInVal == PHIUser) {
136 unsigned opId = (B0->
getOperand(0) == PN) ? 1 : 0;
141 Value *newPHIUser = InsertNewInstWith(
143 scalarPHI,
Op, B0), *B0);
151 if (pos && !isa<PHINode>(pos)) {
157 InsertNewInstWith(newEI, *InsertPos);
163 for (
auto E : Extracts)
164 replaceInstUsesWith(*
E, scalarPHI);
172 SQ.getWithInstruction(&EI)))
173 return replaceInstUsesWith(EI, V);
179 return replaceInstUsesWith(EI,
C->getAggregateElement(0U));
187 if (!IdxC->getValue().ule(VectorWidth))
190 unsigned IndexVal = IdxC->getZExtValue();
196 APInt UndefElts(VectorWidth, 0);
197 APInt DemandedMask(VectorWidth, 0);
198 DemandedMask.
setBit(IndexVal);
199 if (
Value *V = SimplifyDemandedVectorElts(EI.
getOperand(0), DemandedMask,
210 if (
VectorType *VT = dyn_cast<VectorType>(BCI->getOperand(0)->getType()))
211 if (VT->getNumElements() == VectorWidth)
229 if (
I->hasOneUse() &&
232 Builder.CreateExtractElement(BO->getOperand(0), EI.
getOperand(1),
235 Builder.CreateExtractElement(BO->getOperand(1), EI.
getOperand(1),
243 return replaceInstUsesWith(EI,
IE->getOperand(1));
246 if (isa<Constant>(
IE->getOperand(2)) && isa<Constant>(EI.
getOperand(1))) {
255 int SrcIdx = SVI->getMaskValue(Elt->getZExtValue());
262 if (SrcIdx < (
int)LHSWidth)
263 Src = SVI->getOperand(0);
266 Src = SVI->getOperand(1);
273 }
else if (
CastInst *CI = dyn_cast<CastInst>(
I)) {
277 if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast)) {
278 Value *EE = Builder.CreateExtractElement(CI->getOperand(0),
280 Worklist.AddValue(EE);
293 "Invalid CollectSingleShuffleElements");
296 if (isa<UndefValue>(V)) {
302 for (
unsigned i = 0; i != NumElts; ++i)
308 for (
unsigned i = 0; i != NumElts; ++i)
316 Value *VecOp = IEI->getOperand(0);
317 Value *ScalarOp = IEI->getOperand(1);
318 Value *IdxOp = IEI->getOperand(2);
320 if (!isa<ConstantInt>(IdxOp))
322 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
324 if (isa<UndefValue>(ScalarOp)) {
334 unsigned ExtractedIdx =
335 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
345 Mask[InsertedIdx % NumElts] =
350 Mask[InsertedIdx % NumElts] =
352 ExtractedIdx + NumLHSElts);
377 NumExtElts >= NumInsElts)
386 for (
unsigned i = 0; i < NumExtElts; ++i)
388 for (
unsigned i = NumExtElts; i < NumInsElts; ++i)
393 BasicBlock *InsertionBlock = (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
406 if (InsertionBlock != InsElt->
getParent())
424 if (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
425 WideVec->insertAfter(ExtVecOpInst);
458 if (isa<UndefValue>(V)) {
460 return std::make_pair(
464 if (isa<ConstantAggregateZero>(V)) {
466 return std::make_pair(V,
nullptr);
471 Value *VecOp = IEI->getOperand(0);
472 Value *ScalarOp = IEI->getOperand(1);
473 Value *IdxOp = IEI->getOperand(2);
476 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
477 unsigned ExtractedIdx =
478 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
479 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
483 if (EI->
getOperand(0) == PermittedRHS || PermittedRHS ==
nullptr) {
486 assert(LR.second ==
nullptr || LR.second == RHS);
488 if (LR.first->getType() != RHS->
getType()) {
495 for (
unsigned i = 0; i < NumElts; ++i)
497 return std::make_pair(V,
nullptr);
501 Mask[InsertedIdx % NumElts] =
503 NumLHSElts+ExtractedIdx);
504 return std::make_pair(LR.first, RHS);
507 if (VecOp == PermittedRHS) {
510 unsigned NumLHSElts =
512 for (
unsigned i = 0; i != NumElts; ++i)
515 i == InsertedIdx ? ExtractedIdx : NumLHSElts + i));
516 return std::make_pair(EI->
getOperand(0), PermittedRHS);
524 return std::make_pair(EI->
getOperand(0), PermittedRHS);
530 for (
unsigned i = 0; i != NumElts; ++i)
532 return std::make_pair(V,
nullptr);
543 bool IsRedundant =
false;
557 if (UserInsInst->getIndices() == FirstIndices) {
566 return replaceInstUsesWith(I, I.
getOperand(0));
575 if (MaskSize != VecSize)
580 for (
int i = 0; i != MaskSize; ++i) {
582 if (Elt != -1 && Elt != i && Elt != i + VecSize)
604 if (NumElements == 1)
616 if (!Idx || CurrIE->
getOperand(1) != SplatVal)
623 if (CurrIE != &InsElt &&
624 (!CurrIE->
hasOneUse() && (NextIE !=
nullptr || !Idx->isZero())))
627 ElementPresent[Idx->getZExtValue()] =
true;
633 if (
llvm::any_of(ElementPresent, [](
bool Present) {
return !Present; }))
639 InsertFirst = FirstIE;
664 if (!InsElt1 || !InsElt1->hasOneUse())
671 match(InsElt1->getOperand(1),
m_Value(Y)) && !isa<Constant>(Y) &&
688 if (!Inst || !Inst->hasOneUse())
690 if (
auto *Shuf = dyn_cast<ShuffleVectorInst>(InsElt.
getOperand(0))) {
693 Constant *ShufConstVec, *InsEltScalar;
694 uint64_t InsEltIndex;
720 for (
unsigned I = 0;
I != NumElts; ++
I) {
721 if (
I == InsEltIndex) {
722 NewShufElts[
I] = InsEltScalar;
737 }
else if (
auto *IEI = dyn_cast<InsertElementInst>(Inst)) {
742 uint64_t InsertIdx[2];
755 for (uint64_t
I : InsertIdx) {
765 for (
unsigned I = 0;
I < NumElts; ++
I) {
787 VecOp, ScalarOp, IdxOp, SQ.getWithInstruction(&IE)))
788 return replaceInstUsesWith(IE, V);
791 if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
792 replaceInstUsesWith(IE, VecOp);
797 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
799 unsigned NumExtractVectorElts =
801 unsigned ExtractedIdx =
802 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
803 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
805 if (ExtractedIdx >= NumExtractVectorElts)
806 return replaceInstUsesWith(IE, VecOp);
808 if (InsertedIdx >= NumInsertVectorElts)
813 if (EI->
getOperand(0) == VecOp && ExtractedIdx == InsertedIdx)
814 return replaceInstUsesWith(IE, VecOp);
824 if (LR.first != &IE && LR.second != &IE) {
826 if (LR.second ==
nullptr)
836 APInt UndefElts(VWidth, 0);
838 if (
Value *V = SimplifyDemandedVectorElts(&IE, AllOnesEltMask, UndefElts)) {
840 return replaceInstUsesWith(IE, V);
861 unsigned Depth = 5) {
863 if (isa<Constant>(V))
868 if (!I)
return false;
874 if (
Depth == 0)
return false;
878 case Instruction::FAdd:
879 case Instruction::Sub:
880 case Instruction::FSub:
881 case Instruction::Mul:
882 case Instruction::FMul:
883 case Instruction::UDiv:
884 case Instruction::SDiv:
885 case Instruction::FDiv:
886 case Instruction::URem:
887 case Instruction::SRem:
888 case Instruction::FRem:
889 case Instruction::Shl:
890 case Instruction::LShr:
891 case Instruction::AShr:
892 case Instruction::And:
893 case Instruction::Or:
894 case Instruction::Xor:
895 case Instruction::ICmp:
896 case Instruction::FCmp:
897 case Instruction::Trunc:
898 case Instruction::ZExt:
899 case Instruction::SExt:
900 case Instruction::FPToUI:
901 case Instruction::FPToSI:
902 case Instruction::UIToFP:
903 case Instruction::SIToFP:
904 case Instruction::FPTrunc:
905 case Instruction::FPExt:
906 case Instruction::GetElementPtr: {
913 case Instruction::InsertElement: {
915 if (!CI)
return false;
920 bool SeenOnce =
false;
921 for (
int i = 0, e = Mask.
size(); i != e; ++i) {
922 if (Mask[i] == ElementNumber) {
941 case Instruction::FAdd:
942 case Instruction::Sub:
943 case Instruction::FSub:
944 case Instruction::Mul:
945 case Instruction::FMul:
946 case Instruction::UDiv:
947 case Instruction::SDiv:
948 case Instruction::FDiv:
949 case Instruction::URem:
950 case Instruction::SRem:
951 case Instruction::FRem:
952 case Instruction::Shl:
953 case Instruction::LShr:
954 case Instruction::AShr:
955 case Instruction::And:
956 case Instruction::Or:
957 case Instruction::Xor: {
959 assert(NewOps.
size() == 2 &&
"binary operator with #ops != 2");
962 NewOps[0], NewOps[1],
"", BO);
963 if (isa<OverflowingBinaryOperator>(BO)) {
967 if (isa<PossiblyExactOperator>(BO)) {
968 New->setIsExact(BO->
isExact());
970 if (isa<FPMathOperator>(BO))
971 New->copyFastMathFlags(I);
974 case Instruction::ICmp:
975 assert(NewOps.
size() == 2 &&
"icmp with #ops != 2");
977 NewOps[0], NewOps[1]);
978 case Instruction::FCmp:
979 assert(NewOps.
size() == 2 &&
"fcmp with #ops != 2");
981 NewOps[0], NewOps[1]);
982 case Instruction::Trunc:
983 case Instruction::ZExt:
984 case Instruction::SExt:
985 case Instruction::FPToUI:
986 case Instruction::FPToSI:
987 case Instruction::UIToFP:
988 case Instruction::SIToFP:
989 case Instruction::FPTrunc:
990 case Instruction::FPExt: {
995 NewOps[0]->getType()->getVectorNumElements());
996 assert(NewOps.
size() == 1 &&
"cast with #ops != 1");
1000 case Instruction::GetElementPtr: {
1004 cast<GetElementPtrInst>(I)->getSourceElementType(), Ptr, Idx,
"", I);
1005 GEP->
setIsInBounds(cast<GetElementPtrInst>(I)->isInBounds());
1018 if (isa<UndefValue>(V))
1021 if (isa<ConstantAggregateZero>(V))
1024 if (
Constant *
C = dyn_cast<Constant>(V)) {
1026 for (
int i = 0, e = Mask.
size(); i != e; ++i) {
1030 MaskValues.
push_back(Builder.getInt32(Mask[i]));
1037 switch (I->getOpcode()) {
1039 case Instruction::FAdd:
1040 case Instruction::Sub:
1041 case Instruction::FSub:
1042 case Instruction::Mul:
1043 case Instruction::FMul:
1044 case Instruction::UDiv:
1045 case Instruction::SDiv:
1046 case Instruction::FDiv:
1047 case Instruction::URem:
1048 case Instruction::SRem:
1049 case Instruction::FRem:
1050 case Instruction::Shl:
1051 case Instruction::LShr:
1052 case Instruction::AShr:
1053 case Instruction::And:
1054 case Instruction::Or:
1055 case Instruction::Xor:
1056 case Instruction::ICmp:
1057 case Instruction::FCmp:
1058 case Instruction::Trunc:
1059 case Instruction::ZExt:
1060 case Instruction::SExt:
1061 case Instruction::FPToUI:
1062 case Instruction::FPToSI:
1063 case Instruction::UIToFP:
1064 case Instruction::SIToFP:
1065 case Instruction::FPTrunc:
1066 case Instruction::FPExt:
1068 case Instruction::GetElementPtr: {
1070 bool NeedsRebuild = (Mask.
size() != I->getType()->getVectorNumElements());
1071 for (
int i = 0, e = I->getNumOperands(); i != e; ++i) {
1072 Value *V = EvaluateInDifferentElementOrder(I->getOperand(i),
Mask);
1074 NeedsRebuild |= (V != I->getOperand(i));
1081 case Instruction::InsertElement: {
1082 int Element = cast<ConstantInt>(I->getOperand(2))->getLimitedValue();
1089 for (
int e = Mask.
size(); Index != e; ++
Index) {
1090 if (Mask[Index] == Element) {
1099 return EvaluateInDifferentElementOrder(I->getOperand(0),
Mask);
1101 Value *V = EvaluateInDifferentElementOrder(I->getOperand(0),
Mask);
1103 Builder.getInt32(Index),
"",
I);
1110 bool &isLHSID,
bool &isRHSID) {
1111 isLHSID = isRHSID =
true;
1113 for (
unsigned i = 0, e = Mask.
size(); i != e; ++i) {
1114 if (Mask[i] < 0)
continue;
1116 isLHSID &= (Mask[i] == (int)i);
1119 isRHSID &= (Mask[i]-e == i);
1132 unsigned MaskElems = Mask.
size();
1133 unsigned BegIdx = Mask.
front();
1134 unsigned EndIdx = Mask.
back();
1135 if (BegIdx > EndIdx || EndIdx >= LHSElems || EndIdx - BegIdx != MaskElems - 1)
1137 for (
unsigned I = 0;
I != MaskElems; ++
I)
1138 if (static_cast<unsigned>(Mask[
I]) != BegIdx + I)
1151 Opcode(Opc), Op0(V0), Op1(V1) {}
1152 operator bool()
const {
return Opcode != 0; }
1163 case Instruction::Shl: {
1168 return { Instruction::Mul, BO0, ShlOne };
1172 case Instruction::Or: {
1186 assert(Shuf.
isSelect() &&
"Must have select-equivalent shuffle");
1203 auto *BO = cast<BinaryOperator>(Op0IsBinop ? Op0 : Op1);
1217 bool MightCreatePoisonOrUB =
1220 if (MightCreatePoisonOrUB)
1225 Value *
X = Op0IsBinop ? Op1 : Op0;
1254 bool ConstantsAreOp1;
1257 ConstantsAreOp1 =
true;
1260 ConstantsAreOp1 =
false;
1267 bool DropNSW =
false;
1268 if (ConstantsAreOp1 && Opc0 != Opc1) {
1272 if (Opc0 == Instruction::Shl || Opc1 == Instruction::Shl)
1275 assert(isa<Constant>(AltB0.Op1) &&
"Expecting constant with alt binop");
1276 Opc0 = AltB0.Opcode;
1277 C0 = cast<Constant>(AltB0.Op1);
1279 assert(isa<Constant>(AltB1.Op1) &&
"Expecting constant with alt binop");
1280 Opc1 = AltB1.Opcode;
1281 C1 = cast<Constant>(AltB1.Op1);
1298 bool MightCreatePoisonOrUB =
1301 if (MightCreatePoisonOrUB)
1323 if (MightCreatePoisonOrUB && !ConstantsAreOp1)
1360 LHS, RHS, SVI.
getMask(), SVI.
getType(), SQ.getWithInstruction(&SVI)))
1361 return replaceInstUsesWith(SVI, V);
1366 bool MadeChange =
false;
1369 APInt UndefElts(VWidth, 0);
1371 if (
Value *V = SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) {
1373 return replaceInstUsesWith(SVI, V);
1381 if (LHS == RHS || isa<UndefValue>(LHS)) {
1382 if (isa<UndefValue>(LHS) && LHS == RHS) {
1386 return replaceInstUsesWith(SVI, Result);
1391 for (
unsigned i = 0, e = LHSWidth; i != VWidth; ++i) {
1397 if ((Mask[i] >= (
int)e && isa<UndefValue>(RHS)) ||
1398 (Mask[i] < (
int)e && isa<UndefValue>(LHS))) {
1402 Mask[i] = Mask[i] % e;
1414 if (VWidth == LHSWidth) {
1416 bool isLHSID, isRHSID;
1420 if (isLHSID)
return replaceInstUsesWith(SVI, LHS);
1421 if (isRHSID)
return replaceInstUsesWith(SVI, RHS);
1425 Value *V = EvaluateInDifferentElementOrder(LHS, Mask);
1426 return replaceInstUsesWith(SVI, V);
1460 unsigned MaskElems = Mask.
size();
1463 unsigned SrcElemBitWidth = DL.getTypeSizeInBits(SrcTy->
getElementType());
1464 assert(SrcElemBitWidth &&
"vector elements must have a bitwidth");
1470 if (!BC->use_empty())
1474 unsigned BegIdx = Mask.
front();
1475 Type *TgtTy = BC->getDestTy();
1476 unsigned TgtElemBitWidth = DL.getTypeSizeInBits(TgtTy);
1477 if (!TgtElemBitWidth)
1479 unsigned TgtNumElems = VecBitWidth / TgtElemBitWidth;
1480 bool VecBitWidthsEqual = VecBitWidth == TgtNumElems * TgtElemBitWidth;
1481 bool BegIsAligned = 0 == ((SrcElemBitWidth * BegIdx) % TgtElemBitWidth);
1482 if (!VecBitWidthsEqual)
1487 if (!BegIsAligned) {
1492 for (
unsigned I = 0,
E = MaskElems, Idx = BegIdx;
I !=
E; ++Idx, ++
I)
1499 unsigned SrcElemsPerTgtElem = TgtElemBitWidth / SrcElemBitWidth;
1500 assert(SrcElemsPerTgtElem);
1501 BegIdx /= SrcElemsPerTgtElem;
1502 bool BCAlreadyExists = NewBCs.
find(CastSrcTy) != NewBCs.
end();
1506 : Builder.CreateBitCast(V, CastSrcTy, SVI.
getName() +
".bc");
1507 if (!BCAlreadyExists)
1508 NewBCs[CastSrcTy] = NewBC;
1509 auto *
Ext = Builder.CreateExtractElement(
1513 replaceInstUsesWith(*BC,
Ext);
1564 if (!isa<UndefValue>(LHSShuffle->
getOperand(1)) && !isa<UndefValue>(RHS))
1565 LHSShuffle =
nullptr;
1567 if (!isa<UndefValue>(RHSShuffle->getOperand(1)))
1568 RHSShuffle =
nullptr;
1569 if (!LHSShuffle && !RHSShuffle)
1570 return MadeChange ? &SVI :
nullptr;
1572 Value* LHSOp0 =
nullptr;
1573 Value* LHSOp1 =
nullptr;
1574 Value* RHSOp0 =
nullptr;
1575 unsigned LHSOp0Width = 0;
1576 unsigned RHSOp0Width = 0;
1583 RHSOp0 = RHSShuffle->getOperand(0);
1586 Value* newLHS = LHS;
1587 Value* newRHS = RHS;
1590 if (isa<UndefValue>(RHS)) {
1595 else if (LHSOp0Width == LHSWidth) {
1600 if (RHSShuffle && RHSOp0Width == LHSWidth) {
1604 if (LHSOp0 == RHSOp0) {
1609 if (newLHS == LHS && newRHS == RHS)
1610 return MadeChange ? &SVI :
nullptr;
1616 if (RHSShuffle && newRHS != RHS)
1617 RHSMask = RHSShuffle->getShuffleMask();
1619 unsigned newLHSWidth = (newLHS != LHS) ? LHSOp0Width : LHSWidth;
1625 for (
unsigned i = 0; i < VWidth; ++i) {
1630 }
else if (Mask[i] < (
int)LHSWidth) {
1635 if (newLHS != LHS) {
1636 eltMask = LHSMask[Mask[i]];
1639 if (eltMask >= (
int)LHSOp0Width && isa<UndefValue>(LHSOp1))
1648 if (isa<UndefValue>(RHS))
1652 else if (newRHS != RHS) {
1653 eltMask = RHSMask[Mask[i]-LHSWidth];
1656 if (eltMask >= (
int)RHSOp0Width) {
1657 assert(isa<UndefValue>(RHSShuffle->getOperand(1))
1658 &&
"should have been check above");
1662 eltMask = Mask[i]-LHSWidth;
1670 if (eltMask >= 0 && newRHS !=
nullptr && newLHS != newRHS)
1671 eltMask += newLHSWidth;
1676 if (SplatElt >= 0 && SplatElt != eltMask)
1686 if (isSplat || newMask == LHSMask || newMask == RHSMask || newMask == Mask) {
1688 for (
unsigned i = 0, e = newMask.
size(); i != e; ++i) {
1689 if (newMask[i] < 0) {
1702 bool isLHSID, isRHSID;
1704 if (isLHSID && VWidth == LHSOp0Width)
return replaceInstUsesWith(SVI, newLHS);
1705 if (isRHSID && VWidth == RHSOp0Width)
return replaceInstUsesWith(SVI, newRHS);
1707 return MadeChange ? &SVI :
nullptr;
static bool isShuffleEquivalentToSelect(ShuffleVectorInst &Shuf)
std::pair< Value *, Value * > ShuffleOps
We are building a shuffle to create V, which is a sequence of insertelement, extractelement pairs...
Instruction * visitInsertValueInst(InsertValueInst &IV)
Try to find redundant insertvalue instructions, like the following ones: %0 = insertvalue { i8...
void push_back(const T &Elt)
Instruction * InsertNewInstWith(Instruction *New, Instruction &Old)
Same as InsertNewInstBefore, but also sets the debug loc.
A parsed version of the target data layout string in and methods for querying it. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isConstant(const MachineInstr &MI)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static Instruction * foldSelectShuffle(ShuffleVectorInst &Shuf, InstCombiner::BuilderTy &Builder, const DataLayout &DL)
Try to fold shuffles that are the equivalent of a vector select.
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
Compute iterated dominance frontiers using a linear time algorithm.
BinaryOps getOpcode() const
static Instruction * foldConstantInsEltIntoShuffle(InsertElementInst &InsElt)
insertelt (shufflevector X, CVec, Mask|insertelt X, C1, CIndex1), C, CIndex –> shufflevector X...
static ConstantAggregateZero * get(Type *Ty)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
This instruction constructs a fixed permutation of two input vectors.
LLVMContext & getContext() const
All values hold a context through their type.
static bool isShuffleExtractingFromLHS(ShuffleVectorInst &SVI, SmallVector< int, 16 > &Mask)
bool isVectorTy() const
True if this is an instance of VectorType.
static Instruction * hoistInsEltConst(InsertElementInst &InsElt2, InstCombiner::BuilderTy &Builder)
If we have an insertelement instruction feeding into another insertelement and the 2nd is inserting a...
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static BinopElts getAlternateBinop(BinaryOperator *BO, const DataLayout &DL)
Binops may be transformed into binops with different opcodes and operands.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
Constant * getMask() const
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
unsigned getBitWidth() const
Return the number of bits in the Vector type.
void setBit(unsigned BitPosition)
Set a given bit to 1.
This is the base class for all instructions that perform data casts.
void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The core instruction combiner logic.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs...
static bool CanEvaluateShuffled(Value *V, ArrayRef< int > Mask, unsigned Depth=5)
Return true if we can evaluate the specified expression tree if the vector elements were shuffled in ...
uint64_t getNumElements() const
BinopElts(BinaryOperator::BinaryOps Opc=(BinaryOperator::BinaryOps) 0, Value *V0=nullptr, Value *V1=nullptr)
This file implements a class to represent arbitrary precision integral constant values and operations...
void assign(size_type NumElts, const T &Elt)
static Instruction * foldInsSequenceIntoBroadcast(InsertElementInst &InsElt)
Type * getType() const
All values are typed, get the type of this value.
static Constant * getSafeVectorConstantForBinop(BinaryOperator::BinaryOps Opcode, Constant *In, bool IsRHSConstant)
Some binary operators require special handling to avoid poison and undefined behavior.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
This instruction compares its operands according to the predicate given to the constructor.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
This class represents a no-op cast from one type to another.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Instruction * visitExtractElementInst(ExtractElementInst &EI)
These are the ingredients in an alternate form binary operator as described below.
static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, SmallVectorImpl< Constant *> &Mask)
If V is a shuffle of values that ONLY returns elements from either LHS or RHS, return the shuffle mas...
bool isSelect() const
Return true if this shuffle chooses elements from its source vectors without lane crossings and all o...
VectorType * getType() const
Overload to return most specific vector type.
Value * getOperand(unsigned i) const
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
iterator find(const_arg_type_t< KeyT > Val)
Instruction * visitInsertElementInst(InsertElementInst &IE)
Value * SimplifyInsertElementInst(Value *Vec, Value *Elt, Value *Idx, const SimplifyQuery &Q)
Given operands for an InsertElement, fold the result or return null.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
This instruction inserts a single (scalar) element into a VectorType value.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
size_t size() const
size - Get the array size.
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...
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
This instruction compares its operands according to the predicate given to the constructor.
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false)
Return the identity constant for a binary opcode.
self_iterator getIterator()
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Class to represent integer types.
static void replaceExtractElements(InsertElementInst *InsElt, ExtractElementInst *ExtElt, InstCombiner &IC)
If we have insertion into a vector that is wider than the vector that we are extracting from...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool isExact() const
Determine whether the exact flag is set.
static int getMaskValue(const Constant *Mask, unsigned Elt)
Return the shuffle mask value for the specified element of the mask.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * SimplifyShuffleVectorInst(Value *Op0, Value *Op1, Constant *Mask, Type *RetTy, const SimplifyQuery &Q)
Given operands for a ShuffleVectorInst, fold the result or return null.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
Iterator for intrusive lists based on ilist_node.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
This is the shared class of boolean and integer constants.
BinaryOperator::BinaryOps Opcode
bool containsUndefElement() const
Return true if this is a vector constant that includes any undefined elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
static void getShuffleMask(const Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
static Instruction * foldSelectShuffleWith1Binop(ShuffleVectorInst &Shuf)
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
void setOperand(unsigned i, Value *Val)
unsigned getVectorNumElements() const
Class to represent vector types.
Class for arbitrary precision integers.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
iterator_range< user_iterator > users()
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
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 ...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, BinaryOperator *CopyBO, const Twine &Name="")
static bool cheapToScalarize(Value *V, bool isConstant)
Return true if the value is cheaper to scalarize than it is to leave as a vector operation.
static IntegerType * getInt32Ty(LLVMContext &C)
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
Instruction * visitShuffleVectorInst(ShuffleVectorInst &SVI)
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 Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
ArrayRef< unsigned > getIndices() const
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &Q)
Given operands for an ExtractElementInst, fold the result or return null.
static Value * buildNew(Instruction *I, ArrayRef< Value *> NewOps)
Rebuild a new instruction just like 'I' but with the new operands given.
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.
Type * getElementType() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
static bool isSplat(ArrayRef< Value *> VL)
static void recognizeIdentityMask(const SmallVectorImpl< int > &Mask, bool &isLHSID, bool &isRHSID)
static ShuffleOps collectShuffleElements(Value *V, SmallVectorImpl< Constant *> &Mask, Value *PermittedRHS, InstCombiner &IC)
VectorType * getType() const
Overload to return most specific vector type.
static Constant * get(ArrayRef< Constant *> V)
const BasicBlock * getParent() const
This instruction inserts a struct field of array element value into an aggregate value.