33bool UnrolledInstAnalyzer::simplifyInstWithSCEV(
Instruction *
I) {
34 if (!SE.isSCEVable(
I->getType()))
37 const SCEV *S = SE.getSCEV(
I);
39 SimplifiedValues[
I] = SC->getValue();
45 if (!IterationNumber->isZero() && SE.isLoopInvariant(S, L))
49 if (!AR || AR->getLoop() != L)
52 const SCEV *ValueAtIteration = AR->evaluateAtIteration(IterationNumber, SE);
55 SimplifiedValues[
I] = SC->getValue();
63 std::optional<APInt>
Offset =
64 SE.computeConstantDifference(ValueAtIteration, Base);
68 Address.Base = Base->getValue();
70 SimplifiedAddresses[
I] = std::move(
Address);
82 if (
Value *SimpleLHS = SimplifiedValues.lookup(
LHS))
85 if (
Value *SimpleRHS = SimplifiedValues.lookup(
RHS))
88 Value *SimpleV =
nullptr;
89 const DataLayout &
DL =
I.getDataLayout();
97 SimplifiedValues[&
I] = SimpleV;
104bool UnrolledInstAnalyzer::visitLoad(
LoadInst &
I) {
105 Value *AddrOp =
I.getPointerOperand();
107 auto AddressIt = SimplifiedAddresses.find(AddrOp);
108 if (AddressIt == SimplifiedAddresses.end())
114 if (!GV || !GV->hasDefinitiveInitializer() || !GV->isConstant())
119 AddressIt->second.Offset,
I.getDataLayout());
123 SimplifiedValues[&
I] = Res;
128bool UnrolledInstAnalyzer::visitCastInst(
CastInst &
I) {
130 if (
Value *Simplified = SimplifiedValues.lookup(
Op))
137 const DataLayout &
DL =
I.getDataLayout();
139 SimplifiedValues[&
I] =
V;
148bool UnrolledInstAnalyzer::visitCmpInst(
CmpInst &
I) {
153 if (
Value *SimpleLHS = SimplifiedValues.lookup(
LHS))
156 if (
Value *SimpleRHS = SimplifiedValues.lookup(
RHS))
160 auto SimplifiedLHS = SimplifiedAddresses.find(
LHS);
161 if (SimplifiedLHS != SimplifiedAddresses.end()) {
162 auto SimplifiedRHS = SimplifiedAddresses.find(
RHS);
163 if (SimplifiedRHS != SimplifiedAddresses.end()) {
164 SimplifiedAddress &LHSAddr = SimplifiedLHS->second;
165 SimplifiedAddress &RHSAddr = SimplifiedRHS->second;
166 if (LHSAddr.Base == RHSAddr.Base) {
181 const DataLayout &
DL =
I.getDataLayout();
183 SimplifiedValues[&
I] =
V;
190bool UnrolledInstAnalyzer::visitPHINode(
PHINode &PN) {
204bool UnrolledInstAnalyzer::isInvariantComputation(
Instruction *
I) {
207 if (
auto It = InvariantInsts.find(
I); It != InvariantInsts.end())
211 (
II &&
II->isAssumeLikeIntrinsic()) ||
I->mayReadOrWriteMemory() ||
212 I->mayHaveSideEffects()) {
213 InvariantInsts[
I] =
false;
217 auto *OpI = dyn_cast<Instruction>(Op);
218 return !OpI || isInvariantComputation(OpI);
220 InvariantInsts[
I] = Invariant;
224bool UnrolledInstAnalyzer::visitInstruction(
Instruction &
I) {
225 if (simplifyInstWithSCEV(&
I))
231 return !SE.isSCEVable(
I.getType()) && !IterationNumber->isZero() &&
232 isInvariantComputation(&
I);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t IntrinsicInst * II
This is the base class for all instructions that perform data casts.
static LLVM_ABI 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 LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
static LLVM_ABI 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.
const ParentTy * getParent() const
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldLoadFromConst(Constant *C, Type *Ty, const APInt &Offset, const DataLayout &DL)
Extract value of C at the given Offset reinterpreted as Ty.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
DWARFExpression::Operation Op
LLVM_ABI Value * simplifyCmpInst(CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.