32bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
37 if (
auto *SC = dyn_cast<SCEVConstant>(S)) {
38 SimplifiedValues[
I] =
SC->getValue();
47 auto *AR = dyn_cast<SCEVAddRecExpr>(S);
48 if (!AR || AR->getLoop() != L)
51 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
53 if (
auto *SC = dyn_cast<SCEVConstant>(ValueAtIteration)) {
54 SimplifiedValues[
I] =
SC->getValue();
62 std::optional<APInt>
Offset =
67 Address.Base = Base->getValue();
80 if (!isa<Constant>(LHS))
81 if (
Value *SimpleLHS = SimplifiedValues.lookup(LHS))
83 if (!isa<Constant>(RHS))
84 if (
Value *SimpleRHS = SimplifiedValues.lookup(RHS))
87 Value *SimpleV =
nullptr;
89 if (
auto FI = dyn_cast<FPMathOperator>(&
I))
96 SimplifiedValues[&
I] = SimpleV;
103bool UnrolledInstAnalyzer::visitLoad(
LoadInst &
I) {
104 Value *AddrOp =
I.getPointerOperand();
106 auto AddressIt = SimplifiedAddresses.find(AddrOp);
107 if (AddressIt == SimplifiedAddresses.end())
110 auto *GV = dyn_cast<GlobalVariable>(AddressIt->second.Base);
113 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
118 AddressIt->second.Offset,
I.getDataLayout());
122 SimplifiedValues[&
I] = Res;
127bool UnrolledInstAnalyzer::visitCastInst(
CastInst &
I) {
129 if (
Value *Simplified = SimplifiedValues.lookup(
Op))
138 SimplifiedValues[&
I] =
V;
147bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &
I) {
151 if (!isa<Constant>(LHS))
152 if (
Value *SimpleLHS = SimplifiedValues.lookup(LHS))
154 if (!isa<Constant>(RHS))
155 if (
Value *SimpleRHS = SimplifiedValues.lookup(RHS))
158 if (!isa<Constant>(LHS) && !isa<Constant>(RHS) && !
I.isSigned()) {
159 auto SimplifiedLHS = SimplifiedAddresses.find(LHS);
160 if (SimplifiedLHS != SimplifiedAddresses.end()) {
161 auto SimplifiedRHS = SimplifiedAddresses.find(RHS);
162 if (SimplifiedRHS != SimplifiedAddresses.end()) {
163 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
164 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
165 if (LHSAddr.Base == RHSAddr.Base) {
182 SimplifiedValues[&
I] =
V;
189bool UnrolledInstAnalyzer::visitPHINode(
PHINode &PN) {
199bool UnrolledInstAnalyzer::visitInstruction(
Instruction &
I) {
200 return simplifyInstWithSCEV(&
I);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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.
static ConstantInt * getBool(LLVMContext &Context, bool V)
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.
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
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 * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
std::optional< APInt > computeConstantDifference(const SCEV *LHS, const SCEV *RHS)
Compute LHS - RHS and returns the result as an APInt if it is a constant, and std::nullopt if it isn'...
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.
Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
Value * simplifyCmpInst(CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.