31bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
36 if (
auto *SC = dyn_cast<SCEVConstant>(S)) {
37 SimplifiedValues[
I] =
SC->getValue();
46 auto *AR = dyn_cast<SCEVAddRecExpr>(S);
47 if (!AR || AR->getLoop() != L)
50 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
52 if (
auto *SC = dyn_cast<SCEVConstant>(ValueAtIteration)) {
53 SimplifiedValues[
I] =
SC->getValue();
62 dyn_cast<SCEVConstant>(SE.
getMinusSCEV(ValueAtIteration, Base));
66 Address.Base = Base->getValue();
79 if (!isa<Constant>(LHS))
80 if (
Value *SimpleLHS = SimplifiedValues.lookup(LHS))
82 if (!isa<Constant>(RHS))
83 if (
Value *SimpleRHS = SimplifiedValues.lookup(RHS))
86 Value *SimpleV =
nullptr;
88 if (
auto FI = dyn_cast<FPMathOperator>(&
I))
95 SimplifiedValues[&
I] = SimpleV;
102bool UnrolledInstAnalyzer::visitLoad(
LoadInst &
I) {
103 Value *AddrOp =
I.getPointerOperand();
105 auto AddressIt = SimplifiedAddresses.find(AddrOp);
106 if (AddressIt == SimplifiedAddresses.end())
108 ConstantInt *SimplifiedAddrOp = AddressIt->second.Offset;
110 auto *GV = dyn_cast<GlobalVariable>(AddressIt->second.Base);
113 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
117 dyn_cast<ConstantDataSequential>(GV->getInitializer());
130 int64_t SimplifiedAddrOpV = SimplifiedAddrOp->
getSExtValue();
131 if (SimplifiedAddrOpV < 0) {
144 assert(CV &&
"Constant expected.");
145 SimplifiedValues[&
I] = CV;
151bool UnrolledInstAnalyzer::visitCastInst(
CastInst &
I) {
153 if (
Value *Simplified = SimplifiedValues.lookup(
Op))
162 SimplifiedValues[&
I] =
V;
171bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &
I) {
175 if (!isa<Constant>(LHS))
176 if (
Value *SimpleLHS = SimplifiedValues.lookup(LHS))
178 if (!isa<Constant>(RHS))
179 if (
Value *SimpleRHS = SimplifiedValues.lookup(RHS))
182 if (!isa<Constant>(LHS) && !isa<Constant>(RHS)) {
183 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
184 if (SimplifiedLHS != SimplifiedAddresses.end()) {
185 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
186 if (SimplifiedRHS != SimplifiedAddresses.end()) {
187 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
188 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
189 if (LHSAddr.Base == RHSAddr.Base) {
190 LHS = LHSAddr.Offset;
191 RHS = RHSAddr.Offset;
199 SimplifiedValues[&
I] =
V;
206bool UnrolledInstAnalyzer::visitPHINode(
PHINode &PN) {
216bool UnrolledInstAnalyzer::visitInstruction(
Instruction &
I) {
217 return simplifyInstWithSCEV(&
I);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getActiveBits() const
Compute the number of active bits in the value.
This is the base class for all instructions that perform data casts.
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
This class is the base class for the comparison instructions.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
unsigned getNumElements() const
Return the number of elements in the array or vector.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Type * getElementType() const
Return the element type of the array/vector.
This is the shared class of boolean and integer constants.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
bool visitCmpInst(CmpInst &I)
bool visitPHINode(PHINode &I)
bool visitBinaryOperator(BinaryOperator &I)
bool visitCastInst(CastInst &I)
An instruction for reading from memory.
BlockT * getHeader() const
This class represents an analyzed expression in the program.
bool isZero() const
Return true if the expression is a constant zero.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
const SCEV * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
const ParentTy * getParent() const
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
This is an optimization pass for GlobalISel generic memory operations.
Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
Value * simplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.