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 return replaceInstUsesWith(EI, V);
155 return replaceInstUsesWith(EI,
C->getAggregateElement(0U));
160 unsigned IndexVal = IdxC->getZExtValue();
164 assert(IndexVal < VectorWidth);
170 APInt UndefElts(VectorWidth, 0);
171 APInt DemandedMask(VectorWidth, 0);
172 DemandedMask.
setBit(IndexVal);
173 if (
Value *V = SimplifyDemandedVectorElts(EI.
getOperand(0), DemandedMask,
184 if (
VectorType *VT = dyn_cast<VectorType>(BCI->getOperand(0)->getType()))
185 if (VT->getNumElements() == VectorWidth)
203 if (
I->hasOneUse() &&
206 Builder->CreateExtractElement(BO->getOperand(0), EI.
getOperand(1),
209 Builder->CreateExtractElement(BO->getOperand(1), EI.
getOperand(1),
217 return replaceInstUsesWith(EI,
IE->getOperand(1));
220 if (isa<Constant>(
IE->getOperand(2)) && isa<Constant>(EI.
getOperand(1))) {
229 int SrcIdx = SVI->getMaskValue(Elt->getZExtValue());
236 if (SrcIdx < (
int)LHSWidth)
237 Src = SVI->getOperand(0);
240 Src = SVI->getOperand(1);
247 }
else if (
CastInst *CI = dyn_cast<CastInst>(
I)) {
251 if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast)) {
252 Value *EE = Builder->CreateExtractElement(CI->getOperand(0),
254 Worklist.AddValue(EE);
258 if (
SI->hasOneUse()) {
266 Value *TrueVal =
SI->getTrueValue();
267 Value *FalseVal =
SI->getFalseValue();
269 Value *Cond =
SI->getCondition();
271 Cond = Builder->CreateExtractElement(Cond,
277 = Builder->CreateExtractElement(TrueVal,
282 = Builder->CreateExtractElement(FalseVal,
288 SI->getName() +
".elt");
300 "Invalid CollectSingleShuffleElements");
303 if (isa<UndefValue>(V)) {
309 for (
unsigned i = 0;
i != NumElts; ++
i)
315 for (
unsigned i = 0;
i != NumElts; ++
i)
323 Value *VecOp = IEI->getOperand(0);
324 Value *ScalarOp = IEI->getOperand(1);
325 Value *IdxOp = IEI->getOperand(2);
327 if (!isa<ConstantInt>(IdxOp))
329 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
331 if (isa<UndefValue>(ScalarOp)) {
341 unsigned ExtractedIdx =
342 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
352 Mask[InsertedIdx % NumElts] =
357 Mask[InsertedIdx % NumElts] =
359 ExtractedIdx + NumLHSElts);
384 NumExtElts >= NumInsElts)
393 for (
unsigned i = 0;
i < NumExtElts; ++
i)
395 for (
unsigned i = NumExtElts;
i < NumInsElts; ++
i)
400 BasicBlock *InsertionBlock = (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
413 if (InsertionBlock != InsElt->
getParent())
431 if (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
432 WideVec->insertAfter(ExtVecOpInst);
465 if (isa<UndefValue>(V)) {
467 return std::make_pair(
471 if (isa<ConstantAggregateZero>(V)) {
473 return std::make_pair(V,
nullptr);
478 Value *VecOp = IEI->getOperand(0);
479 Value *ScalarOp = IEI->getOperand(1);
480 Value *IdxOp = IEI->getOperand(2);
483 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
484 unsigned ExtractedIdx =
485 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
486 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
490 if (EI->
getOperand(0) == PermittedRHS || PermittedRHS ==
nullptr) {
493 assert(LR.second ==
nullptr || LR.second == RHS);
495 if (LR.first->getType() != RHS->
getType()) {
502 for (
unsigned i = 0;
i < NumElts; ++
i)
504 return std::make_pair(V,
nullptr);
508 Mask[InsertedIdx % NumElts] =
510 NumLHSElts+ExtractedIdx);
511 return std::make_pair(LR.first, RHS);
514 if (VecOp == PermittedRHS) {
517 unsigned NumLHSElts =
519 for (
unsigned i = 0;
i != NumElts; ++
i)
522 i == InsertedIdx ? ExtractedIdx : NumLHSElts +
i));
523 return std::make_pair(EI->
getOperand(0), PermittedRHS);
531 return std::make_pair(EI->
getOperand(0), PermittedRHS);
537 for (
unsigned i = 0;
i != NumElts; ++
i)
539 return std::make_pair(V,
nullptr);
550 bool IsRedundant =
false;
564 if (UserInsInst->getIndices() == FirstIndices) {
573 return replaceInstUsesWith(I, I.
getOperand(0));
582 if (MaskSize != VecSize)
587 for (
int i = 0;
i != MaskSize; ++
i) {
589 if (Elt != -1 && Elt !=
i && Elt !=
i + VecSize)
611 if (NumElements == 1)
622 if (!Idx || CurrIE->
getOperand(1) != SplatVal)
626 if ((CurrIE != &InsElt) && !CurrIE->
hasOneUse())
634 if (
llvm::any_of(ElementPresent, [](
bool Present) {
return !Present; }))
654 if (!Inst || !Inst->hasOneUse())
656 if (
auto *Shuf = dyn_cast<ShuffleVectorInst>(InsElt.
getOperand(0))) {
659 Constant *ShufConstVec, *InsEltScalar;
660 uint64_t InsEltIndex;
686 for (
unsigned I = 0;
I != NumElts; ++
I) {
687 if (
I == InsEltIndex) {
688 NewShufElts[
I] = InsEltScalar;
703 }
else if (
auto *IEI = dyn_cast<InsertElementInst>(Inst)) {
708 uint64_t InsertIdx[2];
721 for (uint64_t
I : InsertIdx) {
731 for (
unsigned I = 0;
I < NumElts; ++
I) {
753 if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
754 replaceInstUsesWith(IE, VecOp);
759 if (isa<ConstantInt>(EI->
getOperand(1)) && isa<ConstantInt>(IdxOp)) {
761 unsigned NumExtractVectorElts =
763 unsigned ExtractedIdx =
764 cast<ConstantInt>(EI->
getOperand(1))->getZExtValue();
765 unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();
767 if (ExtractedIdx >= NumExtractVectorElts)
768 return replaceInstUsesWith(IE, VecOp);
770 if (InsertedIdx >= NumInsertVectorElts)
775 if (EI->
getOperand(0) == VecOp && ExtractedIdx == InsertedIdx)
776 return replaceInstUsesWith(IE, VecOp);
786 if (LR.first != &IE && LR.second != &IE) {
788 if (LR.second ==
nullptr)
798 APInt UndefElts(VWidth, 0);
800 if (
Value *V = SimplifyDemandedVectorElts(&IE, AllOnesEltMask, UndefElts)) {
802 return replaceInstUsesWith(IE, V);
820 unsigned Depth = 5) {
822 if (isa<Constant>(V))
827 if (!I)
return false;
833 if (
Depth == 0)
return false;
837 case Instruction::FAdd:
838 case Instruction::Sub:
839 case Instruction::FSub:
840 case Instruction::Mul:
841 case Instruction::FMul:
842 case Instruction::UDiv:
843 case Instruction::SDiv:
844 case Instruction::FDiv:
845 case Instruction::URem:
846 case Instruction::SRem:
847 case Instruction::FRem:
848 case Instruction::Shl:
849 case Instruction::LShr:
850 case Instruction::AShr:
854 case Instruction::ICmp:
855 case Instruction::FCmp:
856 case Instruction::Trunc:
857 case Instruction::ZExt:
858 case Instruction::SExt:
859 case Instruction::FPToUI:
860 case Instruction::FPToSI:
861 case Instruction::UIToFP:
862 case Instruction::SIToFP:
863 case Instruction::FPTrunc:
864 case Instruction::FPExt:
865 case Instruction::GetElementPtr: {
872 case Instruction::InsertElement: {
874 if (!CI)
return false;
879 bool SeenOnce =
false;
880 for (
int i = 0, e = Mask.
size();
i != e; ++
i) {
881 if (Mask[
i] == ElementNumber) {
900 case Instruction::FAdd:
901 case Instruction::Sub:
902 case Instruction::FSub:
903 case Instruction::Mul:
904 case Instruction::FMul:
905 case Instruction::UDiv:
906 case Instruction::SDiv:
907 case Instruction::FDiv:
908 case Instruction::URem:
909 case Instruction::SRem:
910 case Instruction::FRem:
911 case Instruction::Shl:
912 case Instruction::LShr:
913 case Instruction::AShr:
918 assert(NewOps.
size() == 2 &&
"binary operator with #ops != 2");
921 NewOps[0], NewOps[1],
"", BO);
922 if (isa<OverflowingBinaryOperator>(BO)) {
926 if (isa<PossiblyExactOperator>(BO)) {
927 New->setIsExact(BO->
isExact());
929 if (isa<FPMathOperator>(BO))
930 New->copyFastMathFlags(I);
933 case Instruction::ICmp:
934 assert(NewOps.
size() == 2 &&
"icmp with #ops != 2");
935 return new ICmpInst(I, cast<ICmpInst>(I)->getPredicate(),
936 NewOps[0], NewOps[1]);
937 case Instruction::FCmp:
938 assert(NewOps.
size() == 2 &&
"fcmp with #ops != 2");
939 return new FCmpInst(I, cast<FCmpInst>(I)->getPredicate(),
940 NewOps[0], NewOps[1]);
941 case Instruction::Trunc:
942 case Instruction::ZExt:
943 case Instruction::SExt:
944 case Instruction::FPToUI:
945 case Instruction::FPToSI:
946 case Instruction::UIToFP:
947 case Instruction::SIToFP:
948 case Instruction::FPTrunc:
949 case Instruction::FPExt: {
954 NewOps[0]->getType()->getVectorNumElements());
955 assert(NewOps.
size() == 1 &&
"cast with #ops != 1");
959 case Instruction::GetElementPtr: {
963 cast<GetElementPtrInst>(I)->getSourceElementType(), Ptr, Idx,
"", I);
964 GEP->
setIsInBounds(cast<GetElementPtrInst>(I)->isInBounds());
976 if (isa<UndefValue>(V)) {
980 if (isa<ConstantAggregateZero>(V)) {
985 if (
Constant *
C = dyn_cast<Constant>(V)) {
987 for (
int i = 0, e = Mask.
size();
i != e; ++
i) {
991 MaskValues.
push_back(Builder->getInt32(Mask[
i]));
1000 case Instruction::FAdd:
1001 case Instruction::Sub:
1002 case Instruction::FSub:
1003 case Instruction::Mul:
1004 case Instruction::FMul:
1005 case Instruction::UDiv:
1006 case Instruction::SDiv:
1007 case Instruction::FDiv:
1008 case Instruction::URem:
1009 case Instruction::SRem:
1010 case Instruction::FRem:
1011 case Instruction::Shl:
1012 case Instruction::LShr:
1013 case Instruction::AShr:
1017 case Instruction::ICmp:
1018 case Instruction::FCmp:
1019 case Instruction::Trunc:
1020 case Instruction::ZExt:
1021 case Instruction::SExt:
1022 case Instruction::FPToUI:
1023 case Instruction::FPToSI:
1024 case Instruction::UIToFP:
1025 case Instruction::SIToFP:
1026 case Instruction::FPTrunc:
1027 case Instruction::FPExt:
1029 case Instruction::GetElementPtr: {
1042 case Instruction::InsertElement: {
1043 int Element = cast<ConstantInt>(I->
getOperand(2))->getLimitedValue();
1050 for (
int e = Mask.
size(); Index != e; ++Index) {
1051 if (Mask[Index] == Element) {
1064 Builder->getInt32(Index),
"",
I);
1071 bool &isLHSID,
bool &isRHSID) {
1072 isLHSID = isRHSID =
true;
1074 for (
unsigned i = 0, e = Mask.
size();
i != e; ++
i) {
1075 if (Mask[
i] < 0)
continue;
1077 isLHSID &= (Mask[
i] == (int)
i);
1080 isRHSID &= (Mask[
i]-e ==
i);
1093 unsigned MaskElems = Mask.
size();
1094 unsigned BegIdx = Mask.
front();
1095 unsigned EndIdx = Mask.
back();
1096 if (BegIdx > EndIdx || EndIdx >= LHSElems || EndIdx - BegIdx != MaskElems - 1)
1098 for (
unsigned I = 0; I != MaskElems; ++
I)
1099 if (static_cast<unsigned>(Mask[I]) != BegIdx + I)
1110 bool MadeChange =
false;
1118 APInt UndefElts(VWidth, 0);
1120 if (
Value *V = SimplifyDemandedVectorElts(&SVI, AllOnesEltMask, UndefElts)) {
1122 return replaceInstUsesWith(SVI, V);
1132 if (LHS == RHS || isa<UndefValue>(LHS)) {
1133 if (isa<UndefValue>(LHS) && LHS == RHS) {
1135 Value *Result = (VWidth == LHSWidth)
1137 return replaceInstUsesWith(SVI, Result);
1142 for (
unsigned i = 0, e = LHSWidth;
i != VWidth; ++
i) {
1148 if ((Mask[
i] >= (
int)e && isa<UndefValue>(RHS)) ||
1149 (Mask[
i] < (
int)e && isa<UndefValue>(LHS))) {
1153 Mask[
i] = Mask[
i] % e;
1165 if (VWidth == LHSWidth) {
1167 bool isLHSID, isRHSID;
1171 if (isLHSID)
return replaceInstUsesWith(SVI, LHS);
1172 if (isRHSID)
return replaceInstUsesWith(SVI, RHS);
1176 Value *V = EvaluateInDifferentElementOrder(LHS, Mask);
1177 return replaceInstUsesWith(SVI, V);
1211 unsigned MaskElems = Mask.
size();
1212 unsigned BegIdx = Mask.
front();
1215 unsigned SrcElemBitWidth = DL.getTypeSizeInBits(SrcTy->
getElementType());
1216 assert(SrcElemBitWidth &&
"vector elements must have a bitwidth");
1222 if (!BC->use_empty())
1226 Type *TgtTy = BC->getDestTy();
1227 unsigned TgtElemBitWidth = DL.getTypeSizeInBits(TgtTy);
1228 if (!TgtElemBitWidth)
1230 unsigned TgtNumElems = VecBitWidth / TgtElemBitWidth;
1231 bool VecBitWidthsEqual = VecBitWidth == TgtNumElems * TgtElemBitWidth;
1232 bool BegIsAligned = 0 == ((SrcElemBitWidth * BegIdx) % TgtElemBitWidth);
1233 if (!VecBitWidthsEqual)
1238 if (!BegIsAligned) {
1243 for (
unsigned I = 0,
E = MaskElems, Idx = BegIdx; I !=
E; ++Idx, ++
I)
1250 unsigned SrcElemsPerTgtElem = TgtElemBitWidth / SrcElemBitWidth;
1251 assert(SrcElemsPerTgtElem);
1252 BegIdx /= SrcElemsPerTgtElem;
1253 bool BCAlreadyExists = NewBCs.
find(CastSrcTy) != NewBCs.
end();
1257 : Builder->CreateBitCast(V, CastSrcTy, SVI.
getName() +
".bc");
1258 if (!BCAlreadyExists)
1259 NewBCs[CastSrcTy] = NewBC;
1260 auto *
Ext = Builder->CreateExtractElement(
1264 replaceInstUsesWith(*BC,
Ext);
1315 if (!isa<UndefValue>(LHSShuffle->
getOperand(1)) && !isa<UndefValue>(RHS))
1316 LHSShuffle =
nullptr;
1318 if (!isa<UndefValue>(RHSShuffle->getOperand(1)))
1319 RHSShuffle =
nullptr;
1320 if (!LHSShuffle && !RHSShuffle)
1321 return MadeChange ? &SVI :
nullptr;
1323 Value* LHSOp0 =
nullptr;
1324 Value* LHSOp1 =
nullptr;
1325 Value* RHSOp0 =
nullptr;
1326 unsigned LHSOp0Width = 0;
1327 unsigned RHSOp0Width = 0;
1334 RHSOp0 = RHSShuffle->getOperand(0);
1337 Value* newLHS = LHS;
1338 Value* newRHS = RHS;
1341 if (isa<UndefValue>(RHS)) {
1346 else if (LHSOp0Width == LHSWidth) {
1351 if (RHSShuffle && RHSOp0Width == LHSWidth) {
1355 if (LHSOp0 == RHSOp0) {
1360 if (newLHS == LHS && newRHS == RHS)
1361 return MadeChange ? &SVI :
nullptr;
1367 if (RHSShuffle && newRHS != RHS)
1368 RHSMask = RHSShuffle->getShuffleMask();
1370 unsigned newLHSWidth = (newLHS != LHS) ? LHSOp0Width : LHSWidth;
1376 for (
unsigned i = 0;
i < VWidth; ++
i) {
1381 }
else if (Mask[
i] < (
int)LHSWidth) {
1386 if (newLHS != LHS) {
1387 eltMask = LHSMask[Mask[
i]];
1390 if (eltMask >= (
int)LHSOp0Width && isa<UndefValue>(LHSOp1))
1399 if (isa<UndefValue>(RHS))
1403 else if (newRHS != RHS) {
1404 eltMask = RHSMask[Mask[
i]-LHSWidth];
1407 if (eltMask >= (
int)RHSOp0Width) {
1408 assert(isa<UndefValue>(RHSShuffle->getOperand(1))
1409 &&
"should have been check above");
1413 eltMask = Mask[
i]-LHSWidth;
1421 if (eltMask >= 0 && newRHS !=
nullptr && newLHS != newRHS)
1422 eltMask += newLHSWidth;
1427 if (SplatElt >= 0 && SplatElt != eltMask)
1437 if (isSplat || newMask == LHSMask || newMask == RHSMask || newMask == Mask) {
1439 for (
unsigned i = 0, e = newMask.
size();
i != e; ++
i) {
1440 if (newMask[
i] < 0) {
1453 bool isLHSID, isRHSID;
1455 if (isLHSID && VWidth == LHSOp0Width)
return replaceInstUsesWith(SVI, newLHS);
1456 if (isRHSID && VWidth == RHSOp0Width)
return replaceInstUsesWith(SVI, newRHS);
1458 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.
This class is the base class for the comparison instructions.
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.
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...
void setBit(unsigned bitPosition)
Set a given bit to 1.
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)
const_iterator begin(StringRef path)
Get begin iterator over path.
const Function * getParent() const
Return the enclosing method, or null if none.
static bool isShuffleExtractingFromLHS(ShuffleVectorInst &SVI, SmallVector< int, 16 > &Mask)
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)
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)
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 * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Type * getElementType() const
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
unsigned getNumIncomingValues() const
Return the number of incoming edges.
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.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
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...
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)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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...
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...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void setOperand(unsigned i, Value *Val)
Class to represent vector types.
Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an ExtractElementInst, fold the result or return null.
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
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
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.
iterator find(const KeyT &Val)
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.
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.
static void recognizeIdentityMask(const SmallVectorImpl< int > &Mask, bool &isLHSID, bool &isRHSID)
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
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.