22 using namespace PatternMatch;
24 #define DEBUG_TYPE "instcombine"
86 case Instruction::Mul:
87 case Instruction::And:
89 case Instruction::Xor:
91 case Instruction::Sub:
92 case Instruction::Shl:
93 case Instruction::LShr:
94 case Instruction::AShr:
107 case Instruction::Sub:
108 case Instruction::Or:
109 case Instruction::Xor:
110 case Instruction::Shl:
111 case Instruction::LShr:
112 case Instruction::AShr:
114 case Instruction::And:
116 case Instruction::Mul:
157 if (TI->
getOpcode() != Instruction::BitCast &&
185 Value *MatchOp, *OtherOpT, *OtherOpF;
191 MatchIsOpZero =
true;
196 MatchIsOpZero =
false;
203 MatchIsOpZero =
true;
208 MatchIsOpZero =
true;
216 Value *Op0 = MatchIsOpZero ? MatchOp : NewSI;
217 Value *Op1 = MatchIsOpZero ? NewSI : MatchOp;
240 if (
Instruction *TVI = dyn_cast<Instruction>(TrueVal)) {
241 if (TVI->hasOneUse() && TVI->getNumOperands() == 2 &&
242 !isa<Constant>(FalseVal)) {
244 unsigned OpToFold = 0;
245 if ((SFO & 1) && FalseVal == TVI->getOperand(0)) {
247 }
else if ((SFO & 2) && FalseVal == TVI->getOperand(1)) {
253 Value *OOp = TVI->getOperand(2-OpToFold);
256 if (!isa<Constant>(OOp) ||
isSelect01(C, cast<Constant>(OOp))) {
270 if (
Instruction *FVI = dyn_cast<Instruction>(FalseVal)) {
271 if (FVI->hasOneUse() && FVI->getNumOperands() == 2 &&
272 !isa<Constant>(TrueVal)) {
274 unsigned OpToFold = 0;
275 if ((SFO & 1) && TrueVal == FVI->getOperand(0)) {
277 }
else if ((SFO & 2) && TrueVal == FVI->getOperand(1)) {
283 Value *OOp = FVI->getOperand(2-OpToFold);
286 if (!isa<Constant>(OOp) ||
isSelect01(C, cast<Constant>(OOp))) {
360 bool OrOnTrueVal =
false;
365 if (!OrOnFalseVal && !OrOnTrueVal)
368 Value *
Y = OrOnFalseVal ? TrueVal : FalseVal;
372 bool NeedXor = (!IsEqualZero && OrOnFalseVal) || (IsEqualZero && OrOnTrueVal);
373 bool NeedShift = C1Log != C2Log;
378 Value *Or = OrOnFalseVal ? FalseVal : TrueVal;
379 if ((NeedShift + NeedXor + NeedZExtTrunc) >
392 }
else if (C1Log > C2Log) {
426 Value *Count = FalseVal;
427 Value *ValueOnZero = TrueVal;
450 Type *Ty = NewI->getArgOperand(1)->getType();
491 if ((CmpLHS == TrueVal && AdjustedRHS == FalseVal) ||
492 (CmpLHS == FalseVal && AdjustedRHS == TrueVal)) {
507 AdjustedRHS = SextRHS;
509 SextRHS == TrueVal) {
511 AdjustedRHS = SextRHS;
520 AdjustedRHS = ZextRHS;
522 ZextRHS == TrueVal) {
524 AdjustedRHS = ZextRHS;
536 CmpRHS = AdjustedRHS;
573 default:
return nullptr;
590 "Unexpected results from matchSelectPattern");
600 if (
Instruction *NewSel = canonicalizeMinMaxWithConstant(SI, *ICI, Builder))
603 bool Changed = adjustMinMax(SI, *ICI);
617 if (TrueVal->
getType() == Ty) {
618 if (
ConstantInt *Cmp = dyn_cast<ConstantInt>(CmpRHS)) {
632 if (C2->isMinusOne())
633 return replaceInstUsesWith(SI, Builder.
CreateOr(AShr, C1));
636 return replaceInstUsesWith(SI, Builder.
CreateAdd(And, C1));
644 if (CmpRHS != CmpLHS && isa<Constant>(CmpRHS)) {
665 bool IsBitTest =
false;
675 TrueWhenUnset =
false;
680 TrueWhenUnset =
true;
685 if (TrueWhenUnset && TrueVal == X &&
689 else if (!TrueWhenUnset && FalseVal == X &&
693 else if (TrueWhenUnset && FalseVal == X &&
697 else if (!TrueWhenUnset && TrueVal == X &&
702 return replaceInstUsesWith(SI, V);
707 return replaceInstUsesWith(SI, V);
709 if (
Value *V = foldSelectCttzCtlz(ICI, TrueVal, FalseVal, Builder))
710 return replaceInstUsesWith(SI, V);
712 return Changed ? &SI :
nullptr;
726 static bool canSelectOperandBeMappingIntoPredBlock(
const Value *V,
737 if (
const PHINode *VP = dyn_cast<PHINode>(I))
738 if (VP->getParent() == CondPHI->
getParent())
762 if (C == A || C == B) {
766 return replaceInstUsesWith(Outer, Inner);
774 return replaceInstUsesWith(Outer, C);
778 const APInt *CB, *CC;
786 return replaceInstUsesWith(Outer, Inner);
803 return replaceInstUsesWith(Outer, Inner);
814 return replaceInstUsesWith(Outer, NewSI);
817 auto IsFreeOrProfitableToInvert =
818 [&](
Value *V,
Value *&NotV,
bool &ElidesXor) {
834 Value *NotA, *NotB, *NotC;
835 bool ElidesXor =
false;
847 IsFreeOrProfitableToInvert(A, NotA, ElidesXor) &&
848 IsFreeOrProfitableToInvert(B, NotB, ElidesXor) &&
849 IsFreeOrProfitableToInvert(C, NotC, ElidesXor) && ElidesXor) {
861 return replaceInstUsesWith(Outer, NewOuter);
891 if ((TrueVal - FalseVal).isPowerOf2())
893 else if ((FalseVal - TrueVal).isPowerOf2())
911 unsigned ValZeros = ValC.
logBase2();
921 if (ValZeros > AndZeros)
922 V = Builder.
CreateShl(V, ValZeros - AndZeros);
923 else if (ValZeros < AndZeros)
924 V = Builder.
CreateLShr(V, AndZeros - ValZeros);
934 if (!
Offset.isNullValue())
948 if (!TI || !FI || !TI->
hasOneUse() || !FI->hasOneUse())
952 if ((TI->
getOpcode() == Instruction::Sub &&
955 FI->getOpcode() == Instruction::FAdd)) {
958 }
else if ((FI->getOpcode() == Instruction::Sub &&
960 (FI->getOpcode() == Instruction::FSub &&
967 Value *OtherAddOp =
nullptr;
968 if (SubOp->getOperand(0) == AddOp->
getOperand(0)) {
970 }
else if (SubOp->getOperand(0) == AddOp->
getOperand(1)) {
979 NegVal = Builder.
CreateFNeg(SubOp->getOperand(1));
980 if (
Instruction *NegInst = dyn_cast<Instruction>(NegVal)) {
982 Flags &= SubOp->getFastMathFlags();
983 NegInst->setFastMathFlags(Flags);
986 NegVal = Builder.
CreateNeg(SubOp->getOperand(1));
989 Value *NewTrueOp = OtherAddOp;
990 Value *NewFalseOp = NegVal;
998 BinaryOperator::CreateFAdd(SubOp->getOperand(0), NewSel);
1001 Flags &= SubOp->getFastMathFlags();
1018 if (ExtOpcode != Instruction::ZExt && ExtOpcode != Instruction::SExt)
1039 Value *TruncCVal = cast<Value>(TruncC);
1081 for (
unsigned i = 0; i != NumElts; ++i) {
1092 }
else if (isa<UndefValue>(Elt)) {
1123 if (TVal == A || TVal == B || FVal == A || FVal == B)
1140 if (TSrc == C && FSrc == D) {
1144 }
else if (TSrc == D && FSrc == C) {
1161 SQ.getWithInstruction(&SI)))
1162 return replaceInstUsesWith(SI, V);
1164 if (
Instruction *I = canonicalizeSelectToShuffle(SI))
1175 CmpInst *Cond = cast<CmpInst>(CondVal);
1188 return BinaryOperator::CreateOr(CondVal, FalseVal);
1193 return BinaryOperator::CreateAnd(NotCond, FalseVal);
1197 return BinaryOperator::CreateAnd(CondVal, TrueVal);
1202 return BinaryOperator::CreateOr(NotCond, TrueVal);
1207 if (CondVal == TrueVal)
1208 return BinaryOperator::CreateOr(CondVal, FalseVal);
1209 if (CondVal == FalseVal)
1210 return BinaryOperator::CreateAnd(CondVal, TrueVal);
1215 return BinaryOperator::CreateAnd(TrueVal, FalseVal);
1217 return BinaryOperator::CreateOr(TrueVal, FalseVal);
1230 return new ZExtInst(CondVal, SelType);
1234 return new SExtInst(CondVal, SelType);
1239 return new ZExtInst(NotCond, SelType);
1245 return new SExtInst(NotCond, SelType);
1249 if (
ConstantInt *TrueValC = dyn_cast<ConstantInt>(TrueVal))
1250 if (
ConstantInt *FalseValC = dyn_cast<ConstantInt>(FalseVal))
1251 if (
Value *V = foldSelectICmpAnd(SI, TrueValC->getValue(),
1252 FalseValC->getValue(), Builder))
1253 return replaceInstUsesWith(SI, V);
1256 if (
FCmpInst *FCI = dyn_cast<FCmpInst>(CondVal)) {
1257 if (FCI->getOperand(0) == TrueVal && FCI->getOperand(1) == FalseVal) {
1264 if (((CFPt = dyn_cast<ConstantFP>(TrueVal)) &&
1266 ((CFPf = dyn_cast<ConstantFP>(FalseVal)) &&
1268 return replaceInstUsesWith(SI, FalseVal);
1276 if (((CFPt = dyn_cast<ConstantFP>(TrueVal)) &&
1278 ((CFPf = dyn_cast<ConstantFP>(FalseVal)) &&
1280 return replaceInstUsesWith(SI, TrueVal);
1300 }
else if (FCI->getOperand(0) == FalseVal && FCI->getOperand(1) == TrueVal){
1307 if (((CFPt = dyn_cast<ConstantFP>(TrueVal)) &&
1309 ((CFPf = dyn_cast<ConstantFP>(FalseVal)) &&
1311 return replaceInstUsesWith(SI, FalseVal);
1319 if (((CFPt = dyn_cast<ConstantFP>(TrueVal)) &&
1321 ((CFPf = dyn_cast<ConstantFP>(FalseVal)) &&
1323 return replaceInstUsesWith(SI, TrueVal);
1348 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(CondVal))
1349 if (
Instruction *Result = foldSelectInstWithICmp(SI, ICI))
1358 if (TI && FI && TI->
getOpcode() == FI->getOpcode())
1367 if (
Instruction *FoldI = foldSelectIntoOp(SI, TrueVal, FalseVal))
1370 Value *LHS, *RHS, *LHS2, *RHS2;
1386 auto FMF = cast<FPMathOperator>(SI.
getCondition())->getFastMathFlags();
1394 return replaceInstUsesWith(SI, NewSI);
1406 if (
Instruction *R = foldSPFofSPF(cast<Instruction>(LHS),SPF2,LHS2,RHS2,
1410 if (
Instruction *R = foldSPFofSPF(cast<Instruction>(RHS),SPF2,LHS2,RHS2,
1426 if (NumberOfNots >= 2) {
1433 return replaceInstUsesWith(SI, NewSI);
1444 if (canSelectOperandBeMappingIntoPredBlock(TrueVal, SI) &&
1445 canSelectOperandBeMappingIntoPredBlock(FalseVal, SI))
1449 if (
SelectInst *TrueSI = dyn_cast<SelectInst>(TrueVal)) {
1450 if (TrueSI->getCondition()->getType() == CondVal->
getType()) {
1452 if (TrueSI->getCondition() == CondVal) {
1461 if (TrueSI->getFalseValue() == FalseVal && TrueSI->
hasOneUse()) {
1469 if (
SelectInst *FalseSI = dyn_cast<SelectInst>(FalseVal)) {
1470 if (FalseSI->getCondition()->getType() == CondVal->
getType()) {
1472 if (FalseSI->getCondition() == CondVal) {
1479 if (FalseSI->getTrueValue() == TrueVal && FalseSI->
hasOneUse()) {
1480 Value *Or = Builder.
CreateOr(CondVal, FalseSI->getCondition());
1495 if (
VectorType *VecTy = dyn_cast<VectorType>(SelType)) {
1496 unsigned VWidth = VecTy->getNumElements();
1497 APInt UndefElts(VWidth, 0);
1499 if (
Value *V = SimplifyDemandedVectorElts(&SI, AllOnesEltMask, UndefElts)) {
1501 return replaceInstUsesWith(SI, V);
1505 if (isa<ConstantAggregateZero>(CondVal)) {
1506 return replaceInstUsesWith(SI, FalseVal);
1514 auto *PBI = dyn_cast_or_null<BranchInst>(Dom->getTerminator());
1515 if (PBI && PBI->isConditional() &&
1516 PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
1517 (PBI->getSuccessor(0) == Parent || PBI->getSuccessor(1) == Parent)) {
1518 bool CondIsFalse = PBI->getSuccessor(1) == Parent;
1522 Value *V = *Implication ? TrueVal : FalseVal;
1523 return replaceInstUsesWith(SI, V);
1536 if (Known.One.isOneValue())
1537 return replaceInstUsesWith(SI, TrueVal);
1538 if (Known.Zero.isOneValue())
1539 return replaceInstUsesWith(SI, FalseVal);
1542 if (
Instruction *BitCastSel = foldSelectCmpBitcasts(SI, Builder))
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
void push_back(const T &Elt)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
This class is the base class for the comparison instructions.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
DiagnosticInfoOptimizationBase::Argument NV
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
match_zero m_Zero()
Match an arbitrary zero/null constant.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
This class represents zero extension of integer types.
unsigned getNumOperands() const
bool isOneValue() const
Returns true if the value is one.
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
static Value * foldSelectICmpAndOr(const SelectInst &SI, Value *TrueVal, Value *FalseVal, InstCombiner::BuilderTy &Builder)
We want to turn: (select (icmp eq (and X, C1), 0), Y, (or Y, C2)) into: (or (shl (and X...
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
static bool isCanonicalPredicate(CmpInst::Predicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
0 1 0 0 True if ordered and less than
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)
1 1 1 0 True if unordered or not equal
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
This class represents a sign extension of integer types.
void reserve(size_type N)
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 isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool Ordered
Only applicable if Flavor is SPF_FMINNUM or SPF_FMAXNUM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
Value * CreateNot(Value *V, const Twine &Name="")
bool match(Val *V, const Pattern &P)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
This class represents the LLVM 'select' instruction.
const APInt & getValue() const
Return the constant as an APInt value reference.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static SelectPatternFlavor getInverseMinMaxSelectPattern(SelectPatternFlavor SPF)
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
not_match< LHS > m_Not(const LHS &L)
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
This instruction compares its operands according to the predicate given to the constructor.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power of 2.
void takeName(Value *V)
Transfer the name from V to this value.
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
static const Value * getNotArgument(const Value *BinOp)
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Value * SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q)
Given operands for a SelectInst, fold the result or return null.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
LLVM Basic Block Representation.
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)
bool isVectorTy() const
True if this is an instance of VectorType.
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
bool isEquality() const
Return true if this predicate is either EQ or NE.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
const Value * getCondition() const
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
ConstantFP - Floating Point Values [float, double].
bool isIntPredicate() const
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.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Value * getOperand(unsigned i) const
bool isCommutative() const
Return true if the instruction is commutative:
static bool isNot(const Value *V)
unsigned getIntegerBitWidth() const
Class to represent integer types.
Predicate getPredicate() const
Return the predicate for this instruction.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
LLVMContext & getContext() const
All values hold a context through their type.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
This is the shared class of boolean and integer constants.
SelectPatternFlavor Flavor
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
unsigned logBase2() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
1 1 0 0 True if unordered or less than
Type * getType() const
All values are typed, get the type of this value.
SelectPatternFlavor
Specific patterns of select instructions we can match.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static ConstantInt * getTrue(LLVMContext &Context)
Instruction * visitSelectInst(SelectInst &SI)
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
void setOperand(unsigned i, Value *Val)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
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.
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
void setCondition(Value *V)
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
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 setTrueValue(Value *V)
static IntegerType * getInt32Ty(LLVMContext &C)
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
match_one m_One()
Match an integer 1 or a vector with all elements equal to 1.
bool hasOneUse() const
Return true if there is exactly one user of this value.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
static Value * generateMinMaxSelectPattern(InstCombiner::BuilderTy &Builder, SelectPatternFlavor SPF, Value *A, Value *B)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void setFalseValue(Value *V)
1 0 1 0 True if unordered or greater than
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
static Constant * getSelectFoldableConstant(Instruction *I)
For the same transformation as the previous function, return the identity constant that goes into the...
const APFloat & getValueAPF() const
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
match_all_ones m_AllOnes()
Match an integer or vector with all bits set to true.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
static CmpInst::Predicate getCmpPredicateForMinMax(SelectPatternFlavor SPF, bool Ordered=false)
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 unsigned getSelectFoldableOperands(Instruction *I)
We want to turn code that looks like this: C = or A, B D = select cond, C, A into: C = select cond...
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.
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
static bool isSelect01(Constant *C1, Constant *C2)
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsFalse=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if RHS is known to be implied true by LHS.
const Value * getFalseValue() const
Convenience struct for specifying and reasoning about fast-math flags.
bool isNullValue() const
Determine if all bits are clear.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
const BasicBlock * getParent() const
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
A wrapper class for inspecting calls to intrinsic functions.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
bool slt(const APInt &RHS) const
Signed less than comparison.