28 bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
33 if (
auto *
SC = dyn_cast<SCEVConstant>(S)) {
34 SimplifiedValues[
I] =
SC->getValue();
39 if (!AR || AR->getLoop() != L)
42 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
44 if (
auto *
SC = dyn_cast<SCEVConstant>(ValueAtIteration)) {
45 SimplifiedValues[
I] =
SC->getValue();
58 Address.Base =
Base->getValue();
59 Address.Offset =
Offset->getValue();
69 bool UnrolledInstAnalyzer::visitBinaryOperator(
BinaryOperator &I) {
71 if (!isa<Constant>(LHS))
72 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
74 if (!isa<Constant>(RHS))
75 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
78 Value *SimpleV =
nullptr;
80 if (
auto FI = dyn_cast<FPMathOperator>(&I))
86 if (
Constant *
C = dyn_cast_or_null<Constant>(SimpleV))
87 SimplifiedValues[&I] =
C;
95 bool UnrolledInstAnalyzer::visitLoad(
LoadInst &I) {
98 auto AddressIt = SimplifiedAddresses.find(AddrOp);
99 if (AddressIt == SimplifiedAddresses.end())
101 ConstantInt *SimplifiedAddrOp = AddressIt->second.Offset;
106 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
123 int64_t SimplifiedAddrOpV = SimplifiedAddrOp->
getSExtValue();
124 if (SimplifiedAddrOpV < 0) {
129 uint64_t
Index =
static_cast<uint64_t
>(SimplifiedAddrOpV) / ElemSize;
137 assert(CV &&
"Constant expected.");
138 SimplifiedValues[&
I] = CV;
144 bool UnrolledInstAnalyzer::visitCastInst(
CastInst &I) {
148 COp = SimplifiedValues.lookup(I.
getOperand(0));
158 SimplifiedValues[&
I] =
C;
167 bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &I) {
171 if (!isa<Constant>(LHS))
172 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
174 if (!isa<Constant>(RHS))
175 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
178 if (!isa<Constant>(LHS) && !isa<Constant>(RHS)) {
179 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
180 if (SimplifiedLHS != SimplifiedAddresses.end()) {
181 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
182 if (SimplifiedRHS != SimplifiedAddresses.end()) {
183 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
184 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
185 if (LHSAddr.Base == RHSAddr.Base) {
186 LHS = LHSAddr.Offset;
187 RHS = RHSAddr.Offset;
193 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
194 if (
Constant *CRHS = dyn_cast<Constant>(RHS)) {
195 if (CLHS->getType() == CRHS->getType()) {
197 SimplifiedValues[&
I] =
C;
207 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.
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FP BinaryOperator, fold the result or return null.
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...
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())
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.
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.