Go to the documentation of this file.
43 using namespace PatternMatch;
45 #define DEBUG_TYPE "instcombine"
57 bool MadeChange =
false;
61 Value *A =
nullptr, *
B =
nullptr, *One =
nullptr;
71 if (
I &&
I->isLogicalShift() &&
80 if (
I->getOpcode() == Instruction::LShr && !
I->isExact()) {
85 if (
I->getOpcode() == Instruction::Shl && !
I->hasNoUnsignedWrap()) {
86 I->setHasNoUnsignedWrap();
95 return MadeChange ? V :
nullptr;
125 Builder.setFastMathFlags(
I.getFastMathFlags());
135 Builder.setFastMathFlags(
I.getFastMathFlags());
144 SQ.getWithInstruction(&
I)))
145 return replaceInstUsesWith(
I, V);
147 if (SimplifyAssociativeOrCommutative(
I))
153 if (
Value *V = SimplifyUsingDistributiveLaws(
I))
154 return replaceInstUsesWith(
I, V);
156 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
157 unsigned BitWidth =
I.getType()->getScalarSizeInBits();
162 if (
I.hasNoSignedWrap())
179 if (
I.hasNoUnsignedWrap() &&
Mul->hasNoUnsignedWrap())
181 if (
I.hasNoSignedWrap() &&
Mul->hasNoSignedWrap() &&
192 if (
I.hasNoUnsignedWrap())
194 if (
I.hasNoSignedWrap()) {
213 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(
I))
217 return replaceInstUsesWith(
I, FoldedMul);
220 if (isa<Constant>(Op1)) {
254 if (
I.hasNoSignedWrap() &&
255 cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap() &&
256 cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap())
257 NewMul->setHasNoSignedWrap();
271 if (!Div || (Div->
getOpcode() != Instruction::UDiv &&
272 Div->
getOpcode() != Instruction::SDiv)) {
274 Div = dyn_cast<BinaryOperator>(Op1);
276 Value *Neg = dyn_castNegVal(
Y);
279 (Div->
getOpcode() == Instruction::UDiv ||
280 Div->
getOpcode() == Instruction::SDiv)) {
286 return replaceInstUsesWith(
I,
X);
290 auto RemOpc = Div->
getOpcode() == Instruction::UDiv ? Instruction::URem
294 return BinaryOperator::CreateSub(
X, Rem);
295 return BinaryOperator::CreateSub(Rem,
X);
300 if (
I.getType()->isIntOrIntVectorTy(1))
301 return BinaryOperator::CreateAnd(Op0, Op1);
310 BO = BinaryOperator::CreateShl(Op1,
Y);
311 ShlNSW = cast<ShlOperator>(Op0)->hasNoSignedWrap();
313 BO = BinaryOperator::CreateShl(Op0,
Y);
314 ShlNSW = cast<ShlOperator>(Op1)->hasNoSignedWrap();
317 if (
I.hasNoUnsignedWrap())
319 if (
I.hasNoSignedWrap() && ShlNSW)
330 X->getType()->isIntOrIntVectorTy(1) &&
X->getType() ==
Y->getType() &&
331 (Op0->
hasOneUse() || Op1->hasOneUse())) {
340 X->getType()->isIntOrIntVectorTy(1) &&
X->getType() ==
Y->getType() &&
341 (Op0->
hasOneUse() || Op1->hasOneUse())) {
361 return BinaryOperator::CreateAnd(
Builder.CreateAShr(
X, *
C), Op1);
363 return BinaryOperator::CreateAnd(
Builder.CreateAShr(
X, *
C), Op0);
375 return replaceInstUsesWith(
I, Abs);
381 bool Changed =
false;
382 if (!
I.hasNoSignedWrap() && willNotOverflowSignedMul(Op0, Op1,
I)) {
384 I.setHasNoSignedWrap(
true);
387 if (!
I.hasNoUnsignedWrap() && willNotOverflowUnsignedMul(Op0, Op1,
I)) {
389 I.setHasNoUnsignedWrap(
true);
392 return Changed ? &
I :
nullptr;
397 assert((Opcode == Instruction::FMul || Opcode == Instruction::FDiv) &&
398 "Expected fmul or fdiv");
400 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
416 (Op0->
hasOneUse() || Op1->hasOneUse())) {
418 Builder.setFastMathFlags(
I.getFastMathFlags());
420 Value *Fabs =
Builder.CreateUnaryIntrinsic(Intrinsic::fabs, XY);
422 return replaceInstUsesWith(
I, Fabs);
430 I.getFastMathFlags(),
431 SQ.getWithInstruction(&
I)))
432 return replaceInstUsesWith(
I, V);
434 if (SimplifyAssociativeOrCommutative(
I))
440 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(
I))
444 return replaceInstUsesWith(
I, FoldedMul);
450 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
461 if (
Value *V = SimplifySelectsFeedingBinaryOp(
I, Op0, Op1))
462 return replaceInstUsesWith(
I, V);
464 if (
I.hasAllowReassoc()) {
520 Value *Sqrt =
Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, XY, &
I);
521 return replaceInstUsesWith(
I, Sqrt);
530 if (
I.hasNoSignedZeros() &&
534 if (
I.hasNoSignedZeros() &&
541 if (
I.hasNoNaNs() &&
I.hasNoSignedZeros() && Op0 == Op1 &&
546 m_Intrinsic<Intrinsic::sqrt>(
m_Value(
Y))))) {
562 (Op0->
hasOneUse() || Op1->hasOneUse())) {
564 Value *Exp =
Builder.CreateUnaryIntrinsic(Intrinsic::exp, XY, &
I);
565 return replaceInstUsesWith(
I, Exp);
572 (Op0->
hasOneUse() || Op1->hasOneUse())) {
574 Value *Exp2 =
Builder.CreateUnaryIntrinsic(Intrinsic::exp2, XY, &
I);
575 return replaceInstUsesWith(
I, Exp2);
602 Log2 = cast<IntrinsicInst>(Op0);
607 Log2 = cast<IntrinsicInst>(Op1);
639 replaceOperand(
I, 1,
SI->getOperand(NonNullOperand));
649 Value *SelectCond =
SI->getCondition();
656 while (BBI != BBFront) {
664 for (
Use &
Op : BBI->operands()) {
666 replaceUse(
Op,
SI->getOperand(NonNullOperand));
667 Worklist.push(&*BBI);
668 }
else if (
Op == SelectCond) {
671 Worklist.push(&*BBI);
678 if (&*BBI == SelectCond)
679 SelectCond =
nullptr;
682 if (!SelectCond && !
SI)
693 Product = IsSigned ?
C1.smul_ov(C2, Overflow) :
C1.umul_ov(C2, Overflow);
710 APInt Remainder(
C1.getBitWidth(), 0ULL, IsSigned);
724 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
725 bool IsSigned =
I.getOpcode() == Instruction::SDiv;
726 Type *Ty =
I.getType();
730 return replaceOperand(
I, 1, V);
734 if (simplifyDivRemOfSelectWithZeroOp(
I))
745 APInt Product(
C1->getBitWidth(), 0ULL, IsSigned);
753 APInt Quotient(
C1->getBitWidth(), 0ULL, IsSigned);
759 NewDiv->setIsExact(
I.isExact());
767 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
768 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
769 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
775 *
C1 !=
C1->getBitWidth() - 1) ||
777 APInt Quotient(
C1->getBitWidth(), 0ULL, IsSigned);
779 C1->getBitWidth(),
static_cast<unsigned>(
C1->getLimitedValue()));
782 if (
isMultiple(*C2, C1Shifted, Quotient, IsSigned)) {
785 BO->setIsExact(
I.isExact());
790 if (
isMultiple(C1Shifted, *C2, Quotient, IsSigned)) {
793 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
794 Mul->setHasNoUnsignedWrap(!IsSigned && OBO->hasNoUnsignedWrap());
795 Mul->setHasNoSignedWrap(OBO->hasNoSignedWrap());
801 if (
Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(
I))
822 if (SimplifyDemandedInstructionBits(
I))
841 bool HasNSW = cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap();
842 bool HasNUW = cast<OverflowingBinaryOperator>(Op1)->hasNoUnsignedWrap();
843 if ((IsSigned && HasNSW) || (!IsSigned && HasNUW)) {
845 replaceOperand(
I, 1,
Y);
862 struct UDivFoldAction {
865 FoldUDivOperandCb FoldAction;
868 Value *OperandToFold;
878 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand)
879 : FoldAction(FA), OperandToFold(InputOperand), FoldResult(
nullptr) {}
880 UDivFoldAction(FoldUDivOperandCb FA,
Value *InputOperand,
size_t SLHS)
881 : FoldAction(FA), OperandToFold(InputOperand), SelectLHSIdx(SLHS) {}
915 if (Op1 != ShiftLeft)
929 unsigned Depth = 0) {
936 return Actions.size();
942 Actions.push_back(UDivFoldAction(
foldUDivShl, Op1));
943 return Actions.size();
957 Actions.push_back(UDivFoldAction(
nullptr, Op1, LHSIdx - 1));
958 return Actions.size();
971 Type *Ty =
I.getType();
974 X->getType() ==
Y->getType() && (
N->hasOneUse() ||
D->hasOneUse())) {
993 Value *NarrowOp = isa<Constant>(
D) ?
Builder.CreateBinOp(Opcode,
X, TruncC)
994 :
Builder.CreateBinOp(Opcode, TruncC,
X);
1003 SQ.getWithInstruction(&
I)))
1004 return replaceInstUsesWith(
I, V);
1013 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1032 Type *Ty =
I.getType();
1055 return BinaryOperator::CreateUDiv(
B,
X);
1058 return BinaryOperator::CreateUDiv(A,
X);
1064 for (
unsigned i = 0,
e = UDivActions.size();
i !=
e; ++
i) {
1065 FoldUDivOperandCb Action = UDivActions[
i].FoldAction;
1066 Value *ActionOp1 = UDivActions[
i].OperandToFold;
1069 Inst = Action(Op0, ActionOp1,
I, *
this);
1074 size_t SelectRHSIdx =
i - 1;
1075 Value *SelectRHS = UDivActions[SelectRHSIdx].FoldResult;
1076 size_t SelectLHSIdx = UDivActions[
i].SelectLHSIdx;
1077 Value *SelectLHS = UDivActions[SelectLHSIdx].FoldResult;
1079 SelectLHS, SelectRHS);
1087 UDivActions[
i].FoldResult = Inst;
1097 SQ.getWithInstruction(&
I)))
1098 return replaceInstUsesWith(
I, V);
1107 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1108 Type *Ty =
I.getType();
1125 if (DivisorWasNegative)
1127 auto *AShr = BinaryOperator::CreateExactAShr(
1129 if (!DivisorWasNegative)
1132 AShr->setName(
I.getName() +
".neg");
1151 Value *NarrowOp =
Builder.CreateSDiv(Op0Src, NarrowDivisor);
1171 Builder.CreateSDiv(
X,
Y,
I.getName(),
I.isExact()));
1189 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1,
I.getName());
1190 BO->setIsExact(
I.isExact());
1206 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1,
I.getName());
1207 BO->setIsExact(
I.isExact());
1229 if (!(
C->hasExactInverseFP() || (
I.hasAllowReciprocal() &&
C->isNormalFP())))
1237 if (!RecipC->isNormalFP())
1255 if (!
I.hasAllowReassoc() || !
I.hasAllowReciprocal())
1280 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1281 auto *II = dyn_cast<IntrinsicInst>(Op1);
1282 if (!II || !II->hasOneUse() || !
I.hasAllowReassoc() ||
1283 !
I.hasAllowReciprocal())
1293 case Intrinsic::pow:
1294 Args.push_back(II->getArgOperand(0));
1295 Args.push_back(
Builder.CreateFNegFMF(II->getArgOperand(1), &
I));
1305 Args.push_back(II->getArgOperand(0));
1306 Args.push_back(
Builder.CreateNeg(II->getArgOperand(1)));
1308 case Intrinsic::exp:
1309 case Intrinsic::exp2:
1310 Args.push_back(
Builder.CreateFNegFMF(II->getArgOperand(0), &
I));
1321 I.getFastMathFlags(),
1322 SQ.getWithInstruction(&
I)))
1323 return replaceInstUsesWith(
I, V);
1337 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1338 if (isa<Constant>(Op0))
1343 if (isa<Constant>(Op1))
1348 if (
I.hasAllowReassoc() &&
I.hasAllowReciprocal()) {
1351 (!isa<Constant>(
Y) || !isa<Constant>(Op1))) {
1357 (!isa<Constant>(
Y) || !isa<Constant>(Op0))) {
1372 if (
I.hasAllowReassoc() && Op0->
hasOneUse() && Op1->hasOneUse()) {
1376 bool IsTan =
match(Op0, m_Intrinsic<Intrinsic::sin>(
m_Value(
X))) &&
1379 !IsTan &&
match(Op0, m_Intrinsic<Intrinsic::cos>(
m_Value(
X))) &&
1382 if ((IsTan || IsCot) &&
1383 hasFloatFn(&TLI,
I.getType(), LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
1386 B.setFastMathFlags(
I.getFastMathFlags());
1393 return replaceInstUsesWith(
I, Res);
1401 if (
I.hasNoNaNs() &&
I.hasAllowReassoc() &&
1404 replaceOperand(
I, 1,
Y);
1410 if (
I.hasNoNaNs() &&
I.hasNoInfs() &&
1415 return replaceInstUsesWith(
I, V);
1429 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1433 return replaceOperand(
I, 1, V);
1436 if (simplifyDivRemOfSelectWithZeroOp(
I))
1439 if (isa<Constant>(Op1)) {
1440 if (
Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
1444 }
else if (
auto *PN = dyn_cast<PHINode>(Op0I)) {
1445 const APInt *Op1Int;
1447 (
I.getOpcode() == Instruction::URem ||
1458 if (SimplifyDemandedInstructionBits(
I))
1468 SQ.getWithInstruction(&
I)))
1469 return replaceInstUsesWith(
I, V);
1481 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1482 Type *Ty =
I.getType();
1488 return BinaryOperator::CreateAnd(Op0, Add);
1519 SQ.getWithInstruction(&
I)))
1520 return replaceInstUsesWith(
I, V);
1529 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1548 return BinaryOperator::CreateURem(Op0, Op1,
I.getName());
1552 if (isa<ConstantVector>(Op1) || isa<ConstantDataVector>(Op1)) {
1554 unsigned VWidth = cast<FixedVectorType>(
C->getType())->getNumElements();
1556 bool hasNegative =
false;
1557 bool hasMissing =
false;
1558 for (
unsigned i = 0;
i != VWidth; ++
i) {
1565 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elt))
1566 if (RHS->isNegative())
1570 if (hasNegative && !hasMissing) {
1572 for (
unsigned i = 0;
i != VWidth; ++
i) {
1573 Elts[
i] =
C->getAggregateElement(
i);
1574 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Elts[
i])) {
1575 if (RHS->isNegative())
1582 return replaceOperand(
I, 1, NewRHSV);
1591 I.getFastMathFlags(),
1592 SQ.getWithInstruction(&
I)))
1593 return replaceInstUsesWith(
I, V);
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, unsigned Depth=0, const Instruction *CxtI=nullptr)
Value * SimplifyMulInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a Mul, fold the result or return null.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of non-negative values.
This class represents lattice values for constants.
Value * SimplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a URem, fold the result or return null.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
static Constant * getFDiv(Constant *C1, Constant *C2)
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
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.
bool hasOneUse() const
Return true if there is exactly one use of this value.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
InstListType::iterator iterator
Instruction iterators...
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FDiv, fold the result or return null.
SelectPatternFlavor Flavor
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
instcombine should handle this C2 when C1
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static Instruction * foldUDivPow2Cst(Value *Op0, Value *Op1, const BinaryOperator &I, InstCombinerImpl &IC)
static BinaryOperator * CreateFDivFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static Instruction * foldFDivConstantDivisor(BinaryOperator &I)
Remove negation and try to convert division into multiplication.
Instruction * visitSRem(BinaryOperator &I)
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 ...
Instruction * visitFDiv(BinaryOperator &I)
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
Value * SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FRem, fold the result or return null.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getBitWidth() const
Return the number of bits in the APInt.
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
DiagnosticInfoOptimizationBase::Argument NV
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
static Constant * getExactLogBase2(Constant *C)
If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fix...
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
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...
SelectPatternFlavor
Specific patterns of select instructions we can match.
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isMinValue() const
Determine if this is the smallest unsigned value.
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.
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
OneUse_match< T > m_OneUse(const T &SubPattern)
static size_t visitUDivOperand(Value *Op0, Value *Op1, const BinaryOperator &I, SmallVectorImpl< UDivFoldAction > &Actions, unsigned Depth=0)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static Value * simplifyValueKnownNonZero(Value *V, InstCombinerImpl &IC, Instruction &CxtI)
The specific integer value is used in a context where it is known to be non-zero.
@ SPF_NABS
Absolute value.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
Value * SimplifySDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
This is the shared class of boolean and integer constants.
static Value * foldMulSelectToNegate(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
Instruction * commonIRemTransforms(BinaryOperator &I)
This function implements the transforms common to both integer remainder instructions (urem and srem)...
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
@ And
Bitwise or logical AND of integers.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
bool match(Val *V, const Pattern &P)
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
Exact_match< T > m_Exact(const T &SubPattern)
specific_intval< true > m_SpecificIntAllowUndef(APInt V)
(vector float) vec_cmpeq(*A, *B) C
unsigned Log2(Align A)
Returns the log2 of the alignment.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
static Constant * getAllOnesValue(Type *Ty)
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
BinaryOps getOpcode() const
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FMul, fold the result or return null.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
Value * SimplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
static Constant * getFNeg(Constant *C)
bool isAllOnesValue() const
Determine if all bits are set.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
AttributeList getAttributes() const
Return the attribute list for this Function.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
This is an important base class in LLVM.
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="", Instruction *InsertBefore=nullptr)
static BinaryOperator * CreateFMulFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
static Instruction * foldUDivShl(Value *Op0, Value *Op1, const BinaryOperator &I, InstCombinerImpl &IC)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Instruction * commonIDivTransforms(BinaryOperator &I)
This function implements the transforms common to both integer division instructions (udiv and sdiv).
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
@ SPF_ABS
Floating point maxnum.
static LLVM_NODISCARD Value * Negate(bool LHSIsZero, Value *Root, InstCombinerImpl &IC)
Attempt to negate Root.
This class represents the LLVM 'select' instruction.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I)
Fold a divide or remainder with a select instruction divisor when one of the select operands is zero.
Instruction * visitSDiv(BinaryOperator &I)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class represents zero extension of integer types.
Class for arbitrary precision integers.
static Instruction * foldFDivConstantDividend(BinaryOperator &I)
Remove negation and try to reassociate constant math.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
SmallVector< MachineOperand, 4 > Cond
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getType() const
All values are typed, get the type of this value.
Instruction * visitFMul(BinaryOperator &I)
bool isExact() const
Determine whether the exact flag is set.
@ Mul
Product of integers.
static Constant * get(ArrayRef< Constant * > V)
static Constant * getFMul(Constant *C1, Constant *C2)
This class represents a sign extension of integer types.
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
static ConstantInt * getFalse(LLVMContext &Context)
static const unsigned MaxDepth
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.
Instruction * visitURem(BinaryOperator &I)
static ConstantInt * getTrue(LLVMContext &Context)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isMinSignedValue() const
Determine if this is the smallest signed value.
static BinaryOperator * CreateFAddFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
Instruction * visitFRem(BinaryOperator &I)
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Instruction * visitMul(BinaryOperator &I)
static ConstantInt * getBool(LLVMContext &Context, bool V)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
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...
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
constexpr unsigned BitWidth
static BinaryOperator * CreateNSWNeg(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
static Instruction * foldFDivPowDivisor(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
Negate the exponent of pow/exp to fold division-by-pow() into multiply.
This is blocked on not handling X *X *X powi(X, 3)(see note above). The issue is that we end up getting t
static double log2(double V)
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 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.
A wrapper class for inspecting calls to intrinsic functions.
Value * SimplifyUDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
bool isNullValue() const
Determine if all bits are clear.
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
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.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
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.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
void takeName(Value *V)
Transfer the name from V to this value.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Value * getOperand(unsigned i) const
static CastInst * CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt or BitCast cast instruction.
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.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Instruction *CopyO, const Twine &Name="")
LLVM Value Representation.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
APInt ushl_ov(const APInt &Amt, bool &Overflow) const
Instruction * visitUDiv(BinaryOperator &I)
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 (...
static BinaryOperator * CreateFSubFMF(Value *V1, Value *V2, Instruction *FMFSource, const Twine &Name="")
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
A Use represents the edge between a Value definition and its users.