34 #define DEBUG_TYPE "aggressive-instcombine" 43 class AggressiveInstCombinerLegacyPass :
public FunctionPass {
79 Value *L0, *L1, *R0, *R1;
86 if (RotL.match(V) && L0 == R0 && L1 == R1) {
89 return Intrinsic::fshl;
95 if (RotR.match(V) && L0 == R0 && L1 == R1) {
98 return Intrinsic::fshr;
109 Value *RotSrc, *RotAmt;
115 assert((IID == Intrinsic::fshl || IID == Intrinsic::fshr) &&
116 "Pattern must match funnel shift left or right");
165 : Root(nullptr), Mask(
APInt::getNullValue(BitWidth)),
166 MatchAndChain(MatchAnds), FoundAnd1(
false) {}
197 uint64_t BitIndex = 0;
203 MOps.
Root = Candidate;
211 return MOps.
Root == Candidate;
225 bool MatchAllBitsSet;
227 MatchAllBitsSet =
true;
229 MatchAllBitsSet =
false;
234 if (MatchAllBitsSet) {
235 if (!
matchAndOrChain(cast<BinaryOperator>(&I), MOps) || !MOps.FoundAnd1)
275 if (!(Len <= 128 && Len > 8 && Len % 8 == 0))
301 Value *Root, *SubOp1;
324 bool MadeChange =
false;
353 bool MadeChange =
false;
356 MadeChange |= TIC.
run(F);
361 void AggressiveInstCombinerLegacyPass::getAnalysisUsage(
373 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
374 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
396 "aggressive-instcombine",
397 "Combine pattern based expressions",
false,
false)
413 return new AggressiveInstCombinerLegacyPass();
Legacy wrapper pass to provide the GlobalsAAResult object.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
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 GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool runImpl(Function &F, TargetLibraryInfo &TLI, DominatorTree &DT)
This is the entry point for all transforms.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
This class represents lattice values for constants.
This is the interface for a simple mod/ref and alias analysis over globals.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
A global registry used in conjunction with static constructors to make pluggable components (like tar...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
struct LLVMOpaquePassRegistry * LLVMPassRegistryRef
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...
Analysis pass which computes a DominatorTree.
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...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static bool matchAndOrChain(Value *V, MaskOps &MOps)
This is a recursive helper for foldAnyOrAllBitsSet() that walks through a chain of 'and' or 'or' inst...
aggressive Combine pattern based expressions
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void setBit(unsigned BitPosition)
Set a given bit to 1.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Attribute unwrap(LLVMAttributeRef Attr)
This is used by foldAnyOrAllBitsSet() to capture a source value (Root) and the bit indexes (Mask) nee...
FunctionPass * createAggressiveInstCombinerPass()
Type * getType() const
All values are typed, get the type of this value.
void LLVMInitializeAggressiveInstCombiner(LLVMPassRegistryRef R)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
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.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static bool tryToRecognizePopCount(Instruction &I)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
static bool foldAnyOrAllBitsSet(Instruction &I)
Match patterns that correspond to "any-bits-set" and "all-bits-set".
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Value * getOperand(unsigned i) const
INITIALIZE_PASS_BEGIN(AggressiveInstCombinerLegacyPass, "aggressive-instcombine", "Combine pattern based expressions", false, false) INITIALIZE_PASS_END(AggressiveInstCombinerLegacyPass
OneUse_match< T > m_OneUse(const T &SubPattern)
static bool runOnFunction(Function &F, bool PostInlining)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
static bool foldUnusualPatterns(Function &F, DominatorTree &DT)
This is the entry point for folds that could be implemented in regular InstCombine, but they are separated because they are not expected to occur frequently and/or have more than a constant-length pattern match.
A set of analyses that are preserved following a run of a transformation pass.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
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.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static Instruction * matchRotate(Instruction &Or)
Transform UB-safe variants of bitwise rotate to the funnel shift intrinsic.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
This is an important base class in LLVM.
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.
A manager for alias analyses.
specific_intval m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Represent the analysis usage information of a pass.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Analysis pass providing a never-invalidated alias analysis result.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
FunctionPass class - This class is used to implement most global optimizations.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void initializeAggressiveInstCombine(PassRegistry &)
Initialize all passes linked into the AggressiveInstCombine library.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
bool run(Function &F)
Perform TruncInst pattern optimization on given function.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned getNumOperands() const
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.
static bool foldGuardedRotateToFunnelShift(Instruction &I)
Match a pattern for a bitwise rotate operation that partially guards against undefined behavior by br...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Provides information about what library functions are available for the current target.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
void initializeAggressiveInstCombinerLegacyPassPass(PassRegistry &)
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.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
struct LLVMOpaquePassManager * LLVMPassManagerRef
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
Represents analyses that only rely on functions' control flow.
MaskOps(unsigned BitWidth, bool MatchAnds)
void preserveSet()
Mark an analysis set as preserved.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
void preserve()
Mark an analysis as preserved.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
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.
This is the interface for LLVM's primary stateless and local alias analysis.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const BasicBlock * getParent() const
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Legacy wrapper pass to provide the BasicAAResult object.