21 #define DEBUG_TYPE "instcombine" 36 bool AnalyzeForSignBitExtraction) {
48 Value *Trunc =
nullptr;
73 unsigned MaximalPossibleTotalShiftAmount =
76 APInt MaximalRepresentableShiftAmount =
78 if (MaximalRepresentableShiftAmount.
ult(MaximalPossibleTotalShiftAmount))
85 if (AnalyzeForSignBitExtraction && !HadTwoRightShifts)
92 if (!IdenticalShOpcodes && !AnalyzeForSignBitExtraction)
98 if (Trunc && !AnalyzeForSignBitExtraction &&
103 auto *NewShAmt = dyn_cast_or_null<Constant>(
108 unsigned NewShAmtBitWidth = NewShAmt->getType()->getScalarSizeInBits();
112 APInt(NewShAmtBitWidth, XBitWidth))))
120 if (HadTwoRightShifts && (Trunc || AnalyzeForSignBitExtraction)) {
124 APInt(NewShAmtBitWidth, XBitWidth - 1))))
127 if (AnalyzeForSignBitExtraction)
131 assert(IdenticalShOpcodes &&
"Should not get here with different shifts.");
142 if (ShiftOpcode == Instruction::BinaryOps::Shl) {
154 Builder.Insert(NewShift);
182 "The input must be 'shl'!");
184 Value *Masked, *ShiftShAmt;
196 Type *WidestTy = Masked->getType();
197 bool HadTrunc = WidestTy != NarrowestTy;
224 if (MaskShAmt->
getType() != ShiftShAmt->getType())
229 MaskShAmt, ShiftShAmt,
false,
false, Q));
245 auto *ExtendedInvertedMask =
256 if (MaskShAmt->
getType() != ShiftShAmt->getType())
261 ShiftShAmt, MaskShAmt,
false,
false, Q));
296 if (!Masked->hasOneUse())
327 if (!LogicInst || !LogicInst->isBitwiseLogicOp() || !LogicInst->hasOneUse())
330 const APInt *C0, *C1;
341 auto matchFirstShift = [&](
Value *V) {
342 return !isa<ConstantExpr>(V) &&
344 cast<BinaryOperator>(V)->
getOpcode() == ShiftOpcode &&
349 if (matchFirstShift(LogicInst->getOperand(0)))
350 Y = LogicInst->getOperand(1);
351 else if (matchFirstShift(LogicInst->getOperand(1)))
352 Y = LogicInst->getOperand(0);
370 Value *NewExt = Builder.CreateZExt(Y, I.
getType(), Op1->getName());
375 if (SimplifyDemandedInstructionBits(I))
379 if (isa<Constant>(Op0))
384 if (
Constant *CUI = dyn_cast<Constant>(Op1))
385 if (
Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
388 if (
auto *NewShift = cast_or_null<Instruction>(
389 reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ)))
429 const APInt *InnerShiftConst;
436 bool IsInnerShl = InnerShift->
getOpcode() == Instruction::Shl;
437 if (IsInnerShl == IsOuterShl)
443 if (*InnerShiftConst == OuterShAmt)
453 if (InnerShiftConst->ugt(OuterShAmt) && InnerShiftConst->ult(TypeWidth)) {
454 unsigned InnerShAmt = InnerShiftConst->getZExtValue();
456 IsInnerShl ? TypeWidth - InnerShAmt : InnerShAmt - OuterShAmt;
478 if (isa<Constant>(V))
482 if (!I)
return false;
497 uint32_t OrigBitWidth = OrigTy->getScalarSizeInBits();
498 uint32_t BitWidth = Ty->getScalarSizeInBits();
502 return CanEvaluateTruncated(I->
getOperand(0), Ty);
514 default:
return false;
515 case Instruction::And:
516 case Instruction::Or:
517 case Instruction::Xor:
522 case Instruction::Shl:
523 case Instruction::LShr:
533 case Instruction::PHI: {
551 bool IsInnerShl = InnerShift->
getOpcode() == Instruction::Shl;
561 auto NewInnerShift = [&](
unsigned ShAmt) {
575 if (IsInnerShl == IsOuterShl) {
577 if (InnerShAmt + OuterShAmt >= TypeWidth)
580 return NewInnerShift(InnerShAmt + OuterShAmt);
586 if (InnerShAmt == OuterShAmt) {
592 if (
auto *AndI = dyn_cast<Instruction>(And)) {
593 AndI->moveBefore(InnerShift);
599 assert(InnerShAmt > OuterShAmt &&
600 "Unexpected opposite direction logical shift pair");
606 return NewInnerShift(InnerShAmt - OuterShAmt);
614 if (
Constant *
C = dyn_cast<Constant>(V)) {
620 if (
auto *
C = dyn_cast<Constant>(V))
632 case Instruction::And:
633 case Instruction::Or:
634 case Instruction::Xor:
642 case Instruction::Shl:
643 case Instruction::LShr:
653 case Instruction::PHI: {
660 isLeftShift, IC, DL));
674 return Shift.
getOpcode() == Instruction::Shl;
675 case Instruction::Or:
676 case Instruction::Xor:
677 case Instruction::And:
684 bool isLeftShift = I.
getOpcode() == Instruction::Shl;
692 if (I.
getOpcode() != Instruction::AShr &&
695 dbgs() <<
"ICE: GetShiftedValue propagating shift through expression" 696 " to eliminate shift:\n IN: " 697 << *Op0 <<
"\n SH: " << I <<
"\n");
699 return replaceInstUsesWith(
708 "Shift over the type width should have been removed already");
710 if (
Instruction *FoldedShift = foldBinOpIntoSelectOrPhi(I))
714 if (
TruncInst *TI = dyn_cast<TruncInst>(Op0)) {
734 unsigned DstSize = TI->getType()->getScalarSizeInBits();
749 Value *And = Builder.CreateAnd(NSh,
763 switch (Op0BO->getOpcode()) {
766 case Instruction::And:
767 case Instruction::Or:
768 case Instruction::Xor: {
771 if (isLeftShift && Op0BO->getOperand(1)->hasOneUse() &&
775 Builder.CreateShl(Op0BO->getOperand(0), Op1, Op0BO->
getName());
777 Value *
X = Builder.CreateBinOp(Op0BO->getOpcode(), YS, V1,
778 Op0BO->getOperand(1)->
getName());
785 return BinaryOperator::CreateAnd(X, Mask);
789 Value *Op0BOOp1 = Op0BO->getOperand(1);
790 if (isLeftShift && Op0BOOp1->
hasOneUse() &&
795 Builder.CreateShl(Op0BO->getOperand(0), Op1, Op0BO->
getName());
804 case Instruction::Sub: {
806 if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
810 Builder.CreateShl(Op0BO->getOperand(1), Op1, Op0BO->
getName());
812 Value *
X = Builder.CreateBinOp(Op0BO->getOpcode(), V1, YS,
813 Op0BO->getOperand(0)->
getName());
820 return BinaryOperator::CreateAnd(X, Mask);
824 if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
825 match(Op0BO->getOperand(0),
829 Builder.CreateShl(Op0BO->getOperand(1), Op1, Op0BO->
getName());
848 cast<Constant>(Op0BO->getOperand(1)), Op1);
851 Builder.CreateBinOp(I.
getOpcode(), Op0BO->getOperand(0), Op1);
862 if (isLeftShift && Op0BO->getOpcode() == Instruction::Sub &&
865 cast<Constant>(Op0BO->getOperand(0)), Op1);
867 Value *NewShift = Builder.CreateShl(Op0BO->getOperand(1), Op1);
870 return BinaryOperator::CreateSub(NewRHS, NewShift);
888 if (!isa<Constant>(FalseVal) && TBO->
getOperand(0) == FalseVal &&
895 Builder.CreateBinOp(I.
getOpcode(), FalseVal, Op1);
907 if (!isa<Constant>(TrueVal) && FBO->
getOperand(0) == TrueVal &&
914 Builder.CreateBinOp(I.
getOpcode(), TrueVal, Op1);
930 return replaceInstUsesWith(I, V);
945 const APInt *ShAmtAPInt;
954 if (ShAmt < SrcWidth &&
956 return new ZExtInst(Builder.CreateShl(X, ShAmt), Ty);
970 if (ShrAmt < ShAmt) {
973 auto *NewShl = BinaryOperator::CreateShl(X, ShiftDiff);
978 if (ShrAmt > ShAmt) {
982 cast<BinaryOperator>(Op0)->
getOpcode(), X, ShiftDiff);
983 NewShr->setIsExact(
true);
991 if (AmtSum < BitWidth)
1015 Value *
Mask = Builder.CreateShl(AllOnes, Op1);
1016 return BinaryOperator::CreateAnd(Mask, X);
1041 return BinaryOperator::CreateLShr(
1049 SQ.getWithInstruction(&I)))
1050 return replaceInstUsesWith(I, V);
1060 const APInt *ShAmtAPInt;
1066 (II->getIntrinsicID() == Intrinsic::ctlz ||
1067 II->getIntrinsicID() == Intrinsic::cttz ||
1068 II->getIntrinsicID() == Intrinsic::ctpop)) {
1074 Value *Cmp = Builder.CreateICmpEQ(II->getArgOperand(0), RHS);
1081 if (ShOp1->
ult(ShAmt)) {
1086 auto *NewLShr = BinaryOperator::CreateLShr(X, ShiftDiff);
1087 NewLShr->setIsExact(I.
isExact());
1091 Value *NewLShr = Builder.CreateLShr(X, ShiftDiff,
"", I.
isExact());
1095 if (ShOp1->
ugt(ShAmt)) {
1100 auto *NewShl = BinaryOperator::CreateShl(X, ShiftDiff);
1101 NewShl->setHasNoUnsignedWrap(
true);
1105 Value *NewShl = Builder.CreateShl(X, ShiftDiff);
1118 "Big shift not simplified to zero?");
1120 Value *NewLShr = Builder.CreateLShr(X, ShAmt);
1128 if (ShAmt == BitWidth - 1) {
1130 if (SrcTyBitWidth == 1)
1135 Value *NewLShr = Builder.CreateLShr(X, SrcTyBitWidth - 1);
1141 if (ShAmt == BitWidth - SrcTyBitWidth && Op0->
hasOneUse()) {
1143 unsigned NewShAmt = std::min(ShAmt, SrcTyBitWidth - 1);
1144 Value *AShr = Builder.CreateAShr(X, NewShAmt);
1152 if (AmtSum < BitWidth)
1169 Value *
Mask = Builder.CreateLShr(AllOnes, Op1);
1170 return BinaryOperator::CreateAnd(Mask, X);
1180 "Must be called with arithmetic right-shift instruction only.");
1187 V->getType()->getScalarSizeInBits())));
1195 if (!
match(&OldAShr,
1201 !BitWidthSplat(C1, &OldAShr) || !BitWidthSplat(C2, &OldAShr))
1207 bool HadTrunc = MaybeTrunc != HighBitExtract;
1210 Value *
X, *NumLowBitsToSkip;
1216 if (!
match(NumLowBitsToSkip,
1219 !BitWidthSplat(C0, HighBitExtract))
1226 return replaceInstUsesWith(OldAShr, MaybeTrunc);
1241 Builder.Insert(NewAShr);
1247 SQ.getWithInstruction(&I)))
1248 return replaceInstUsesWith(I, V);
1259 const APInt *ShAmtAPInt;
1275 ShOp1->
ult(BitWidth)) {
1277 if (ShlAmt < ShAmt) {
1280 auto *NewAShr = BinaryOperator::CreateAShr(X, ShiftDiff);
1281 NewAShr->setIsExact(I.
isExact());
1284 if (ShlAmt > ShAmt) {
1288 NewShl->setHasNoSignedWrap(
true);
1294 ShOp1->
ult(BitWidth)) {
1297 AmtSum = std::min(AmtSum, BitWidth - 1);
1319 if (
Instruction *R = foldVariableSignZeroExtensionOfVariableHighBitExtract(I))
1324 return BinaryOperator::CreateLShr(Op0, Op1);
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
A parsed version of the target data layout string in and methods for querying it. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static Instruction * foldShiftOfShiftedLogic(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
If we have a shift-by-constant of a bitwise logic op that itself has a shift-by-constant operand with...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
uint64_t getZExtValue() const
Get zero extended value.
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.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
This class represents lattice values for constants.
SimplifyQuery getWithInstruction(Instruction *I) const
BinaryOps getOpcode() const
static Instruction * dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift, const SimplifyQuery &Q, InstCombiner::BuilderTy &Builder)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
This class represents zero extension of integer types.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
static bool canEvaluateShifted(Value *V, unsigned NumBits, bool IsLeftShift, InstCombiner &IC, Instruction *CxtI)
See if we can compute the specified value, but shifted logically to the left or right by some number ...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
const Value * getTrueValue() const
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
LLVMContext & getContext() const
All values hold a context through their type.
void Add(Instruction *I)
Add - Add the specified instruction to the worklist if it isn't already in it.
This class represents a sign extension of integer types.
Value * SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for a Shl, fold the result or return null.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isVectorTy() const
True if this is an instance of VectorType.
void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Value * SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q)
Given operands for a LShr, fold the result or return null.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, OpTy > m_ZExtOrSelf(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
This class represents the LLVM 'select' instruction.
Instruction * commonShiftTransforms(BinaryOperator &I)
Exact_match< T > m_Exact(const T &SubPattern)
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool isIntegerTy() const
True if this is an instance of IntegerType.
The core instruction combiner logic.
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.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static bool canShiftBinOpWithConstantRHS(BinaryOperator &Shift, BinaryOperator *BO)
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Instruction * foldVariableSignZeroExtensionOfVariableHighBitExtract(BinaryOperator &OldAShr)
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the give value is known to be non-negative.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
match_combine_or< CastClass_match< OpTy, Instruction::Trunc >, OpTy > m_TruncOrSelf(const OpTy &Op)
Type * getExtendedType() const
Given scalar/vector integer type, returns a type with elements twice as wide as in the original type...
void takeName(Value *V)
Transfer the name from V to this value.
static Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
This class represents a truncation of integer types.
Value * getOperand(unsigned i) const
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
OneUse_match< T > m_OneUse(const T &SubPattern)
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
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...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
The instances of the Type class are immutable: once they are created, they are never changed...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
This is an important base class in LLVM.
Value * reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0, const SimplifyQuery &SQ, bool AnalyzeForSignBitExtraction=false)
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
specific_intval m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
static Constant * getNot(Constant *C)
static Constant * getAllOnesValue(Type *Ty)
Instruction * visitLShr(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
static wasm::ValType getType(const TargetRegisterClass *RC)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
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 * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
TargetLibraryInfo & getTargetLibraryInfo() const
InstCombineWorklist & Worklist
A worklist of the instructions that need to be simplified.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
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...
static bool canEvaluateShiftedShift(unsigned OuterShAmt, bool IsOuterShl, Instruction *InnerShift, InstCombiner &IC, Instruction *CxtI)
Return true if we can simplify two logical (either left or right) shifts that have constant shift amo...
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.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Class to represent vector types.
Class for arbitrary precision integers.
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.
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
const Value * getFalseValue() const
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth=0, const Instruction *CxtI=nullptr) const
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 ...
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static CastInst * CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a Trunc or BitCast cast instruction.
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...
StringRef getName() const
Return a constant reference to the value's name.
Value * SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q)
Given operands for a AShr, fold the result or return nulll.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
static Value * getShiftedValue(Value *V, unsigned NumBits, bool isLeftShift, InstCombiner &IC, const DataLayout &DL)
When canEvaluateShifted() returns true for an expression, this function inserts the new computation t...
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.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
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())
static Value * foldShiftedShift(BinaryOperator *InnerShift, unsigned OuterShAmt, bool IsOuterShl, InstCombiner::BuilderTy &Builder)
Fold OuterShift (InnerShift X, C1), C2.
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Value * SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for a Sub, fold the result or return null.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
bool hasOneUse() const
Return true if there is exactly one user of this value.
Instruction * visitAShr(BinaryOperator &I)
void setIncomingValue(unsigned i, Value *V)
Instruction * visitShl(BinaryOperator &I)
static BinaryOperator * CreateMul(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
op_range incoming_values()
Instruction * FoldShiftByConstant(Value *Op0, Constant *Op1, BinaryOperator &I)
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
A wrapper class for inspecting calls to intrinsic functions.
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.