44 #define DEBUG_TYPE "instcombine" 56 bool MadeChange =
false;
60 Value *A =
nullptr, *
B =
nullptr, *One =
nullptr;
94 return MadeChange ? V :
nullptr;
115 if (isa<UndefValue>(Elt)) {
134 Value *Cond, *OtherOp;
173 SQ.getWithInstruction(&I)))
174 return replaceInstUsesWith(I, V);
176 if (SimplifyAssociativeOrCommutative(I))
182 if (
Value *V = SimplifyUsingDistributiveLaws(I))
183 return replaceInstUsesWith(I, V);
207 BO->setHasNoUnsignedWrap();
210 BO->setHasNoSignedWrap();
232 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
237 const APInt & Val = CI->getValue();
240 Value *
X =
nullptr, *
Y =
nullptr;
243 Value *Sub =
nullptr;
245 Sub = Builder.CreateSub(X,
Y,
"suba");
247 Sub = Builder.CreateSub(Builder.CreateNeg(C1),
Y,
"subc");
257 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
261 return replaceInstUsesWith(I, FoldedMul);
264 if (isa<Constant>(Op1)) {
269 Value *Mul = Builder.CreateMul(C1, Op1);
289 NewMul->setHasNoSignedWrap();
303 if (!Div || (Div->
getOpcode() != Instruction::UDiv &&
304 Div->
getOpcode() != Instruction::SDiv)) {
308 Value *Neg = dyn_castNegVal(Y);
311 (Div->
getOpcode() == Instruction::UDiv ||
312 Div->
getOpcode() == Instruction::SDiv)) {
318 return replaceInstUsesWith(I, X);
322 auto RemOpc = Div->
getOpcode() == Instruction::UDiv ? Instruction::URem
324 Value *Rem = Builder.CreateBinOp(RemOpc, X, DivOp1);
326 return BinaryOperator::CreateSub(X, Rem);
327 return BinaryOperator::CreateSub(Rem, X);
333 return BinaryOperator::CreateAnd(Op0, Op1);
342 BO = BinaryOperator::CreateShl(Op1, Y);
345 BO = BinaryOperator::CreateShl(Op0, Y);
372 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op1);
374 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op0);
379 bool Changed =
false;
390 return Changed ? &
I :
nullptr;
396 SQ.getWithInstruction(&I)))
397 return replaceInstUsesWith(I, V);
399 if (SimplifyAssociativeOrCommutative(I))
405 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
409 return replaceInstUsesWith(I, FoldedMul);
427 if (Op0 == Op1 &&
match(Op0, m_Intrinsic<Intrinsic::fabs>(
m_Value(X))))
431 if (
Value *V = SimplifySelectsFeedingBinaryOp(I, Op0, Op1))
432 return replaceInstUsesWith(I, V);
464 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
470 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
479 Value *NewFMul = Builder.CreateFMulFMF(X, Z, &I);
489 Value *XY = Builder.CreateFMulFMF(X, Y, &I);
490 Value *Sqrt = Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, XY, &I);
491 return replaceInstUsesWith(I, Sqrt);
501 m_Intrinsic<Intrinsic::sqrt>(
m_Value(Y))))) {
502 Value *XX = Builder.CreateFMulFMF(X, X, &I);
508 Value *XX = Builder.CreateFMulFMF(X, X, &I);
515 if (
match(Op0, m_Intrinsic<Intrinsic::exp>(
m_Value(X))) &&
517 (Op0->
hasOneUse() || Op1->hasOneUse())) {
518 Value *XY = Builder.CreateFAddFMF(X, Y, &I);
519 Value *Exp = Builder.CreateUnaryIntrinsic(Intrinsic::exp, XY, &I);
520 return replaceInstUsesWith(I, Exp);
525 if (
match(Op0, m_Intrinsic<Intrinsic::exp2>(
m_Value(X))) &&
527 (Op0->
hasOneUse() || Op1->hasOneUse())) {
528 Value *XY = Builder.CreateFAddFMF(X, Y, &I);
529 Value *Exp2 = Builder.CreateUnaryIntrinsic(Intrinsic::exp2, XY, &I);
530 return replaceInstUsesWith(I, Exp2);
542 Value *XX = Builder.CreateFMulFMF(Op1, Op1, &I);
547 Value *XX = Builder.CreateFMulFMF(Op0, Op0, &I);
557 Log2 = cast<IntrinsicInst>(Op0);
562 Log2 = cast<IntrinsicInst>(Op1);
568 Value *LogXTimesY = Builder.CreateFMulFMF(Log2, Y, &I);
612 while (BBI != BBFront) {
625 }
else if (*I == SelectCond) {
635 if (&*BBI == SelectCond)
636 SelectCond =
nullptr;
639 if (!SelectCond && !SI)
650 Product = IsSigned ? C1.
smul_ov(C2, Overflow) : C1.
umul_ov(C2, Overflow);
673 return Remainder.isMinValue();
682 bool IsSigned = I.
getOpcode() == Instruction::SDiv;
693 if (simplifyDivRemOfSelectWithZeroOp(I))
715 if (
isMultiple(*C2, *C1, Quotient, IsSigned)) {
723 if (
isMultiple(*C1, *C2, Quotient, IsSigned)) {
726 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
727 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
728 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
741 if (
isMultiple(*C2, C1Shifted, Quotient, IsSigned)) {
749 if (
isMultiple(C1Shifted, *C2, Quotient, IsSigned)) {
752 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
753 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
754 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
760 if (
Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(I))
770 Value *Inc = Builder.CreateAdd(Op1, Op0);
776 return new ZExtInst(Builder.CreateICmpEQ(Op1, Op0), Ty);
781 if (SimplifyDemandedInstructionBits(I))
802 if ((IsSigned && HasNSW) || (!IsSigned && HasNUW)) {
821 struct UDivFoldAction {
824 FoldUDivOperandCb FoldAction;
827 Value *OperandToFold;
837 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand)
838 : FoldAction(FA), OperandToFold(InputOperand), FoldResult(
nullptr) {}
839 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand,
size_t SLHS)
840 : FoldAction(FA), OperandToFold(InputOperand), SelectLHSIdx(SLHS) {}
873 if (Op1 != ShiftLeft)
887 unsigned Depth = 0) {
892 return Actions.
size();
899 return Actions.
size();
903 if (
Depth++ == MaxDepth)
910 Actions.push_back(UDivFoldAction(
nullptr, Op1, LHSIdx - 1));
911 return Actions.size();
956 SQ.getWithInstruction(&I)))
957 return replaceInstUsesWith(I, V);
968 const APInt *C1, *C2;
987 Value *Cmp = Builder.CreateICmpUGE(Op0, Op1);
1008 return BinaryOperator::CreateUDiv(B, X);
1011 return BinaryOperator::CreateUDiv(A, X);
1017 for (
unsigned i = 0,
e = UDivActions.
size(); i !=
e; ++i) {
1018 FoldUDivOperandCb Action = UDivActions[i].FoldAction;
1019 Value *ActionOp1 = UDivActions[i].OperandToFold;
1022 Inst = Action(Op0, ActionOp1, I, *
this);
1027 size_t SelectRHSIdx = i - 1;
1028 Value *SelectRHS = UDivActions[SelectRHSIdx].FoldResult;
1029 size_t SelectLHSIdx = UDivActions[i].SelectLHSIdx;
1030 Value *SelectLHS = UDivActions[SelectLHSIdx].FoldResult;
1032 SelectLHS, SelectRHS);
1040 UDivActions[i].FoldResult = Inst;
1050 SQ.getWithInstruction(&I)))
1051 return replaceInstUsesWith(I, V);
1057 if (
Instruction *Common = commonIDivTransforms(I))
1075 if (I.
isExact() && Op1C->isNonNegative() && Op1C->isPowerOf2()) {
1077 return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.
getName());
1085 Op0Src->getType()->getScalarSizeInBits() >= Op1C->getMinSignedBits()) {
1093 Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
1100 if (!Op1C->isMinSignedValue() &&
1103 Instruction *BO = BinaryOperator::CreateSDiv(X, NegC);
1121 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1131 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1162 if (!RecipC->isNormalFP())
1205 SQ.getWithInstruction(&I)))
1206 return replaceInstUsesWith(I, V);
1218 if (isa<Constant>(Op0))
1223 if (isa<Constant>(Op1))
1231 (!isa<Constant>(
Y) || !isa<Constant>(Op1))) {
1233 Value *YZ = Builder.CreateFMulFMF(Y, Op1, &I);
1237 (!isa<Constant>(Y) || !isa<Constant>(Op0))) {
1239 Value *YZ = Builder.CreateFMulFMF(Y, Op0, &I);
1256 bool IsTan =
match(Op0, m_Intrinsic<Intrinsic::sin>(
m_Value(X))) &&
1259 !IsTan &&
match(Op0, m_Intrinsic<Intrinsic::cos>(
m_Value(X))) &&
1262 if ((IsTan || IsCot) &&
1270 LibFunc_tanl, B, Attrs);
1273 return replaceInstUsesWith(I, Res);
1302 Value *V = Builder.CreateBinaryIntrinsic(
1304 return replaceInstUsesWith(I, V);
1323 if (simplifyDivRemOfSelectWithZeroOp(I))
1326 if (isa<Constant>(Op1)) {
1327 if (
Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
1331 }
else if (
auto *PN = dyn_cast<PHINode>(Op0I)) {
1332 const APInt *Op1Int;
1345 if (SimplifyDemandedInstructionBits(I))
1355 SQ.getWithInstruction(&I)))
1356 return replaceInstUsesWith(I, V);
1361 if (
Instruction *common = commonIRemTransforms(I))
1374 Value *
Add = Builder.CreateAdd(Op1, N1);
1375 return BinaryOperator::CreateAnd(Op0, Add);
1386 Value *Cmp = Builder.CreateICmpULT(Op0, Op1);
1387 Value *Sub = Builder.CreateSub(Op0, Op1);
1406 SQ.getWithInstruction(&I)))
1407 return replaceInstUsesWith(I, V);
1413 if (
Instruction *Common = commonIRemTransforms(I))
1438 return BinaryOperator::CreateURem(Op0, Op1, I.
getName());
1442 if (isa<ConstantVector>(Op1) || isa<ConstantDataVector>(Op1)) {
1446 bool hasNegative =
false;
1447 bool hasMissing =
false;
1448 for (
unsigned i = 0; i != VWidth; ++i) {
1455 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elt))
1456 if (RHS->isNegative())
1460 if (hasNegative && !hasMissing) {
1462 for (
unsigned i = 0; i != VWidth; ++i) {
1464 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elts[i])) {
1465 if (RHS->isNegative())
1485 SQ.getWithInstruction(&I)))
1486 return replaceInstUsesWith(I, V);
APInt abs() const
Get the absolute value;.
static Instruction * foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I, InstCombiner &IC)
unsigned Log2(Align A)
Returns the log2 of the alignment.
Instruction * visitSDiv(BinaryOperator &I)
bool hasNoInfs() const
Determine whether the no-infs flag is set.
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")
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
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)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
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 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.
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...
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)
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.
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
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.
static bool hasNoSignedWrap(BinaryOperator &I)
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)
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
bool isAllOnesValue() const
Determine if all bits are set.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
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...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
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 * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
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)
static bool hasNoUnsignedWrap(BinaryOperator &I)
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.
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
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...
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 const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
static ConstantInt * getTrue(LLVMContext &Context)
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 BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
static BinaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="")
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)
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.
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
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
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())
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, or, for vectors, does not contain smallest...
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)
static Value * foldMulSelectToNegate(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
bool hasFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
static Constant * get(ArrayRef< Constant *> V)
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
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