37using namespace PatternMatch;
39#define DEBUG_TYPE "aggressive-instcombine"
41STATISTIC(NumAnyOrAllBitsSet,
"Number of any/all-bits-set patterns folded");
43 "Number of guarded rotates transformed into funnel shifts");
45 "Number of guarded funnel shifts transformed into funnel shifts");
46STATISTIC(NumPopCountRecognized,
"Number of popcount idioms recognized");
50 cl::desc(
"Max number of instructions to scan for aggressive instcombine."));
54 cl::desc(
"The maximum length of a constant string for a builtin string cmp "
55 "call eligible for inlining. The default value is 3."));
61 if (
I.getOpcode() != Instruction::PHI ||
I.getNumOperands() != 2)
75 unsigned Width = V->getType()->getScalarSizeInBits();
83 return Intrinsic::fshl;
92 return Intrinsic::fshr;
104 unsigned FunnelOp = 0, GuardOp = 1;
105 Value *P0 = Phi.getOperand(0), *P1 = Phi.getOperand(1);
106 Value *ShVal0, *ShVal1, *ShAmt;
109 (IID == Intrinsic::fshl && ShVal0 != P1) ||
110 (IID == Intrinsic::fshr && ShVal1 != P1)) {
113 (IID == Intrinsic::fshl && ShVal0 != P0) ||
114 (IID == Intrinsic::fshr && ShVal1 != P0))
116 assert((IID == Intrinsic::fshl || IID == Intrinsic::fshr) &&
117 "Pattern must match funnel shift left or right");
125 BasicBlock *GuardBB = Phi.getIncomingBlock(GuardOp);
126 BasicBlock *FunnelBB = Phi.getIncomingBlock(FunnelOp);
144 if (ShVal0 == ShVal1)
147 ++NumGuardedFunnelShifts;
151 bool IsFshl = IID == Intrinsic::fshl;
152 if (ShVal0 != ShVal1) {
174 Phi.replaceAllUsesWith(Builder.
CreateCall(
F, {ShVal0, ShVal1, ShAmt}));
220 const APInt *BitIndex =
nullptr;
226 MOps.
Root = Candidate;
234 return MOps.
Root == Candidate;
248 bool MatchAllBitsSet;
250 MatchAllBitsSet =
true;
252 MatchAllBitsSet =
false;
256 MaskOps MOps(
I.getType()->getScalarSizeInBits(), MatchAllBitsSet);
257 if (MatchAllBitsSet) {
273 I.replaceAllUsesWith(Zext);
274 ++NumAnyOrAllBitsSet;
290 if (
I.getOpcode() != Instruction::LShr)
293 Type *Ty =
I.getType();
299 if (!(Len <= 128 && Len > 8 && Len % 8 == 0))
308 Value *Op0 =
I.getOperand(0);
309 Value *Op1 =
I.getOperand(1);
325 Value *Root, *SubOp1;
333 I.getModule(), Intrinsic::ctpop,
I.getType());
334 I.replaceAllUsesWith(Builder.
CreateCall(Func, {Root}));
335 ++NumPopCountRecognized;
356 const APInt *MinC, *MaxC;
366 if (!(*MinC + 1).isPowerOf2() || -*MaxC != *MinC + 1)
369 Type *IntTy =
I.getType();
370 Type *FpTy = In->getType();
373 if (
auto *VecTy = dyn_cast<VectorType>(IntTy))
374 SatTy = VectorType::get(SatTy, VecTy->getElementCount());
395 if (SatCost >= MinMaxCost)
402 I.replaceAllUsesWith(Builder.
CreateSExt(Sat, IntTy));
413 Module *M = Call->getModule();
421 Type *Ty = Call->getType();
422 Value *Arg = Call->getArgOperand(0);
424 (Call->hasNoNaNs() ||
426 Arg, 0,
SimplifyQuery(M->getDataLayout(), &TLI, &DT, &AC, Call)))) {
433 Call->replaceAllUsesWith(NewSqrt);
437 Call->eraseFromParent();
450 if (Length < InputBits || Length > InputBits * 2)
454 unsigned Matched = 0;
456 for (
unsigned i = 0; i <
Length; i++) {
458 if (Element >= InputBits)
465 if ((((
Mul << Element) & Mask.getZExtValue()) >> Shift) == i)
469 return Matched == InputBits;
536 if (!
GEP || !
GEP->isInBounds() ||
GEP->getNumIndices() != 2)
539 if (!
GEP->getSourceElementType()->isArrayTy())
542 uint64_t ArraySize =
GEP->getSourceElementType()->getArrayNumElements();
543 if (ArraySize != 32 && ArraySize != 64)
558 Value *Idx2 = std::next(
GEP->idx_begin())->get();
570 if (InputBits != 32 && InputBits != 64)
574 if (InputBits -
Log2_32(InputBits) != ShiftConst &&
575 InputBits -
Log2_32(InputBits) - 1 != ShiftConst)
578 if (!
isCTTZTable(*ConstData, MulConst, ShiftConst, InputBits))
582 bool DefinedForZero = ZeroTableElem == InputBits;
587 auto Cttz =
B.CreateIntrinsic(Intrinsic::cttz, {XType}, {X1, BoolConst});
588 Value *ZExtOrTrunc =
nullptr;
590 if (DefinedForZero) {
591 ZExtOrTrunc =
B.CreateZExtOrTrunc(Cttz, AccessType);
595 auto Cmp =
B.CreateICmpEQ(X1, ConstantInt::get(XType, 0));
597 B.CreateSelect(Cmp, ConstantInt::get(XType, ZeroTableElem), Cttz);
602 ZExtOrTrunc =
B.CreateZExtOrTrunc(
Select, AccessType);
628 const APInt *ShAmt2 =
nullptr;
652 LI1 = dyn_cast<LoadInst>(L1);
654 LoadInst *LI2 = dyn_cast<LoadInst>(L2);
666 bool IsBigEndian =
DL.isBigEndian();
684 if (Load1Ptr != Load2Ptr || LoadSize1 != LoadSize2)
694 if (!Start->comesBefore(
End)) {
701 unsigned NumScanned = 0;
715 if (Offset2.
slt(Offset1)) {
746 uint64_t ShiftDiff = IsBigEndian ? LoadSize2 : LoadSize1;
749 if ((Shift2 - Shift1) != ShiftDiff || (Offset2 - Offset1) != PrevSize)
759 LOps.
LoadSize = LoadSize1 + LoadSize2;
778 if (isa<VectorType>(
I.getType()))
794 unsigned AS = LI1->getPointerAddressSpace();
797 AS, LI1->getAlign(), &
Fast);
798 if (!Allowed || !
Fast)
802 Value *Load1Ptr = LI1->getPointerOperand();
813 LI1->isVolatile(),
"");
819 Value *NewOp = NewLoad;
827 NewOp = Builder.
CreateShl(NewOp, ConstantInt::get(
I.getContext(), *LOps.
Shift));
828 I.replaceAllUsesWith(NewOp);
835static std::pair<APInt, APInt>
837 unsigned BW =
DL.getIndexTypeSizeInBits(PtrOp->
getType());
838 std::optional<APInt> Stride;
839 APInt ModOffset(BW, 0);
842 while (
auto *
GEP = dyn_cast<GEPOperator>(PtrOp)) {
844 if (!
GEP->collectOffset(
DL, BW, VarOffsets, ModOffset))
847 for (
auto [V, Scale] : VarOffsets) {
849 if (!
GEP->isInBounds())
858 PtrOp =
GEP->getPointerOperand();
863 if (!isa<GlobalVariable>(PtrOp) || !Stride)
868 ModOffset = ModOffset.
srem(*Stride);
870 ModOffset += *Stride;
872 return {*Stride, ModOffset};
878 auto *LI = dyn_cast<LoadInst>(&
I);
879 if (!LI || LI->isVolatile())
884 auto *PtrOp = LI->getPointerOperand();
886 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
891 uint64_t GVSize =
DL.getTypeAllocSize(
C->getType());
892 if (!GVSize || 4096 < GVSize)
895 Type *LoadTy = LI->getType();
896 unsigned BW =
DL.getIndexTypeSizeInBits(PtrOp->getType());
902 if (
auto LA = LI->getAlign();
903 LA <= GV->
getAlign().valueOrOne() && Stride.getZExtValue() < LA.value()) {
904 ConstOffset =
APInt(BW, 0);
905 Stride =
APInt(BW, LA.value());
912 unsigned E = GVSize -
DL.getTypeStoreSize(LoadTy);
913 for (; ConstOffset.getZExtValue() <= E; ConstOffset += Stride)
917 I.replaceAllUsesWith(Ca);
923class StrNCmpInliner {
929 bool optimizeStrNCmp();
970bool StrNCmpInliner::optimizeStrNCmp() {
977 Value *Str1P = CI->getArgOperand(0);
978 Value *Str2P = CI->getArgOperand(1);
986 if (HasStr1 == HasStr2)
991 Value *StrP = HasStr1 ? Str2P : Str1P;
993 size_t Idx = Str.find(
'\0');
995 if (Func == LibFunc_strncmp) {
996 if (
auto *ConstInt = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
997 N = std::min(
N, ConstInt->getZExtValue());
1007 bool CanBeNull =
false, CanBeFreed =
false;
1010 inlineCompare(StrP, Str,
N, HasStr1);
1050 auto &Ctx = CI->getContext();
1063 cast<BranchInst>(BBCI->
getTerminator())->setSuccessor(0, BBSubs[0]);
1065 B.SetInsertPoint(BBNE);
1071 B.SetInsertPoint(BBSubs[i]);
1073 B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
1074 B.CreateInBoundsPtrAdd(
Base,
B.getInt64(i))),
1076 Value *VR = ConstantInt::get(CI->getType(), RHS[i]);
1077 Value *Sub = Swapped ?
B.CreateSub(VR, VL) :
B.CreateSub(VL, VR);
1079 B.CreateCondBr(
B.CreateICmpNE(Sub, ConstantInt::get(CI->getType(), 0)),
1080 BBNE, BBSubs[i + 1]);
1084 Phi->addIncoming(Sub, BBSubs[i]);
1087 CI->replaceAllUsesWith(Phi);
1088 CI->eraseFromParent();
1092 Updates.
push_back({DominatorTree::Insert, BBCI, BBSubs[0]});
1095 Updates.
push_back({DominatorTree::Insert, BBSubs[i], BBSubs[i + 1]});
1096 Updates.
push_back({DominatorTree::Insert, BBSubs[i], BBNE});
1098 Updates.
push_back({DominatorTree::Insert, BBNE, BBTail});
1099 Updates.
push_back({DominatorTree::Delete, BBCI, BBTail});
1100 DTU->applyUpdates(Updates);
1107 bool &MadeCFGChange) {
1109 auto *CI = dyn_cast<CallInst>(&
I);
1110 if (!CI || CI->isNoBuiltin())
1113 Function *CalledFunc = CI->getCalledFunction();
1129 case LibFunc_strcmp:
1130 case LibFunc_strncmp:
1131 if (StrNCmpInliner(CI, LF, &DTU,
DL).optimizeStrNCmp()) {
1132 MadeCFGChange =
true;
1148 bool MadeChange =
false;
1189 bool MadeChange =
false;
1192 MadeChange |= TIC.
run(
F);
1204 bool MadeCFGChange =
false;
1205 if (!
runImpl(
F, AC,
TTI, TLI, DT, AA, MadeCFGChange)) {
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu AMDGPU Register Bank Select
static bool tryToRecognizePopCount(Instruction &I)
static bool foldSqrt(CallInst *Call, LibFunc Func, TargetTransformInfo &TTI, TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree &DT)
Try to replace a mathlib call to sqrt with the LLVM intrinsic.
static bool foldAnyOrAllBitsSet(Instruction &I)
Match patterns that correspond to "any-bits-set" and "all-bits-set".
static bool tryToFPToSat(Instruction &I, TargetTransformInfo &TTI)
Fold smin(smax(fptosi(x), C1), C2) to llvm.fptosi.sat(x), providing C1 and C2 saturate the value of t...
static cl::opt< unsigned > StrNCmpInlineThreshold("strncmp-inline-threshold", cl::init(3), cl::Hidden, cl::desc("The maximum length of a constant string for a builtin string cmp " "call eligible for inlining. The default value is 3."))
static bool matchAndOrChain(Value *V, MaskOps &MOps)
This is a recursive helper for foldAnyOrAllBitsSet() that walks through a chain of 'and' or 'or' inst...
static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, TargetTransformInfo &TTI, AliasAnalysis &AA, const DominatorTree &DT)
static bool runImpl(Function &F, AssumptionCache &AC, TargetTransformInfo &TTI, TargetLibraryInfo &TLI, DominatorTree &DT, AliasAnalysis &AA, bool &MadeCFGChange)
This is the entry point for all transforms.
static bool tryToRecognizeTableBasedCttz(Instruction &I)
static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT)
Match a pattern for a bitwise funnel/rotate operation that partially guards against undefined behavio...
static cl::opt< unsigned > MaxInstrsToScan("aggressive-instcombine-max-scan-instrs", cl::init(64), cl::Hidden, cl::desc("Max number of instructions to scan for aggressive instcombine."))
static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL, AliasAnalysis &AA)
static std::pair< APInt, APInt > getStrideAndModOffsetOfGEP(Value *PtrOp, const DataLayout &DL)
static bool isCTTZTable(const ConstantDataArray &Table, uint64_t Mul, uint64_t Shift, uint64_t InputBits)
static bool foldPatternedLoads(Instruction &I, const DataLayout &DL)
If C is a constant patterned array and all valid loaded results for given alignment are same to a con...
static bool foldLibCalls(Instruction &I, TargetTransformInfo &TTI, TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree &DT, const DataLayout &DL, bool &MadeCFGChange)
static bool foldUnusualPatterns(Function &F, DominatorTree &DT, TargetTransformInfo &TTI, TargetLibraryInfo &TLI, AliasAnalysis &AA, AssumptionCache &AC, bool &MadeCFGChange)
This is the entry point for folds that could be implemented in regular InstCombine,...
AggressiveInstCombiner - Combine expression patterns to form expressions with fewer,...
This is the interface for LLVM's primary stateless and local alias analysis.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool runImpl(Function &F, const TargetLowering &TLI)
This is the interface for a simple mod/ref and alias analysis over globals.
static MaybeAlign getAlign(Value *Ptr)
static Instruction * matchFunnelShift(Instruction &Or, InstCombinerImpl &IC)
Match UB-safe variants of the funnel shift intrinsic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A manager for alias analyses.
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location.
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isNegative() const
Determine sign of this APInt.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool slt(const APInt &RHS) const
Signed less than comparison.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Represents analyses that only rely on functions' control flow.
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
unsigned getNumElements() const
Return the number of elements in the array or vector.
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", bool IsInBounds=false)
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateFreeze(Value *V, const Twine &Name="")
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setAAMetadata(const AAMDNodes &N)
Sets the AA metadata on this instruction from the AAMDNodes structure.
const BasicBlock * getParent() const
AAMDNodes getAAMetadata() const
Returns the AA metadata for this instruction.
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
An instruction for reading from memory.
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
Value * getPointerOperand()
This class implements a map that also provides access to all stored values in a deterministic order.
Representation for a specific memory location.
MemoryLocation getWithNewSize(LocationSize NewSize) const
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
void preserve()
Mark an analysis as preserved.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool run(Function &F)
Perform TruncInst pattern optimization on given function.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
APInt GreatestCommonDivisor(APInt A, APInt B)
Compute GCD of two unsigned APInt values.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ C
The default llvm calling convention, compatible with C.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
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< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
bool match(Val *V, const Pattern &P)
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
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()...
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
OneUse_match< T > m_OneUse(const T &SubPattern)
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
CastInst_match< OpTy, FPToSIInst > m_FPToSI(const OpTy &Op)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
initializer< Ty > init(const Ty &Val)
NodeAddr< PhiNode * > Phi
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
bool isOnlyUsedInZeroComparison(const Instruction *CxtI)
bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI, LibFunc TheLibFunc)
Check whether the library function is available on target and also that it in the current Module is a...
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
bool isModSet(const ModRefInfo MRI)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
@ And
Bitwise or logical AND of integers.
constexpr unsigned BitWidth
BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth, const SimplifyQuery &SQ)
Return true if we can prove that the specified FP value is either NaN or never less than -0....
bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This is used by foldLoadsRecursive() to capture a Root Load node which is of type or(load,...
This is used by foldAnyOrAllBitsSet() to capture a source value (Root) and the bit indexes (Mask) nee...
MaskOps(unsigned BitWidth, bool MatchAnds)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
AAMDNodes concat(const AAMDNodes &Other) const
Determine the best AAMDNodes after concatenating two different locations together.