Go to the documentation of this file.
36 #define DEBUG_TYPE "instcombine"
40 using namespace PatternMatch;
52 bool MadeChange =
false;
56 Value *A =
nullptr, *
B =
nullptr, *One =
nullptr;
66 if (
I &&
I->isLogicalShift() &&
75 if (
I->getOpcode() == Instruction::LShr && !
I->isExact()) {
80 if (
I->getOpcode() == Instruction::Shl && !
I->hasNoUnsignedWrap()) {
81 I->setHasNoUnsignedWrap();
90 return MadeChange ? V :
nullptr;
106 bool HasAnyNoWrap =
I.hasNoSignedWrap() ||
I.hasNoUnsignedWrap();
107 Value *Neg =
Builder.CreateNeg(OtherOp,
"",
false, HasAnyNoWrap);
114 bool HasAnyNoWrap =
I.hasNoSignedWrap() ||
I.hasNoUnsignedWrap();
115 Value *Neg =
Builder.CreateNeg(OtherOp,
"",
false, HasAnyNoWrap);
125 Builder.setFastMathFlags(
I.getFastMathFlags());
135 Builder.setFastMathFlags(
I.getFastMathFlags());
144 SQ.getWithInstruction(&
I)))
145 return replaceInstUsesWith(
I, V);
147 if (SimplifyAssociativeOrCommutative(
I))
156 if (
Value *V = SimplifyUsingDistributiveLaws(
I))
157 return replaceInstUsesWith(
I, V);
159 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
160 unsigned BitWidth =
I.getType()->getScalarSizeInBits();
165 if (
I.hasNoSignedWrap())
195 if (
I.hasNoUnsignedWrap())
197 if (
I.hasNoSignedWrap()) {
216 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(
I))
220 return replaceInstUsesWith(
I, FoldedMul);
223 if (isa<Constant>(Op1)) {
257 if (
I.hasNoSignedWrap() &&
258 cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap() &&
259 cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap())
260 NewMul->setHasNoSignedWrap();
274 if (!Div || (Div->
getOpcode() != Instruction::UDiv &&
275 Div->
getOpcode() != Instruction::SDiv)) {
277 Div = dyn_cast<BinaryOperator>(Op1);
279 Value *Neg = dyn_castNegVal(
Y);
282 (Div->
getOpcode() == Instruction::UDiv ||
283 Div->
getOpcode() == Instruction::SDiv)) {
289 return replaceInstUsesWith(
I,
X);
293 auto RemOpc = Div->
getOpcode() == Instruction::UDiv ? Instruction::URem
297 Value *Rem =
Builder.CreateBinOp(RemOpc, XFreeze, DivOp1);
299 return BinaryOperator::CreateSub(XFreeze, Rem);
300 return BinaryOperator::CreateSub(Rem, XFreeze);
305 if (
I.getType()->isIntOrIntVectorTy(1))
306 return BinaryOperator::CreateAnd(Op0, Op1);
315 BO = BinaryOperator::CreateShl(Op1,
Y);
316 ShlNSW = cast<ShlOperator>(Op0)->hasNoSignedWrap();
318 BO = BinaryOperator::CreateShl(Op0,
Y);
319 ShlNSW = cast<ShlOperator>(Op1)->hasNoSignedWrap();
322 if (
I.hasNoUnsignedWrap())
324 if (
I.hasNoSignedWrap() && ShlNSW)
335 X->getType()->isIntOrIntVectorTy(1) &&
X->getType() ==
Y->getType() &&
336 (Op0->
hasOneUse() || Op1->hasOneUse() ||
X ==
Y)) {
345 X->getType()->isIntOrIntVectorTy(1) &&
X->getType() ==
Y->getType() &&
346 (Op0->
hasOneUse() || Op1->hasOneUse())) {
374 return BinaryOperator::CreateAnd(
Builder.CreateAShr(
X, *
C), Op1);
376 return BinaryOperator::CreateAnd(
Builder.CreateAShr(
X, *
C), Op0);
388 return replaceInstUsesWith(
I, Abs);
394 bool Changed =
false;
395 if (!
I.hasNoSignedWrap() && willNotOverflowSignedMul(Op0, Op1,
I)) {
397 I.setHasNoSignedWrap(
true);
400 if (!
I.hasNoUnsignedWrap() && willNotOverflowUnsignedMul(Op0, Op1,
I)) {
402 I.setHasNoUnsignedWrap(
true);
405 return Changed ? &
I :
nullptr;
410 assert((Opcode == Instruction::FMul || Opcode == Instruction::FDiv) &&
411 "Expected fmul or fdiv");
413 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
429 (Op0->
hasOneUse() || Op1->hasOneUse())) {
431 Builder.setFastMathFlags(
I.getFastMathFlags());
433 Value *Fabs =
Builder.CreateUnaryIntrinsic(Intrinsic::fabs, XY);
435 return replaceInstUsesWith(
I, Fabs);
443 I.getFastMathFlags(),
444 SQ.getWithInstruction(&
I)))
445 return replaceInstUsesWith(
I, V);
447 if (SimplifyAssociativeOrCommutative(
I))
456 if (
Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(
I))
460 return replaceInstUsesWith(
I, FoldedMul);
466 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
477 if (
Value *V = SimplifySelectsFeedingBinaryOp(
I, Op0, Op1))
478 return replaceInstUsesWith(
I, V);
480 if (
I.hasAllowReassoc()) {
536 Value *Sqrt =
Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, XY, &
I);
537 return replaceInstUsesWith(
I, Sqrt);
546 if (
I.hasNoSignedZeros() &&
550 if (
I.hasNoSignedZeros() &&
557 if (
I.hasNoNaNs() &&
I.hasNoSignedZeros() && Op0 == Op1 &&
562 m_Intrinsic<Intrinsic::sqrt>(
m_Value(
Y))))) {
574 if (
I.isOnlyUserOfAnyOperand()) {
578 auto *YZ =
Builder.CreateFAddFMF(
Y, Z, &
I);
579 auto *NewPow =
Builder.CreateBinaryIntrinsic(Intrinsic::pow,
X, YZ, &
I);
580 return replaceInstUsesWith(
I, NewPow);
586 Y->getType() == Z->getType()) {
588 auto *NewPow =
Builder.CreateIntrinsic(
590 return replaceInstUsesWith(
I, NewPow);
597 Value *Exp =
Builder.CreateUnaryIntrinsic(Intrinsic::exp, XY, &
I);
598 return replaceInstUsesWith(
I, Exp);
605 Value *Exp2 =
Builder.CreateUnaryIntrinsic(Intrinsic::exp2, XY, &
I);
606 return replaceInstUsesWith(
I, Exp2);
634 Log2 = cast<IntrinsicInst>(Op0);
639 Log2 = cast<IntrinsicInst>(Op1);
671 replaceOperand(
I, 1,
SI->getOperand(NonNullOperand));
681 Value *SelectCond =
SI->getCondition();
688 while (BBI != BBFront) {
696 for (
Use &
Op : BBI->operands()) {
698 replaceUse(
Op,
SI->getOperand(NonNullOperand));
699 Worklist.push(&*BBI);
700 }
else if (
Op == SelectCond) {
703 Worklist.push(&*BBI);
710 if (&*BBI == SelectCond)
711 SelectCond =
nullptr;
714 if (!SelectCond && !
SI)
725 Product = IsSigned ?
C1.smul_ov(C2, Overflow) :
C1.umul_ov(C2, Overflow);
739 if (IsSigned &&
C1.isMinSignedValue() && C2.
isAllOnes())
742 APInt Remainder(
C1.getBitWidth(), 0ULL, IsSigned);
759 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
760 bool IsSigned =
I.getOpcode() == Instruction::SDiv;
761 Type *Ty =
I.getType();
765 return replaceOperand(
I, 1, V);
769 if (simplifyDivRemOfSelectWithZeroOp(
I))
777 if (
Instruction *R = FoldOpIntoSelect(
I, cast<SelectInst>(Op1),
790 APInt Product(
C1->getBitWidth(), 0ULL, IsSigned);
798 APInt Quotient(
C1->getBitWidth(), 0ULL, IsSigned);
804 NewDiv->setIsExact(
I.isExact());
812 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
820 C1->ult(
C1->getBitWidth() - 1)) ||
822 C1->ult(
C1->getBitWidth()))) {
823 APInt Quotient(
C1->getBitWidth(), 0ULL, IsSigned);
825 C1->getBitWidth(),
static_cast<unsigned>(
C1->getZExtValue()));
828 if (
isMultiple(*C2, C1Shifted, Quotient, IsSigned)) {
831 BO->setIsExact(
I.isExact());
836 if (
isMultiple(C1Shifted, *C2, Quotient, IsSigned)) {
839 auto *OBO = cast<OverflowingBinaryOperator>(Op0);
847 if (
Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(
I))
857 Value *F1 =
Builder.CreateFreeze(Op1, Op1->getName() +
".fr");
869 if (SimplifyDemandedInstructionBits(
I))
888 bool HasNSW = cast<OverflowingBinaryOperator>(Op1)->hasNoSignedWrap();
889 bool HasNUW = cast<OverflowingBinaryOperator>(Op1)->hasNoUnsignedWrap();
890 if ((IsSigned && HasNSW) || (!IsSigned && HasNUW)) {
892 replaceOperand(
I, 1,
Y);
909 return reinterpret_cast<Value *
>(-1);
917 return IfFold([&]() {
933 return IfFold([&]() {
return Builder.CreateZExt(LogX,
Op->getType()); });
939 return IfFold([&]() {
return Builder.CreateAdd(LogX,
Y); });
949 return IfFold([&]() {
950 return Builder.CreateSelect(
SI->getOperand(0), LogX, LogY);
955 auto *
MinMax = dyn_cast<MinMaxIntrinsic>(
Op);
959 return IfFold([&]() {
960 return Builder.CreateBinaryIntrinsic(
961 MinMax->getIntrinsicID(), LogX, LogY);
974 Type *Ty =
I.getType();
977 X->getType() ==
Y->getType() && (
N->hasOneUse() ||
D->hasOneUse())) {
996 Value *NarrowOp = isa<Constant>(
D) ?
Builder.CreateBinOp(Opcode,
X, TruncC)
997 :
Builder.CreateBinOp(Opcode, TruncC,
X);
1006 SQ.getWithInstruction(&
I)))
1007 return replaceInstUsesWith(
I, V);
1016 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1035 Type *Ty =
I.getType();
1058 return BinaryOperator::CreateUDiv(
B,
X);
1061 return BinaryOperator::CreateUDiv(A,
X);
1067 return replaceInstUsesWith(
1068 I,
Builder.CreateLShr(Op0, Res,
I.getName(),
I.isExact()));
1076 SQ.getWithInstruction(&
I)))
1077 return replaceInstUsesWith(
I, V);
1086 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1087 Type *Ty =
I.getType();
1104 if (DivisorWasNegative)
1106 auto *AShr = BinaryOperator::CreateExactAShr(
1108 if (!DivisorWasNegative)
1111 AShr->setName(
I.getName() +
".neg");
1130 Value *NarrowOp =
Builder.CreateSDiv(Op0Src, NarrowDivisor);
1150 Builder.CreateSDiv(
X,
Y,
I.getName(),
I.isExact()));
1168 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1,
I.getName());
1169 BO->setIsExact(
I.isExact());
1178 Value *Shr =
Builder.CreateLShr(Op0, CNegLog2,
I.getName(),
I.isExact());
1187 auto *BO = BinaryOperator::CreateUDiv(Op0, Op1,
I.getName());
1188 BO->setIsExact(
I.isExact());
1210 if (!(
C->hasExactInverseFP() || (
I.hasAllowReciprocal() &&
C->isNormalFP())))
1218 if (!RecipC->isNormalFP())
1236 if (!
I.hasAllowReassoc() || !
I.hasAllowReciprocal())
1261 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1262 auto *II = dyn_cast<IntrinsicInst>(Op1);
1263 if (!II || !II->hasOneUse() || !
I.hasAllowReassoc() ||
1264 !
I.hasAllowReciprocal())
1274 case Intrinsic::pow:
1275 Args.push_back(II->getArgOperand(0));
1276 Args.push_back(
Builder.CreateFNegFMF(II->getArgOperand(1), &
I));
1286 Args.push_back(II->getArgOperand(0));
1287 Args.push_back(
Builder.CreateNeg(II->getArgOperand(1)));
1288 Type *Tys[] = {
I.getType(), II->getArgOperand(1)->getType()};
1292 case Intrinsic::exp:
1293 case Intrinsic::exp2:
1294 Args.push_back(
Builder.CreateFNegFMF(II->getArgOperand(0), &
I));
1307 I.getFastMathFlags(),
1308 SQ.getWithInstruction(&
I)))
1309 return replaceInstUsesWith(
I, V);
1326 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1327 if (isa<Constant>(Op0))
1332 if (isa<Constant>(Op1))
1337 if (
I.hasAllowReassoc() &&
I.hasAllowReciprocal()) {
1340 (!isa<Constant>(
Y) || !isa<Constant>(Op1))) {
1346 (!isa<Constant>(
Y) || !isa<Constant>(Op0))) {
1361 if (
I.hasAllowReassoc() && Op0->
hasOneUse() && Op1->hasOneUse()) {
1365 bool IsTan =
match(Op0, m_Intrinsic<Intrinsic::sin>(
m_Value(
X))) &&
1368 !IsTan &&
match(Op0, m_Intrinsic<Intrinsic::cos>(
m_Value(
X))) &&
1371 if ((IsTan || IsCot) &&
hasFloatFn(
M, &TLI,
I.getType(), LibFunc_tan,
1372 LibFunc_tanf, LibFunc_tanl)) {
1375 B.setFastMathFlags(
I.getFastMathFlags());
1382 return replaceInstUsesWith(
I, Res);
1390 if (
I.hasNoNaNs() &&
I.hasAllowReassoc() &&
1393 replaceOperand(
I, 1,
Y);
1399 if (
I.hasNoNaNs() &&
I.hasNoInfs() &&
1404 return replaceInstUsesWith(
I, V);
1421 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1425 return replaceOperand(
I, 1, V);
1428 if (simplifyDivRemOfSelectWithZeroOp(
I))
1436 if (
Instruction *R = FoldOpIntoSelect(
I, cast<SelectInst>(Op1),
1441 if (isa<Constant>(Op1)) {
1442 if (
Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
1446 }
else if (
auto *PN = dyn_cast<PHINode>(Op0I)) {
1447 const APInt *Op1Int;
1449 (
I.getOpcode() == Instruction::URem ||
1460 if (SimplifyDemandedInstructionBits(
I))
1470 SQ.getWithInstruction(&
I)))
1471 return replaceInstUsesWith(
I, V);
1483 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1484 Type *Ty =
I.getType();
1490 return BinaryOperator::CreateAnd(Op0, Add);
1523 SQ.getWithInstruction(&
I)))
1524 return replaceInstUsesWith(
I, V);
1533 Value *Op0 =
I.getOperand(0), *Op1 =
I.getOperand(1);
1552 return BinaryOperator::CreateURem(Op0, Op1,
I.getName());
1556 if (isa<ConstantVector>(Op1) || isa<ConstantDataVector>(Op1)) {
1558 unsigned VWidth = cast<FixedVectorType>(
C->getType())->getNumElements();
1560 bool hasNegative =
false;
1561 bool hasMissing =
false;
1562 for (
unsigned i = 0;
i != VWidth; ++
i) {
1570 if (
RHS->isNegative())
1574 if (hasNegative && !hasMissing) {
1576 for (
unsigned i = 0;
i != VWidth; ++
i) {
1577 Elts[
i] =
C->getAggregateElement(
i);
1579 if (
RHS->isNegative())
1586 return replaceOperand(
I, 1, NewRHSV);
1595 I.getFastMathFlags(),
1596 SQ.getWithInstruction(&
I)))
1597 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 is an optimization pass for GlobalISel generic memory operations.
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)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
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)
static BinaryOperator * CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Instruction *CopyO, const Twine &Name="", Instruction *InsertBefore=nullptr)
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
NOTE: This is soft-deprecated. Please use getSignificantBits() instead.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Value * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
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)
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
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.
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)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
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)
constexpr 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.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
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)
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
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.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
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.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
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)
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.
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FMul, fold the result or return null.
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.
An efficient, type-erasing, non-owning reference to a callable.
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)
match_combine_and< class_match< Constant >, match_unless< class_match< ConstantExpr > > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
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.
bool hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
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)
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.
StandardInstrumentations SI(Debug, VerifyEach)
This class represents the LLVM 'select' instruction.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
A Module instance is used to store all the information related to an LLVM module.
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.
Value * SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FDiv, fold the result or return null.
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.
Common base class shared among various IRBuilders.
Instruction * visitFMul(BinaryOperator &I)
bool isExact() const
Determine whether the exact flag is set.
static Constant * get(ArrayRef< Constant * > V)
static Constant * getFMul(Constant *C1, Constant *C2)
This class represents a sign extension of integer types.
StringRef getName() const
Return a constant reference to the value's name.
static ConstantInt * getFalse(LLVMContext &Context)
static const unsigned MaxDepth
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)
Value * SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FRem, fold the result or return null.
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 Value * takeLog2(IRBuilderBase &Builder, Value *Op, unsigned Depth, bool DoFold)
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.
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.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
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)
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.
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.