27 bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
32 if (
auto *
SC = dyn_cast<SCEVConstant>(S)) {
33 SimplifiedValues[
I] =
SC->getValue();
38 if (!AR || AR->getLoop() != L)
41 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
43 if (
auto *
SC = dyn_cast<SCEVConstant>(ValueAtIteration)) {
44 SimplifiedValues[
I] =
SC->getValue();
57 Address.Base =
Base->getValue();
58 Address.Offset =
Offset->getValue();
68 bool UnrolledInstAnalyzer::visitBinaryOperator(
BinaryOperator &I) {
70 if (!isa<Constant>(LHS))
71 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
73 if (!isa<Constant>(RHS))
74 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
77 Value *SimpleV =
nullptr;
79 if (
auto FI = dyn_cast<FPMathOperator>(&I))
85 if (
Constant *
C = dyn_cast_or_null<Constant>(SimpleV))
86 SimplifiedValues[&I] =
C;
94 bool UnrolledInstAnalyzer::visitLoad(
LoadInst &I) {
97 auto AddressIt = SimplifiedAddresses.find(AddrOp);
98 if (AddressIt == SimplifiedAddresses.end())
100 ConstantInt *SimplifiedAddrOp = AddressIt->second.Offset;
105 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
122 int64_t SimplifiedAddrOpV = SimplifiedAddrOp->
getSExtValue();
123 if (SimplifiedAddrOpV < 0) {
128 uint64_t
Index =
static_cast<uint64_t
>(SimplifiedAddrOpV) / ElemSize;
136 assert(CV &&
"Constant expected.");
137 SimplifiedValues[&
I] = CV;
143 bool UnrolledInstAnalyzer::visitCastInst(
CastInst &I) {
147 COp = SimplifiedValues.lookup(I.
getOperand(0));
157 SimplifiedValues[&
I] =
C;
166 bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &I) {
170 if (!isa<Constant>(LHS))
171 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
173 if (!isa<Constant>(RHS))
174 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
177 if (!isa<Constant>(LHS) && !isa<Constant>(RHS)) {
178 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
179 if (SimplifiedLHS != SimplifiedAddresses.end()) {
180 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
181 if (SimplifiedRHS != SimplifiedAddresses.end()) {
182 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
183 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
184 if (LHSAddr.Base == RHSAddr.Base) {
185 LHS = LHSAddr.Offset;
186 RHS = RHSAddr.Offset;
192 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
193 if (
Constant *CRHS = dyn_cast<Constant>(RHS)) {
194 if (CLHS->getType() == CRHS->getType()) {
196 SimplifiedValues[&
I] =
C;
206 bool UnrolledInstAnalyzer::visitPHINode(
PHINode &PN) {
A parsed version of the target data layout string in and methods for querying it. ...
This class is the base class for the comparison instructions.
This class represents lattice values for constants.
BinaryOps getOpcode() const
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
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...
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.
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...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
BlockT * getHeader() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
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...
const APInt & getValue() const
Return the constant as an APInt value reference.
Type * getElementType() const
Return the element type of the array/vector.
Value * getOperand(unsigned i) const
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
This is an important base class in LLVM.
Value * getPointerOperand()
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
bool visitBinaryOperator(BinaryOperator &I)
This is the shared class of boolean and integer constants.
CHAIN = SC CHAIN, Imm128 - System call.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Predicate getPredicate() const
Return the predicate for this instruction.
This class represents an analyzed expression in the program.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
unsigned getNumElements() const
Return the number of elements in the array or vector.
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.