45 #define DEBUG_TYPE "instcombine" 57 bool MadeChange =
false;
61 Value *A =
nullptr, *
B =
nullptr, *One =
nullptr;
95 return MadeChange ? V :
nullptr;
116 if (isa<UndefValue>(Elt)) {
130 SQ.getWithInstruction(&I)))
131 return replaceInstUsesWith(I, V);
133 if (SimplifyAssociativeOrCommutative(I))
139 if (
Value *V = SimplifyUsingDistributiveLaws(I))
140 return replaceInstUsesWith(I, V);
164 BO->setHasNoUnsignedWrap();
167 BO->setHasNoSignedWrap();
189 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
194 const APInt & Val = CI->getValue();
197 Value *
X =
nullptr, *
Y =
nullptr;
200 Value *Sub =
nullptr;
202 Sub = Builder.CreateSub(X,
Y,
"suba");
204 Sub = Builder.CreateSub(Builder.CreateNeg(C1),
Y,
"subc");
214 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
218 if (isa<Constant>(Op1)) {
223 Value *Mul = Builder.CreateMul(C1, Op1);
241 cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap() &&
242 cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap())
243 NewMul->setHasNoSignedWrap();
257 if (!Div || (Div->
getOpcode() != Instruction::UDiv &&
258 Div->
getOpcode() != Instruction::SDiv)) {
262 Value *Neg = dyn_castNegVal(Y);
265 (Div->
getOpcode() == Instruction::UDiv ||
266 Div->
getOpcode() == Instruction::SDiv)) {
272 return replaceInstUsesWith(I, X);
276 auto RemOpc = Div->
getOpcode() == Instruction::UDiv ? Instruction::URem
278 Value *Rem = Builder.CreateBinOp(RemOpc, X, DivOp1);
280 return BinaryOperator::CreateSub(X, Rem);
281 return BinaryOperator::CreateSub(Rem, X);
287 return BinaryOperator::CreateAnd(Op0, Op1);
296 BO = BinaryOperator::CreateShl(Op1, Y);
297 ShlNSW = cast<ShlOperator>(Op0)->hasNoSignedWrap();
299 BO = BinaryOperator::CreateShl(Op0, Y);
300 ShlNSW = cast<ShlOperator>(Op1)->hasNoSignedWrap();
326 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op1);
328 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op0);
333 bool Changed =
false;
344 return Changed ? &
I :
nullptr;
350 SQ.getWithInstruction(&I)))
351 return replaceInstUsesWith(I, V);
353 if (SimplifyAssociativeOrCommutative(I))
359 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
386 if (Op0 == Op1 &&
match(Op0, m_Intrinsic<Intrinsic::fabs>(
m_Value(X))))
390 if (
Value *V = SimplifySelectsFeedingBinaryOp(I, Op0, Op1))
391 return replaceInstUsesWith(I, V);
423 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
429 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
440 Value *XY = Builder.CreateFMulFMF(X, Y, &I);
442 return replaceInstUsesWith(I, Sqrt);
454 Value *XX = Builder.CreateFMulFMF(Op1, Op1, &I);
459 Value *XX = Builder.CreateFMulFMF(Op0, Op0, &I);
469 Log2 = cast<IntrinsicInst>(Op0);
474 Log2 = cast<IntrinsicInst>(Op1);
480 Value *LogXTimesY = Builder.CreateFMulFMF(Log2, Y, &I);
524 while (BBI != BBFront) {
537 }
else if (*I == SelectCond) {
547 if (&*BBI == SelectCond)
548 SelectCond =
nullptr;
551 if (!SelectCond && !SI)
562 Product = IsSigned ? C1.
smul_ov(C2, Overflow) : C1.
umul_ov(C2, Overflow);
585 return Remainder.isMinValue();
594 bool IsSigned = I.
getOpcode() == Instruction::SDiv;
605 if (simplifyDivRemOfSelectWithZeroOp(I))
627 if (
isMultiple(*C2, *C1, Quotient, IsSigned)) {
635 if (
isMultiple(*C1, *C2, Quotient, IsSigned)) {
638 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
639 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
640 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
653 if (
isMultiple(*C2, C1Shifted, Quotient, IsSigned)) {
661 if (
isMultiple(C1Shifted, *C2, Quotient, IsSigned)) {
664 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
665 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
666 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
672 if (
Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(I))
682 Value *Inc = Builder.CreateAdd(Op1, Op0);
688 return new ZExtInst(Builder.CreateICmpEQ(Op1, Op0), Ty);
693 if (SimplifyDemandedInstructionBits(I))
712 bool HasNSW = cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap();
713 bool HasNUW = cast<OverflowingBinaryOperator>(Op1)->hasNoUnsignedWrap();
714 if ((IsSigned && HasNSW) || (!IsSigned && HasNUW)) {
733 struct UDivFoldAction {
736 FoldUDivOperandCb FoldAction;
739 Value *OperandToFold;
749 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand)
750 : FoldAction(FA), OperandToFold(InputOperand), FoldResult(
nullptr) {}
751 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand,
size_t SLHS)
752 : FoldAction(FA), OperandToFold(InputOperand), SelectLHSIdx(SLHS) {}
785 if (Op1 != ShiftLeft)
799 unsigned Depth = 0) {
804 return Actions.
size();
811 return Actions.
size();
815 if (
Depth++ == MaxDepth)
822 Actions.push_back(UDivFoldAction(
nullptr, Op1, LHSIdx - 1));
823 return Actions.size();
868 SQ.getWithInstruction(&I)))
869 return replaceInstUsesWith(I, V);
880 const APInt *C1, *C2;
899 Value *Cmp = Builder.CreateICmpUGE(Op0, Op1);
920 return BinaryOperator::CreateUDiv(B, X);
923 return BinaryOperator::CreateUDiv(A, X);
929 for (
unsigned i = 0, e = UDivActions.
size(); i != e; ++i) {
930 FoldUDivOperandCb Action = UDivActions[i].FoldAction;
931 Value *ActionOp1 = UDivActions[i].OperandToFold;
934 Inst = Action(Op0, ActionOp1, I, *
this);
939 size_t SelectRHSIdx = i - 1;
940 Value *SelectRHS = UDivActions[SelectRHSIdx].FoldResult;
941 size_t SelectLHSIdx = UDivActions[i].SelectLHSIdx;
942 Value *SelectLHS = UDivActions[SelectLHSIdx].FoldResult;
944 SelectLHS, SelectRHS);
952 UDivActions[i].FoldResult = Inst;
962 SQ.getWithInstruction(&I)))
963 return replaceInstUsesWith(I, V);
985 return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.
getName());
1001 Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
1006 if (
Constant *RHS = dyn_cast<Constant>(Op1)) {
1008 if (RHS->isMinSignedValue())
1026 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1036 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1067 if (!RecipC->isNormalFP())
1110 SQ.getWithInstruction(&I)))
1111 return replaceInstUsesWith(I, V);
1123 if (isa<Constant>(Op0))
1128 if (isa<Constant>(Op1))
1136 (!isa<Constant>(
Y) || !isa<Constant>(Op1))) {
1138 Value *YZ = Builder.CreateFMulFMF(Y, Op1, &I);
1142 (!isa<Constant>(Y) || !isa<Constant>(Op0))) {
1144 Value *YZ = Builder.CreateFMulFMF(Y, Op0, &I);
1153 bool IsTan =
match(Op0, m_Intrinsic<Intrinsic::sin>(
m_Value(X))) &&
1156 !IsTan &&
match(Op0, m_Intrinsic<Intrinsic::cos>(
m_Value(X))) &&
1160 LibFunc_tanf, LibFunc_tanl)) {
1166 LibFunc_tanl, B, Attrs);
1169 return replaceInstUsesWith(I, Res);
1208 if (simplifyDivRemOfSelectWithZeroOp(I))
1211 if (isa<Constant>(Op1)) {
1212 if (
Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
1216 }
else if (
auto *PN = dyn_cast<PHINode>(Op0I)) {
1217 const APInt *Op1Int;
1230 if (SimplifyDemandedInstructionBits(I))
1240 SQ.getWithInstruction(&I)))
1241 return replaceInstUsesWith(I, V);
1246 if (
Instruction *common = commonIRemTransforms(I))
1257 Value *
Add = Builder.CreateAdd(Op1, N1);
1258 return BinaryOperator::CreateAnd(Op0, Add);
1267 Value *Cmp = Builder.CreateICmpULT(Op0, Op1);
1268 Value *Sub = Builder.CreateSub(Op0, Op1);
1287 SQ.getWithInstruction(&I)))
1288 return replaceInstUsesWith(I, V);
1294 if (
Instruction *Common = commonIRemTransforms(I))
1314 return BinaryOperator::CreateURem(Op0, Op1, I.
getName());
1318 if (isa<ConstantVector>(Op1) || isa<ConstantDataVector>(Op1)) {
1322 bool hasNegative =
false;
1323 bool hasMissing =
false;
1324 for (
unsigned i = 0; i != VWidth; ++i) {
1331 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elt))
1332 if (RHS->isNegative())
1336 if (hasNegative && !hasMissing) {
1338 for (
unsigned i = 0; i != VWidth; ++i) {
1340 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elts[i])) {
1341 if (RHS->isNegative())
1361 SQ.getWithInstruction(&I)))
1362 return replaceInstUsesWith(I, V);
APInt abs() const
Get the absolute value;.
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
static Instruction * foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I, InstCombiner &IC)
Instruction * visitSDiv(BinaryOperator &I)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
static ConstantInt * getFalse(LLVMContext &Context)
void copyFastMathFlags(FastMathFlags FMF)
Convenience function for transferring all fast-math flag values to this instruction, which must be an operator which supports these flags.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
DiagnosticInfoOptimizationBase::Argument NV
bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I)
Fold a divide or remainder with a select instruction divisor when one of the select operands is zero...
static Value * simplifyValueKnownNonZero(Value *V, InstCombiner &IC, Instruction &CxtI)
The specific integer value is used in a context where it is known to be non-zero. ...
This class represents lattice values for constants.
BinaryOps getOpcode() const
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
This class represents zero extension of integer types.
Instruction * visitFRem(BinaryOperator &I)
void push_back(const T &Elt)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
const Value * getTrueValue() const
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Value * SimplifySDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
Value * SimplifyUDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
APInt ushl_ov(const APInt &Amt, bool &Overflow) const
void setArgOperand(unsigned i, Value *v)
This class represents a sign extension of integer types.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
bool isVectorTy() const
True if this is an instance of VectorType.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
static Instruction * foldFDivConstantDivisor(BinaryOperator &I)
Remove negation and try to convert division into multiplication.
static bool multiplyOverflows(const APInt &C1, const APInt &C2, APInt &Product, bool IsSigned)
True if the multiply can not be expressed in an int this size.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Instruction * visitFMul(BinaryOperator &I)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Instruction * visitFDiv(BinaryOperator &I)
iterator begin()
Instruction iterator methods.
Instruction * visitMul(BinaryOperator &I)
static Constant * getFMul(Constant *C1, Constant *C2)
Instruction * commonIRemTransforms(BinaryOperator &I)
This function implements the transforms common to both integer remainder instructions (urem and srem)...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined. ...
This class represents the LLVM 'select' instruction.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Exact_match< T > m_Exact(const T &SubPattern)
bool hasAllowReciprocal() const
Determine whether the allow-reciprocal flag is set.
A Use represents the edge between a Value definition and its users.
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.
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
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, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
static Constant * getLogBase2(Type *Ty, Constant *C)
A helper routine of InstCombiner::visitMul().
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Instruction * commonIDivTransforms(BinaryOperator &I)
This function implements the transforms common to both integer division instructions (udiv and sdiv)...
This file implements a class to represent arbitrary precision integral constant values and operations...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Instruction * visitSRem(BinaryOperator &I)
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
Type * getType() const
All values are typed, get the type of this value.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
int32_t exactLogBase2() const
Value * SimplifyMulInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a Mul, fold the result or return null.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a vector constant with...
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
static Constant * getFDiv(Constant *C1, Constant *C2)
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
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'.
Instruction * visitUDiv(BinaryOperator &I)
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isNegative() const
Determine sign of this APInt.
static Constant * getFNeg(Constant *C)
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
bool isAllOnesValue() const
Determine if all bits are set.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
The instances of the Type class are immutable: once they are created, they are never changed...
Value * SimplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a URem, fold the result or return null.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isFast() const
Determine whether all fast-math-flags are set.
Value * SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FDiv, fold the result or return null.
self_iterator getIterator()
static size_t visitUDivOperand(Value *Op0, Value *Op1, const BinaryOperator &I, SmallVectorImpl< UDivFoldAction > &Actions, unsigned Depth=0)
const Value * getCondition() const
static Constant * getAllOnesValue(Type *Ty)
NUW NUW NUW NUW Exact static Exact BinaryOperator * CreateNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
Helper functions to construct and inspect unary operations (NEG and NOT) via binary operators SUB and...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
bool isExact() const
Determine whether the exact flag is set.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FRem, fold the result or return null.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal) floating-point scalar constant or a vector c...
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
double Log2(double Value)
Return the log base 2 of the specified value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
static ConstantInt * getTrue(LLVMContext &Context)
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, BinaryOperator *FMFSource, const Twine &Name="")
void setOperand(unsigned i, Value *Val)
unsigned logBase2() const
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
unsigned getVectorNumElements() const
Class for arbitrary precision integers.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
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.
static Instruction * foldUDivPow2Cst(Value *Op0, Value *Op1, const BinaryOperator &I, InstCombiner &IC)
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static bool isMultiple(const APInt &C1, const APInt &C2, APInt &Quotient, bool IsSigned)
True if C1 is a multiple of C2. Quotient contains C1/C2.
const Value * getFalseValue() const
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FMul, fold the result or return null.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
Instruction * visitURem(BinaryOperator &I)
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
static Instruction * foldFDivConstantDividend(BinaryOperator &I)
Remove negation and try to reassociate constant math.
StringRef getName() const
Return a constant reference to the value's name.
APInt smul_ov(const APInt &RHS, bool &Overflow) const
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
static BinaryOperator * CreateFNegFMF(Value *Op, BinaryOperator *FMFSource, const Twine &Name="")
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 isLogicalShift() const
Return true if this is a logical shift left or a logical shift right.
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
bool isMinValue() const
Determine if this is the smallest unsigned value.
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * SimplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
LLVM Value Representation.
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
This file provides internal interfaces used to implement the InstCombine.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
bool hasExactInverseFP() const
Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplica...
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.
static Instruction * narrowUDivURem(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
If we have zero-extended operands of an unsigned div or rem, we may be able to narrow the operation (...
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value.
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
bool hasOneUse() const
Return true if there is exactly one user of this value.
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded unary floating point function corresponding to Ty is available...
static Constant * get(ArrayRef< Constant *> V)
bool isNullValue() const
Determine if all bits are clear.
static const unsigned MaxDepth
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const