34 #define DEBUG_TYPE "aggressive-instcombine" 43 class AggressiveInstCombinerLegacyPass :
public FunctionPass {
72 MaskOps(
unsigned BitWidth,
bool MatchAnds) :
73 Root(nullptr), Mask(
APInt::getNullValue(BitWidth)),
74 MatchAndChain(MatchAnds), FoundAnd1(
false) {}
105 uint64_t BitIndex = 0;
111 MOps.
Root = Candidate;
119 return MOps.
Root == Candidate;
133 bool MatchAllBitsSet;
135 MatchAllBitsSet =
true;
137 MatchAllBitsSet =
false;
142 if (MatchAllBitsSet) {
143 if (!
matchAndOrChain(cast<BinaryOperator>(&I), MOps) || !MOps.FoundAnd1)
166 bool MadeChange =
false;
192 bool MadeChange =
false;
195 MadeChange |= TIC.
run(F);
200 void AggressiveInstCombinerLegacyPass::getAnalysisUsage(
212 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
213 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
235 "aggressive-instcombine",
236 "Combine pattern based expressions",
false,
false)
252 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)
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 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...
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.
Compute iterated dominance frontiers using a linear time algorithm.
This is the interface for a simple mod/ref and alias analysis over globals.
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.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
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
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...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
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.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
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...
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.
LLVM Basic Block Representation.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
This file provides the primary interface to the aggressive instcombine pass.
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.
Represent the analysis usage information of a pass.
Analysis pass providing a never-invalidated alias analysis result.
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
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 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.
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:
struct LLVMOpaquePassManager * LLVMPassManagerRef
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.
void preserve()
Mark an analysis as preserved.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Analysis pass providing the TargetLibraryInfo.
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...
Legacy wrapper pass to provide the BasicAAResult object.