21 using namespace PatternMatch;
23 #define DEBUG_TYPE "instcombine"
29 if (
Constant *
C = dyn_cast<Constant>(V)) {
30 if (isConstant)
return true;
33 if (
Constant *Op0 =
C->getAggregateElement(0U)) {
36 if (
C->getAggregateElement(i) != Op0)
46 if (I->
getOpcode() == Instruction::InsertElement && isConstant &&
52 if (BO->hasOneUse() &&
56 if (
CmpInst *CI = dyn_cast<CmpInst>(I))
57 if (CI->hasOneUse() &&
75 for (
auto U : PN->
users()) {
81 }
else if (!PHIUser) {
82 PHIUser = cast<Instruction>(U);
100 PHINode *scalarPHI = cast<PHINode>(InsertNewInstWith(
108 if (PHIInVal == PHIUser) {
113 unsigned opId = (B0->
getOperand(0) == PN) ? 1 : 0;
118 Value *newPHIUser = InsertNewInstWith(
120 scalarPHI,
Op, B0), *B0);
128 if (pos && !isa<PHINode>(pos)) {
134 InsertNewInstWith(newEI, *InsertPos);
140 for (
auto E : Extracts)
141 replaceInstUsesWith(*
E, scalarPHI);
149 SQ.getWithInstruction(&EI)))
150 return replaceInstUsesWith(EI, V);
156 return replaceInstUsesWith(EI,
C->getAggregateElement(0U));
161 unsigned IndexVal = IdxC->getZExtValue();
165 assert(IndexVal < VectorWidth);
171 APInt UndefElts(VectorWidth, 0);
172 APInt DemandedMask(VectorWidth, 0);
173 DemandedMask.
setBit(IndexVal);
174 if (
Value *V = SimplifyDemandedVectorElts(EI.
getOperand(0), DemandedMask,
185 if (
VectorType *VT = dyn_cast<VectorType>(BCI->getOperand(0)->getType()))
186 if (VT->getNumElements() == VectorWidth)
204 if (
I->hasOneUse() &&
207 Builder.CreateExtractElement(BO->getOperand(0), EI.
getOperand(1),
210 Builder.CreateExtractElement(BO->getOperand(1), EI.
getOperand(1),
218 return replaceInstUsesWith(EI,
IE->getOperand(1));
221 if (isa<Constant>(
IE->getOperand(2)) && isa<Constant>(EI.
getOperand(1))) {
230 int SrcIdx = SVI->getMaskValue(Elt->getZExtValue());
237 if (SrcIdx < (
int)LHSWidth)
238 Src = SVI->getOperand(0);
241 Src = SVI->getOperand(1);
248 }
else if (
CastInst *CI = dyn_cast<CastInst>(
I)) {
252 if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast)) {
253 Value *EE = Builder.CreateExtractElement(CI->getOperand(0),
255 Worklist.AddValue(EE);
259 if (
SI->hasOneUse()) {
267 Value *TrueVal =
SI->getTrueValue();
268 Value *FalseVal =
SI->getFalseValue();
270 Value *Cond =
SI->getCondition();
272 Cond = Builder.CreateExtractElement(Cond,
278 = Builder.CreateExtractElement(TrueVal,
283 = Builder.CreateExtractElement(FalseVal,
289 SI->getName() +
".elt");
301 "Invalid CollectSingleShuffleElements");
304 if (isa<UndefValue>(V)) {
310 for (
unsigned i = 0; i != NumElts; ++i)
316 for (
unsigned i = 0; i != NumElts; ++i)
324 Value *VecOp = IEI->getOperand(0);
325 Value *ScalarOp = IEI->getOperand(1);
326 Value *IdxOp = IEI->getOperand(2);
328 if (!isa<ConstantInt>(IdxOp))
330 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
332 if (isa<UndefValue>(ScalarOp)) {
342 unsigned ExtractedIdx =
343 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
353 Mask[InsertedIdx % NumElts] =
358 Mask[InsertedIdx % NumElts] =
360 ExtractedIdx + NumLHSElts);
385 NumExtElts >= NumInsElts)
394 for (
unsigned i = 0; i < NumExtElts; ++i)
396 for (
unsigned i = NumExtElts; i < NumInsElts; ++i)
401 BasicBlock *InsertionBlock = (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
414 if (InsertionBlock != InsElt->
getParent())
432 if (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
433 WideVec->insertAfter(ExtVecOpInst);
466 if (isa<UndefValue>(V)) {
468 return std::make_pair(
472 if (isa<ConstantAggregateZero>(V)) {
474 return std::make_pair(V,
nullptr);
479 Value *VecOp = IEI->getOperand(0);
480 Value *ScalarOp = IEI->getOperand(1);
481 Value *IdxOp = IEI->getOperand(2);
484 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
485 unsigned ExtractedIdx =
486 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
487 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
491 if (EI->
getOperand(0) == PermittedRHS || PermittedRHS ==
nullptr) {
494 assert(LR.second ==
nullptr || LR.second == RHS);
496 if (LR.first->getType() != RHS->
getType()) {
503 for (
unsigned i = 0; i < NumElts; ++i)
505 return std::make_pair(V,
nullptr);
509 Mask[InsertedIdx % NumElts] =
511 NumLHSElts+ExtractedIdx);
512 return std::make_pair(LR.first, RHS);
515 if (VecOp == PermittedRHS) {
518 unsigned NumLHSElts =
520 for (
unsigned i = 0; i != NumElts; ++i)
523 i == InsertedIdx ? ExtractedIdx : NumLHSElts + i));
524 return std::make_pair(EI->
getOperand(0), PermittedRHS);
532 return std::make_pair(EI->
getOperand(0), PermittedRHS);
538 for (
unsigned i = 0; i != NumElts; ++i)
540 return std::make_pair(V,
nullptr);
551 bool IsRedundant =
false;
565 if (UserInsInst->getIndices() == FirstIndices) {
574 return replaceInstUsesWith(I, I.
getOperand(0));
583 if (MaskSize != VecSize)
588 for (
int i = 0; i != MaskSize; ++i) {
590 if (Elt != -1 && Elt != i && Elt != i + VecSize)
612 if (NumElements == 1)
623 if (!Idx || CurrIE->
getOperand(1) != SplatVal)
627 if ((CurrIE != &InsElt) && !CurrIE->
hasOneUse())
635 if (
llvm::any_of(ElementPresent, [](
bool Present) {
return !Present; }))
661 if (!InsElt1 || !InsElt1->hasOneUse())
668 match(InsElt1->getOperand(1),
m_Value(Y)) && !isa<Constant>(Y) &&
685 if (!Inst || !Inst->hasOneUse())
687 if (
auto *Shuf = dyn_cast<ShuffleVectorInst>(InsElt.
getOperand(0))) {
690 Constant *ShufConstVec, *InsEltScalar;
691 uint64_t InsEltIndex;
717 for (
unsigned I = 0;
I != NumElts; ++
I) {
718 if (
I == InsEltIndex) {
719 NewShufElts[
I] = InsEltScalar;
734 }
else if (
auto *IEI = dyn_cast<InsertElementInst>(Inst)) {
739 uint64_t InsertIdx[2];
752 for (uint64_t
I : InsertIdx) {
762 for (
unsigned I = 0;
I < NumElts; ++
I) {
784 if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
785 replaceInstUsesWith(IE, VecOp);
790 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
792 unsigned NumExtractVectorElts =
794 unsigned ExtractedIdx =
795 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
796 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
798 if (ExtractedIdx >= NumExtractVectorElts)
799 return replaceInstUsesWith(IE, VecOp);
801 if (InsertedIdx >= NumInsertVectorElts)
806 if (EI->
getOperand(0) == VecOp && ExtractedIdx == InsertedIdx)
807 return replaceInstUsesWith(IE, VecOp);
817 if (LR.first != &IE && LR.second != &IE) {
819 if (LR.second ==
nullptr)
829 APInt UndefElts(VWidth, 0);
831 if (
Value *V = SimplifyDemandedVectorElts(&IE, AllOnesEltMask, UndefElts)) {
833 return replaceInstUsesWith(IE, V);
854 unsigned Depth = 5) {
856 if (isa<Constant>(V))
861 if (!I)
return false;
867 if (
Depth == 0)
return false;
871 case Instruction::FAdd:
872 case Instruction::Sub:
873 case Instruction::FSub:
874 case Instruction::Mul:
875 case Instruction::FMul:
876 case Instruction::UDiv:
877 case Instruction::SDiv:
878 case Instruction::FDiv:
879 case Instruction::URem:
880 case Instruction::SRem:
881 case Instruction::FRem:
882 case Instruction::Shl:
883 case Instruction::LShr:
884 case Instruction::AShr:
885 case Instruction::And:
886 case Instruction::Or:
887 case Instruction::Xor:
888 case Instruction::ICmp:
889 case Instruction::FCmp:
890 case Instruction::Trunc:
891 case Instruction::ZExt:
892 case Instruction::SExt:
893 case Instruction::FPToUI:
894 case Instruction::FPToSI:
895 case Instruction::UIToFP:
896 case Instruction::SIToFP:
897 case Instruction::FPTrunc:
898 case Instruction::FPExt:
899 case Instruction::GetElementPtr: {
906 case Instruction::InsertElement: {
908 if (!CI)
return false;
913 bool SeenOnce =
false;
914 for (
int i = 0, e = Mask.
size(); i != e; ++i) {
915 if (Mask[i] == ElementNumber) {
934 case Instruction::FAdd:
935 case Instruction::Sub:
936 case Instruction::FSub:
937 case Instruction::Mul:
938 case Instruction::FMul:
939 case Instruction::UDiv:
940 case Instruction::SDiv:
941 case Instruction::FDiv:
942 case Instruction::URem:
943 case Instruction::SRem:
944 case Instruction::FRem:
945 case Instruction::Shl:
946 case Instruction::LShr:
947 case Instruction::AShr:
948 case Instruction::And:
949 case Instruction::Or:
950 case Instruction::Xor: {
952 assert(NewOps.
size() == 2 &&
"binary operator with #ops != 2");
955 NewOps[0], NewOps[1],
"", BO);
956 if (isa<OverflowingBinaryOperator>(BO)) {
960 if (isa<PossiblyExactOperator>(BO)) {
961 New->setIsExact(BO->
isExact());
963 if (isa<FPMathOperator>(BO))
964 New->copyFastMathFlags(I);
967 case Instruction::ICmp:
968 assert(NewOps.
size() == 2 &&
"icmp with #ops != 2");
969 return new ICmpInst(I, cast<ICmpInst>(I)->getPredicate(),
970 NewOps[0], NewOps[1]);
971 case Instruction::FCmp:
972 assert(NewOps.
size() == 2 &&
"fcmp with #ops != 2");
973 return new FCmpInst(I, cast<FCmpInst>(I)->getPredicate(),
974 NewOps[0], NewOps[1]);
975 case Instruction::Trunc:
976 case Instruction::ZExt:
977 case Instruction::SExt:
978 case Instruction::FPToUI:
979 case Instruction::FPToSI:
980 case Instruction::UIToFP:
981 case Instruction::SIToFP:
982 case Instruction::FPTrunc:
983 case Instruction::FPExt: {
988 NewOps[0]->getType()->getVectorNumElements());
989 assert(NewOps.
size() == 1 &&
"cast with #ops != 1");
993 case Instruction::GetElementPtr: {
997 cast<GetElementPtrInst>(I)->getSourceElementType(), Ptr, Idx,
"", I);
998 GEP->
setIsInBounds(cast<GetElementPtrInst>(I)->isInBounds());
1010 if (isa<UndefValue>(V)) {
1014 if (isa<ConstantAggregateZero>(V)) {
1019 if (
Constant *
C = dyn_cast<Constant>(V)) {
1021 for (
int i = 0, e = Mask.
size(); i != e; ++i) {
1025 MaskValues.
push_back(Builder.getInt32(Mask[i]));
1034 case Instruction::FAdd:
1035 case Instruction::Sub:
1036 case Instruction::FSub:
1037 case Instruction::Mul:
1038 case Instruction::FMul:
1039 case Instruction::UDiv:
1040 case Instruction::SDiv:
1041 case Instruction::FDiv:
1042 case Instruction::URem:
1043 case Instruction::SRem:
1044 case Instruction::FRem:
1045 case Instruction::Shl:
1046 case Instruction::LShr:
1047 case Instruction::AShr:
1048 case Instruction::And:
1049 case Instruction::Or:
1050 case Instruction::Xor:
1051 case Instruction::ICmp:
1052 case Instruction::FCmp:
1053 case Instruction::Trunc:
1054 case Instruction::ZExt:
1055 case Instruction::SExt:
1056 case Instruction::FPToUI:
1057 case Instruction::FPToSI:
1058 case Instruction::UIToFP:
1059 case Instruction::SIToFP:
1060 case Instruction::FPTrunc:
1061 case Instruction::FPExt:
1063 case Instruction::GetElementPtr: {
1076 case Instruction::InsertElement: {
1077 int Element = cast<ConstantInt>(I->
getOperand(2))->getLimitedValue();
1084 for (
int e = Mask.
size(); Index != e; ++Index) {
1085 if (Mask[Index] == Element) {
1098 Builder.getInt32(Index),
"",
I);
1105 bool &isLHSID,
bool &isRHSID) {
1106 isLHSID = isRHSID =
true;
1108 for (
unsigned i = 0, e = Mask.
size(); i != e; ++i) {
1109 if (Mask[i] < 0)
continue;
1111 isLHSID &= (Mask[i] == (int)i);
1114 isRHSID &= (Mask[i]-e == i);
1127 unsigned MaskElems = Mask.
size();
1128 unsigned BegIdx = Mask.
front();
1129 unsigned EndIdx = Mask.
back();
1130 if (BegIdx > EndIdx || EndIdx >= LHSElems || EndIdx - BegIdx != MaskElems - 1)
1132 for (
unsigned I = 0; I != MaskElems; ++
I)
1133 if (static_cast<unsigned>(Mask[I]) != BegIdx + I)
1145 LHS, RHS, SVI.
getMask(), SVI.
getType(), SQ.getWithInstruction(&SVI)))
1146 return replaceInstUsesWith(SVI, V);
1148 bool MadeChange =
false;
1151 APInt UndefElts(VWidth, 0);
1153 if (
Value *V = SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) {
1155 return replaceInstUsesWith(SVI, V);
1165 if (LHS == RHS || isa<UndefValue>(LHS)) {
1166 if (isa<UndefValue>(LHS) && LHS == RHS) {
1168 Value *Result = (VWidth == LHSWidth)
1170 return replaceInstUsesWith(SVI, Result);
1175 for (
unsigned i = 0, e = LHSWidth; i != VWidth; ++i) {
1181 if ((Mask[i] >= (
int)e && isa<UndefValue>(RHS)) ||
1182 (Mask[i] < (
int)e && isa<UndefValue>(LHS))) {
1186 Mask[i] = Mask[i] % e;
1198 if (VWidth == LHSWidth) {
1200 bool isLHSID, isRHSID;
1204 if (isLHSID)
return replaceInstUsesWith(SVI, LHS);
1205 if (isRHSID)
return replaceInstUsesWith(SVI, RHS);
1209 Value *V = EvaluateInDifferentElementOrder(LHS, Mask);
1210 return replaceInstUsesWith(SVI, V);
1244 unsigned MaskElems = Mask.
size();
1248 assert(SrcElemBitWidth &&
"vector elements must have a bitwidth");
1254 if (!BC->use_empty())
1258 unsigned BegIdx = Mask.
front();
1259 Type *TgtTy = BC->getDestTy();
1261 if (!TgtElemBitWidth)
1263 unsigned TgtNumElems = VecBitWidth / TgtElemBitWidth;
1264 bool VecBitWidthsEqual = VecBitWidth == TgtNumElems * TgtElemBitWidth;
1265 bool BegIsAligned = 0 == ((SrcElemBitWidth * BegIdx) % TgtElemBitWidth);
1266 if (!VecBitWidthsEqual)
1271 if (!BegIsAligned) {
1276 for (
unsigned I = 0,
E = MaskElems, Idx = BegIdx; I !=
E; ++Idx, ++
I)
1283 unsigned SrcElemsPerTgtElem = TgtElemBitWidth / SrcElemBitWidth;
1284 assert(SrcElemsPerTgtElem);
1285 BegIdx /= SrcElemsPerTgtElem;
1286 bool BCAlreadyExists = NewBCs.
find(CastSrcTy) != NewBCs.
end();
1290 : Builder.CreateBitCast(V, CastSrcTy, SVI.
getName() +
".bc");
1291 if (!BCAlreadyExists)
1292 NewBCs[CastSrcTy] = NewBC;
1293 auto *
Ext = Builder.CreateExtractElement(
1297 replaceInstUsesWith(*BC,
Ext);
1348 if (!isa<UndefValue>(LHSShuffle->
getOperand(1)) && !isa<UndefValue>(RHS))
1349 LHSShuffle =
nullptr;
1351 if (!isa<UndefValue>(RHSShuffle->getOperand(1)))
1352 RHSShuffle =
nullptr;
1353 if (!LHSShuffle && !RHSShuffle)
1354 return MadeChange ? &SVI :
nullptr;
1356 Value* LHSOp0 =
nullptr;
1357 Value* LHSOp1 =
nullptr;
1358 Value* RHSOp0 =
nullptr;
1359 unsigned LHSOp0Width = 0;
1360 unsigned RHSOp0Width = 0;
1367 RHSOp0 = RHSShuffle->getOperand(0);
1370 Value* newLHS = LHS;
1371 Value* newRHS = RHS;
1374 if (isa<UndefValue>(RHS)) {
1379 else if (LHSOp0Width == LHSWidth) {
1384 if (RHSShuffle && RHSOp0Width == LHSWidth) {
1388 if (LHSOp0 == RHSOp0) {
1393 if (newLHS == LHS && newRHS == RHS)
1394 return MadeChange ? &SVI :
nullptr;
1400 if (RHSShuffle && newRHS != RHS)
1401 RHSMask = RHSShuffle->getShuffleMask();
1403 unsigned newLHSWidth = (newLHS != LHS) ? LHSOp0Width : LHSWidth;
1409 for (
unsigned i = 0; i < VWidth; ++i) {
1414 }
else if (Mask[i] < (
int)LHSWidth) {
1419 if (newLHS != LHS) {
1420 eltMask = LHSMask[Mask[i]];
1423 if (eltMask >= (
int)LHSOp0Width && isa<UndefValue>(LHSOp1))
1432 if (isa<UndefValue>(RHS))
1436 else if (newRHS != RHS) {
1437 eltMask = RHSMask[Mask[i]-LHSWidth];
1440 if (eltMask >= (
int)RHSOp0Width) {
1441 assert(isa<UndefValue>(RHSShuffle->getOperand(1))
1442 &&
"should have been check above");
1446 eltMask = Mask[i]-LHSWidth;
1454 if (eltMask >= 0 && newRHS !=
nullptr && newLHS != newRHS)
1455 eltMask += newLHSWidth;
1460 if (SplatElt >= 0 && SplatElt != eltMask)
1470 if (isSplat || newMask == LHSMask || newMask == RHSMask || newMask == Mask) {
1472 for (
unsigned i = 0, e = newMask.
size(); i != e; ++i) {
1473 if (newMask[i] < 0) {
1486 bool isLHSID, isRHSID;
1488 if (isLHSID && VWidth == LHSOp0Width)
return replaceInstUsesWith(SVI, newLHS);
1489 if (isRHSID && VWidth == RHSOp0Width)
return replaceInstUsesWith(SVI, newRHS);
1491 return MadeChange ? &SVI :
nullptr;
static bool isShuffleEquivalentToSelect(ShuffleVectorInst &Shuf)
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.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
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.
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
ArrayRef< unsigned > getIndices() const
static Instruction * foldConstantInsEltIntoShuffle(InsertElementInst &InsElt)
insertelt (shufflevector X, CVec, Mask|insertelt X, C1, CIndex1), C, CIndex –> shufflevector X...
unsigned getNumOperands() const
static ConstantAggregateZero * get(Type *Ty)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
std::pair< Value *, Value * > ShuffleOps
We are building a shuffle to create V, which is a sequence of insertelement, extractelement pairs...
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
const Function * getParent() const
Return the enclosing method, or null if none.
static bool isShuffleExtractingFromLHS(ShuffleVectorInst &SVI, SmallVector< int, 16 > &Mask)
static Instruction * hoistInsEltConst(InsertElementInst &InsElt2, InstCombiner::BuilderTy &Builder)
If we have an insertelement instruction feeding into another insertelement and the 2nd is inserting a...
Constant * getMask() const
StringRef getName() const
Return a constant reference to the value's name.
bool match(Val *V, const Pattern &P)
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 InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static ShuffleOps collectShuffleElements(Value *V, SmallVectorImpl< Constant * > &Mask, Value *PermittedRHS, InstCombiner &IC)
void setBit(unsigned BitPosition)
Set a given bit to 1.
This class represents the LLVM 'select' instruction.
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...
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
The core instruction combiner logic.
unsigned getBitWidth() const
Return the number of bits in the Vector type.
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 getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void assign(size_type NumElts, const T &Elt)
static Instruction * foldInsSequenceIntoBroadcast(InsertElementInst &InsElt)
VectorType * getType() const
Overload to return most specific vector type.
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.
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 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.
Instruction * visitExtractElementInst(ExtractElementInst &EI)
Type * getElementType() const
size_t size() const
size - Get the array size.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
iterator find(const_arg_type_t< KeyT > Val)
Instruction * visitInsertElementInst(InsertElementInst &IE)
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.
LLVM Basic Block Representation.
bool isExact() const
Determine whether the exact flag is set.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
self_iterator getIterator()
Class to represent integer types.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
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.
LLVMContext & getContext() const
All values hold a context through their type.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Value * SimplifyShuffleVectorInst(Value *Op0, Value *Op1, Constant *Mask, Type *RetTy, const SimplifyQuery &Q)
Given operands for a ShuffleVectorInst, fold the result or return null.
BinaryOps getOpcode() const
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
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...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, 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...
void setOperand(unsigned i, Value *Val)
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()
unsigned getVectorNumElements() const
llvm_unreachable("Unknown RegBank!")
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 int getMaskValue(Constant *Mask, unsigned Elt)
Return the shuffle mask value for the specified element of the mask.
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 Value * buildNew(Instruction *I, ArrayRef< Value * > NewOps)
Rebuild a new instruction just like 'I' but with the new operands given.
static IntegerType * getInt32Ty(LLVMContext &C)
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
Instruction * visitShuffleVectorInst(ShuffleVectorInst &SVI)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
VectorType * getType() const
Overload to return most specific vector type.
static bool isSplat(ArrayRef< Value * > VL)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &Q)
Given operands for an ExtractElementInst, fold the result or return null.
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.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static void recognizeIdentityMask(const SmallVectorImpl< int > &Mask, bool &isLHSID, bool &isRHSID)
static void getShuffleMask(Constant *Mask, SmallVectorImpl< int > &Result)
Convert the input shuffle mask operand to a vector of integers.
const BasicBlock * getParent() const
This instruction inserts a struct field of array element value into an aggregate value.