29 bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
34 if (
auto *
SC = dyn_cast<SCEVConstant>(S)) {
35 SimplifiedValues[
I] =
SC->getValue();
40 if (!AR || AR->getLoop() != L)
43 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
45 if (
auto *
SC = dyn_cast<SCEVConstant>(ValueAtIteration)) {
46 SimplifiedValues[
I] =
SC->getValue();
59 Address.Base = Base->getValue();
60 Address.Offset =
Offset->getValue();
70 bool UnrolledInstAnalyzer::visitBinaryOperator(
BinaryOperator &I) {
72 if (!isa<Constant>(LHS))
73 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
75 if (!isa<Constant>(RHS))
76 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
79 Value *SimpleV =
nullptr;
81 if (
auto FI = dyn_cast<FPMathOperator>(&I))
87 if (
Constant *
C = dyn_cast_or_null<Constant>(SimpleV))
88 SimplifiedValues[&I] =
C;
96 bool UnrolledInstAnalyzer::visitLoad(
LoadInst &I) {
99 auto AddressIt = SimplifiedAddresses.find(AddrOp);
100 if (AddressIt == SimplifiedAddresses.end())
102 ConstantInt *SimplifiedAddrOp = AddressIt->second.Offset;
107 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
124 int64_t SimplifiedAddrOpV = SimplifiedAddrOp->
getSExtValue();
125 if (SimplifiedAddrOpV < 0) {
130 uint64_t Index =
static_cast<uint64_t
>(SimplifiedAddrOpV) / ElemSize;
138 assert(CV &&
"Constant expected.");
139 SimplifiedValues[&
I] = CV;
145 bool UnrolledInstAnalyzer::visitCastInst(
CastInst &I) {
149 COp = SimplifiedValues.lookup(I.
getOperand(0));
159 SimplifiedValues[&
I] =
C;
168 bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &I) {
172 if (!isa<Constant>(LHS))
173 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
175 if (!isa<Constant>(RHS))
176 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
179 if (!isa<Constant>(LHS) && !isa<Constant>(RHS)) {
180 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
181 if (SimplifiedLHS != SimplifiedAddresses.end()) {
182 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
183 if (SimplifiedRHS != SimplifiedAddresses.end()) {
184 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
185 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
186 if (LHSAddr.Base == RHSAddr.Base) {
187 LHS = LHSAddr.Offset;
188 RHS = RHSAddr.Offset;
194 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
195 if (
Constant *CRHS = dyn_cast<Constant>(RHS)) {
196 if (CLHS->getType() == CRHS->getType()) {
198 SimplifiedValues[&
I] =
C;
208 bool UnrolledInstAnalyzer::visitPHINode(
PHINode &PN) {
A parsed version of the target data layout string in and methods for querying it. ...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
This class is the base class for the comparison instructions.
bool visitCmpInst(CmpInst &I)
bool visitCastInst(CastInst &I)
const SCEV * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
An instruction for reading from memory.
bool visitPHINode(PHINode &I)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
BlockT * getHeader() const
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
This node represents a polynomial recurrence on the trip count of the specified loop.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
unsigned getActiveBits() const
Compute the number of active bits in the value.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
This is an important base class in LLVM.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
Value * getOperand(unsigned i) const
Value * getPointerOperand()
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, const FastMathFlags &FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an FP BinaryOperator, fold the result or return null.
Predicate getPredicate() const
Return the predicate for this instruction.
BinaryOps getOpcode() const
bool visitBinaryOperator(BinaryOperator &I)
This is the shared class of boolean and integer constants.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Type * getType() const
All values are typed, get the type of this value.
CHAIN = SC CHAIN, Imm128 - System call.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for a BinaryOperator, fold the result or return null.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This class represents an analyzed expression in the program.
unsigned getNumElements() const
Return the number of elements in the array or vector.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getElementType() const
Return the element type of the array/vector.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
const BasicBlock * getParent() const
This class represents a constant integer value.