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();
174 unsigned Width = NewCst->getType()->getPrimitiveSizeInBits();
190 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
195 const APInt & Val = CI->getValue();
198 Value *
X =
nullptr, *
Y =
nullptr;
201 Value *Sub =
nullptr;
203 Sub = Builder.CreateSub(X,
Y,
"suba");
205 Sub = Builder.CreateSub(Builder.CreateNeg(C1),
Y,
"subc");
215 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
219 if (isa<Constant>(Op1)) {
224 Value *Mul = Builder.CreateMul(C1, Op1);
242 cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap() &&
243 cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap())
244 NewMul->setHasNoSignedWrap();
253 if (!Div || (Div->
getOpcode() != Instruction::UDiv &&
254 Div->
getOpcode() != Instruction::SDiv)) {
258 Value *Neg = dyn_castNegVal(Y);
261 (Div->
getOpcode() == Instruction::UDiv ||
262 Div->
getOpcode() == Instruction::SDiv)) {
268 return replaceInstUsesWith(I, X);
272 auto RemOpc = Div->
getOpcode() == Instruction::UDiv ? Instruction::URem
274 Value *Rem = Builder.CreateBinOp(RemOpc, X, DivOp1);
276 return BinaryOperator::CreateSub(X, Rem);
277 return BinaryOperator::CreateSub(Rem, X);
283 return BinaryOperator::CreateAnd(Op0, Op1);
292 BO = BinaryOperator::CreateShl(Op1, Y);
293 ShlNSW = cast<ShlOperator>(Op0)->hasNoSignedWrap();
295 BO = BinaryOperator::CreateShl(Op0, Y);
296 ShlNSW = cast<ShlOperator>(Op1)->hasNoSignedWrap();
322 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op1);
324 return BinaryOperator::CreateAnd(Builder.CreateAShr(X, *C), Op0);
328 if (
SExtInst *Op0Conv = dyn_cast<SExtInst>(Op0)) {
330 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
331 if (Op0Conv->hasOneUse()) {
335 willNotOverflowSignedMul(Op0Conv->getOperand(0), CI,
I)) {
338 Builder.CreateNSWMul(Op0Conv->getOperand(0), CI,
"mulconv");
345 if (
SExtInst *Op1Conv = dyn_cast<SExtInst>(Op1)) {
349 if (Op0Conv->getOperand(0)->getType() ==
350 Op1Conv->getOperand(0)->getType() &&
351 (Op0Conv->hasOneUse() || Op1Conv->hasOneUse()) &&
352 willNotOverflowSignedMul(Op0Conv->getOperand(0),
353 Op1Conv->getOperand(0),
I)) {
355 Value *NewMul = Builder.CreateNSWMul(
356 Op0Conv->getOperand(0), Op1Conv->getOperand(0),
"mulconv");
364 if (
auto *Op0Conv = dyn_cast<ZExtInst>(Op0)) {
366 if (
ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1)) {
367 if (Op0Conv->hasOneUse()) {
371 willNotOverflowUnsignedMul(Op0Conv->getOperand(0), CI,
I)) {
374 Builder.CreateNUWMul(Op0Conv->getOperand(0), CI,
"mulconv");
381 if (
auto *Op1Conv = dyn_cast<ZExtInst>(Op1)) {
385 if (Op0Conv->getOperand(0)->getType() ==
386 Op1Conv->getOperand(0)->getType() &&
387 (Op0Conv->hasOneUse() || Op1Conv->hasOneUse()) &&
388 willNotOverflowUnsignedMul(Op0Conv->getOperand(0),
389 Op1Conv->getOperand(0),
I)) {
391 Value *NewMul = Builder.CreateNUWMul(
392 Op0Conv->getOperand(0), Op1Conv->getOperand(0),
"mulconv");
398 bool Changed =
false;
409 return Changed ? &
I :
nullptr;
415 SQ.getWithInstruction(&I)))
416 return replaceInstUsesWith(I, V);
418 if (SimplifyAssociativeOrCommutative(I))
424 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
451 if (Op0 == Op1 &&
match(Op0, m_Intrinsic<Intrinsic::fabs>(
m_Value(X))))
455 if (
Value *V = SimplifySelectsFeedingBinaryOp(I, Op0, Op1))
456 return replaceInstUsesWith(I, V);
488 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
494 Value *
XC = Builder.CreateFMulFMF(X, C, &I);
505 Value *XY = Builder.CreateFMulFMF(X, Y, &I);
506 Value *Sqrt = Builder.CreateIntrinsic(Intrinsic::sqrt, { XY }, &
I);
507 return replaceInstUsesWith(I, Sqrt);
519 Value *XX = Builder.CreateFMulFMF(Op1, Op1, &I);
524 Value *XX = Builder.CreateFMulFMF(Op0, Op0, &I);
534 Log2 = cast<IntrinsicInst>(Op0);
539 Log2 = cast<IntrinsicInst>(Op1);
545 Value *LogXTimesY = Builder.CreateFMulFMF(Log2, Y, &I);
589 while (BBI != BBFront) {
602 }
else if (*I == SelectCond) {
612 if (&*BBI == SelectCond)
613 SelectCond =
nullptr;
616 if (!SelectCond && !SI)
627 Product = IsSigned ? C1.
smul_ov(C2, Overflow) : C1.
umul_ov(C2, Overflow);
650 return Remainder.isMinValue();
659 bool IsSigned = I.
getOpcode() == Instruction::SDiv;
670 if (simplifyDivRemOfSelectWithZeroOp(I))
692 if (
isMultiple(*C2, *C1, Quotient, IsSigned)) {
700 if (
isMultiple(*C1, *C2, Quotient, IsSigned)) {
703 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
704 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
705 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
718 if (
isMultiple(*C2, C1Shifted, Quotient, IsSigned)) {
726 if (
isMultiple(C1Shifted, *C2, Quotient, IsSigned)) {
729 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
730 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
731 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
737 if (
Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(I))
747 Value *Inc = Builder.CreateAdd(Op1, Op0);
753 return new ZExtInst(Builder.CreateICmpEQ(Op1, Op0), Ty);
758 if (SimplifyDemandedInstructionBits(I))
777 bool HasNSW = cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap();
778 bool HasNUW = cast<OverflowingBinaryOperator>(Op1)->hasNoUnsignedWrap();
779 if ((IsSigned && HasNSW) || (!IsSigned && HasNUW)) {
798 struct UDivFoldAction {
801 FoldUDivOperandCb FoldAction;
804 Value *OperandToFold;
814 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand)
815 : FoldAction(FA), OperandToFold(InputOperand), FoldResult(
nullptr) {}
816 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand,
size_t SLHS)
817 : FoldAction(FA), OperandToFold(InputOperand), SelectLHSIdx(SLHS) {}
850 if (Op1 != ShiftLeft)
864 unsigned Depth = 0) {
869 return Actions.
size();
876 return Actions.
size();
880 if (
Depth++ == MaxDepth)
887 Actions.push_back(UDivFoldAction(
nullptr, Op1, LHSIdx - 1));
888 return Actions.size();
933 SQ.getWithInstruction(&I)))
934 return replaceInstUsesWith(I, V);
945 const APInt *C1, *C2;
964 Value *Cmp = Builder.CreateICmpUGE(Op0, Op1);
985 return BinaryOperator::CreateUDiv(B, X);
988 return BinaryOperator::CreateUDiv(A, X);
994 for (
unsigned i = 0, e = UDivActions.
size(); i != e; ++i) {
995 FoldUDivOperandCb Action = UDivActions[i].FoldAction;
996 Value *ActionOp1 = UDivActions[i].OperandToFold;
999 Inst = Action(Op0, ActionOp1, I, *
this);
1004 size_t SelectRHSIdx = i - 1;
1005 Value *SelectRHS = UDivActions[SelectRHSIdx].FoldResult;
1006 size_t SelectLHSIdx = UDivActions[i].SelectLHSIdx;
1007 Value *SelectLHS = UDivActions[SelectLHSIdx].FoldResult;
1009 SelectLHS, SelectRHS);
1017 UDivActions[i].FoldResult = Inst;
1027 SQ.getWithInstruction(&I)))
1028 return replaceInstUsesWith(I, V);
1034 if (
Instruction *Common = commonIDivTransforms(I))
1050 return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.
getName());
1066 Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
1071 if (
Constant *RHS = dyn_cast<Constant>(Op1)) {
1073 if (RHS->isMinSignedValue())
1091 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1101 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.
getName());
1132 if (!RecipC->isNormalFP())
1175 SQ.getWithInstruction(&I)))
1176 return replaceInstUsesWith(I, V);
1188 if (isa<Constant>(Op0))
1193 if (isa<Constant>(Op1))
1201 (!isa<Constant>(
Y) || !isa<Constant>(Op1))) {
1203 Value *YZ = Builder.CreateFMulFMF(Y, Op1, &I);
1207 (!isa<Constant>(Y) || !isa<Constant>(Op0))) {
1209 Value *YZ = Builder.CreateFMulFMF(Y, Op0, &I);
1218 bool IsTan =
match(Op0, m_Intrinsic<Intrinsic::sin>(
m_Value(X))) &&
1221 !IsTan &&
match(Op0, m_Intrinsic<Intrinsic::cos>(
m_Value(X))) &&
1225 LibFunc_tanf, LibFunc_tanl)) {
1233 return replaceInstUsesWith(I, Res);
1272 if (simplifyDivRemOfSelectWithZeroOp(I))
1275 if (isa<Constant>(Op1)) {
1276 if (
Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
1280 }
else if (
auto *PN = dyn_cast<PHINode>(Op0I)) {
1281 const APInt *Op1Int;
1294 if (SimplifyDemandedInstructionBits(I))
1304 SQ.getWithInstruction(&I)))
1305 return replaceInstUsesWith(I, V);
1310 if (
Instruction *common = commonIRemTransforms(I))
1321 Value *
Add = Builder.CreateAdd(Op1, N1);
1322 return BinaryOperator::CreateAnd(Op0, Add);
1331 Value *Cmp = Builder.CreateICmpULT(Op0, Op1);
1332 Value *Sub = Builder.CreateSub(Op0, Op1);
1351 SQ.getWithInstruction(&I)))
1352 return replaceInstUsesWith(I, V);
1358 if (
Instruction *Common = commonIRemTransforms(I))
1378 return BinaryOperator::CreateURem(Op0, Op1, I.
getName());
1382 if (isa<ConstantVector>(Op1) || isa<ConstantDataVector>(Op1)) {
1386 bool hasNegative =
false;
1387 bool hasMissing =
false;
1388 for (
unsigned i = 0; i != VWidth; ++i) {
1395 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elt))
1396 if (RHS->isNegative())
1400 if (hasNegative && !hasMissing) {
1402 for (
unsigned i = 0; i != VWidth; ++i) {
1404 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elts[i])) {
1405 if (RHS->isNegative())
1425 SQ.getWithInstruction(&I)))
1426 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)
BinaryOp_match< cstfp_pred_ty< is_neg_zero_fp >, RHS, Instruction::FSub > m_FNeg(const RHS &X)
Match 'fneg X' as 'fsub -0.0, X'.
void push_back(const T &Elt)
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.
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)
Return true if the given value is known to have exactly one bit set when defined. ...
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. ...
Compute iterated dominance frontiers using a linear time algorithm.
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)
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
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)
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.
static Constant * getLogBase2(Type *Ty, Constant *C)
A helper routine of InstCombiner::visitMul().
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)
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...
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)
Return true if 'V & Mask' is known to be zero.
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.
void setArgOperand(unsigned i, Value *v)
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 GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
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)
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