15#ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
16#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEINTERNAL_H
32#define DEBUG_TYPE "instcombine"
63 public InstVisitor<InstCombinerImpl, Instruction *> {
91 Value *OptimizePointerDifference(
113 Value *reassociateShiftAmtsOfTwoSameDirectionShifts(
115 bool AnalyzeForSignBitExtraction =
false);
116 Instruction *canonicalizeCondSignextOfHighBitExtractToSignextHighBitExtract(
118 Instruction *foldVariableSignZeroExtensionOfVariableHighBitExtract(
192 const unsigned SIOpd);
195 const Twine &Suffix =
"");
199 bool isDesirableIntType(
unsigned BitWidth)
const;
200 bool shouldChangeType(
unsigned FromBitWidth,
unsigned ToBitWidth)
const;
213 bool shouldOptimizeCast(
CastInst *CI);
234 bool transformConstExprCastCall(
CallBase &Call);
256 bool willNotOverflowSignedAdd(
const Value *LHS,
const Value *RHS,
262 bool willNotOverflowUnsignedAdd(
const Value *LHS,
const Value *RHS,
268 bool willNotOverflowAdd(
const Value *LHS,
const Value *RHS,
270 return IsSigned ? willNotOverflowSignedAdd(LHS, RHS, CxtI)
271 : willNotOverflowUnsignedAdd(
LHS,
RHS, CxtI);
274 bool willNotOverflowSignedSub(
const Value *LHS,
const Value *RHS,
280 bool willNotOverflowUnsignedSub(
const Value *LHS,
const Value *RHS,
286 bool willNotOverflowSub(
const Value *LHS,
const Value *RHS,
288 return IsSigned ? willNotOverflowSignedSub(LHS, RHS, CxtI)
289 : willNotOverflowUnsignedSub(
LHS,
RHS, CxtI);
292 bool willNotOverflowSignedMul(
const Value *LHS,
const Value *RHS,
298 bool willNotOverflowUnsignedMul(
const Value *LHS,
const Value *RHS,
304 bool willNotOverflowMul(
const Value *LHS,
const Value *RHS,
306 return IsSigned ? willNotOverflowSignedMul(LHS, RHS, CxtI)
307 : willNotOverflowUnsignedMul(
LHS,
RHS, CxtI);
312 bool IsSigned)
const {
314 case Instruction::Add:
return willNotOverflowAdd(LHS, RHS, CxtI, IsSigned);
315 case Instruction::Sub:
return willNotOverflowSub(LHS, RHS, CxtI, IsSigned);
316 case Instruction::Mul:
return willNotOverflowMul(LHS, RHS, CxtI, IsSigned);
334 void freelyInvertAllUsersOf(
Value *V,
Value *IgnoredUser =
nullptr);
348 Value *simplifyIntToPtrRoundTripCast(
Value *Val);
351 bool IsAnd,
bool IsLogical =
false);
363 bool IsLogicalSelect =
false);
369 canonicalizeConditionalNegationViaMathToSelect(
BinaryOperator &i);
373 bool IsLogical =
false);
375 bool InvertFalseVal =
false);
410 assert(
I.use_empty() &&
"Cannot erase instruction that is used!");
415 for (
Use &Operand :
I.operands())
416 if (
auto *Inst = dyn_cast<Instruction>(Operand))
473 unsigned Depth = 0)
override;
479 const APInt &DemandedMask,
485 Value *simplifyShrShlDemandedBits(
491 bool SimplifyDemandedInstructionBits(
Instruction &Inst);
495 bool AllowMultipleUsers =
false)
override;
522 bool FoldWithMultiUse =
false);
543 bool foldIntegerTypedPHI(
PHINode &PN);
644 bool mergeStoreIntoSuccessor(
StoreInst &SI);
650 bool MatchBitReversals);
674 const bool IsTrulyNegation;
682 unsigned NumValuesVisitedInThisNegator = 0;
686 using Result = std::pair<ArrayRef<Instruction *> ,
689 std::array<Value *, 2> getSortedOperandsOfBinOp(
Instruction *
I);
697 [[nodiscard]] std::optional<Result> run(
Value *Root);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu AMDGPU Register Bank Select
SmallVector< MachineOperand, 4 > Cond
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static bool foldICmpWithDominatingICmp(CmpInst *Cmp, const TargetLowering &TLI)
For pattern like:
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int Opcode)
static constexpr unsigned NegatorMaxNodesSSO
static constexpr unsigned NegatorDefaultMaxDepth
This file provides the interface for the instcombine pass implementation.
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...
static const uint32_t IV[8]
Class for arbitrary precision integers.
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
This class represents any memset intrinsic.
A cache of @llvm.assume calls within a function.
an instruction that atomically reads a memory location, combines it with another value,...
LLVM Basic Block Representation.
This class represents a no-op cast from one type to another.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This is the shared class of boolean and integer constants.
static ConstantInt * getTrue(LLVMContext &Context)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This instruction compares its operands according to the predicate given to the constructor.
This class represents a cast from floating point to signed integer.
This class represents a cast from floating point to unsigned integer.
This class represents a truncation of floating point types.
An instruction for ordering other memory operations.
This class represents a freeze function that returns random concrete value if an operand is either a ...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction compares its operands according to the predicate given to the constructor.
This instruction inserts a single (scalar) element into a VectorType value.
This instruction inserts a struct field of array element value into an aggregate value.
virtual ~InstCombinerImpl()=default
Instruction * foldVectorSelect(SelectInst &Sel)
Instruction * foldSelectValueEquivalence(SelectInst &SI, ICmpInst &ICI)
Instruction * foldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1, Value *A, Value *B, Instruction &Outer, SelectPatternFlavor SPF2, Value *C)
Instruction * eraseInstFromFunction(Instruction &I) override
Combiner aware instruction erasure.
Instruction * foldSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI)
Instruction * visitInstruction(Instruction &I)
Specify what to return for unhandled instructions.
InstCombinerImpl(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, const DataLayout &DL, LoopInfo *LI)
void CreateNonTerminatorUnreachable(Instruction *InsertAt)
Create and insert the idiom we use to indicate a block is unreachable without having to rewrite the C...
Instruction * visitSelectInst(SelectInst &SI)
Instruction * foldSelectOfBools(SelectInst &SI)
Instruction * foldSelectExtConst(SelectInst &Sel)
The core instruction combiner logic.
Base class for instruction visitors.
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
This class represents a cast from an integer to a pointer.
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
An instruction for reading from memory.
static Value * Negate(bool LHSIsZero, Value *Root, InstCombinerImpl &IC)
Attempt to negate Root.
This is a utility class that provides an abstraction for the common functionality between Instruction...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis providing profile information.
This class represents a cast from a pointer to an integer.
Return a value (possibly void), from a function.
This class represents a sign extension of integer types.
This class represents the LLVM 'select' instruction.
This instruction constructs a fixed permutation of two input vectors.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
This class represents a truncation of integer types.
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.
static PointerType * getInt1PtrTy(LLVMContext &C, unsigned AS=0)
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
This represents the llvm.va_end intrinsic.
LLVM Value Representation.
LLVMContext & getContext() const
All values hold a context through their type.
This class represents zero extension of integer types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ NeverOverflows
Never overflows.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)
void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
SelectPatternFlavor
Specific patterns of select instructions we can match.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
constexpr unsigned BitWidth
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)