[llvm] [IVDescriptors] Implement MonotonicDescriptor (PR #214490)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 10:58:23 PDT 2026
================
@@ -482,6 +483,76 @@ class InductionDescriptor {
SmallVector<const SCEVPredicate *, 2> NoWrapPredicates;
};
+/// A struct for saving information about monotonic variables.
+/// Monotonic variable can be considered as a "conditional" induction variable:
+/// its update happens only on loop iterations for which a certain predicate is
+/// satisfied.
+class MonotonicDescriptor {
+public:
+ MonotonicDescriptor() = default;
+
+ MonotonicDescriptor(const SmallPtrSetImpl<PHINode *> &Chain,
+ const DenseMap<Value *, const SCEV *> &CompressedPtrs,
+ Instruction *StepInst, const SCEVAddRecExpr *Expr)
+ : Chain(llvm::from_range, Chain), CompressedPtrs(CompressedPtrs),
+ StepInst(StepInst), Expr(Expr) {}
+
+ /// Returns the PHIs that feed into the backedge of the monotonic PHI.
+ const SmallPtrSetImpl<PHINode *> &getChain() const { return Chain; }
+
+ // Returns pointers (used by load/store operations) where the address is
+ // derived from this monotonic PHI. The keys are pointers, the values are
+ // SCEVAddRecs that represent how the pointer is updated by StepInst.
+ const DenseMap<Value *, const SCEV *> &getCompressedPtrs() const {
+ return CompressedPtrs;
+ }
+
+ /// Returns the instruction that updates the value of the monotonic PHI.
+ Instruction *getStepInst() const { return StepInst; }
----------------
MacDue wrote:
It's not that dissimilar to other transforms. I still think it's the best approach for now. Otherwise, we have to add a fairly complex check to the IVDescriptors (and likely plumb through a post-dominator tree too).
https://github.com/llvm/llvm-project/pull/214490
More information about the llvm-commits
mailing list