[llvm] [IVDescriptors] Implement MonotonicDescriptor (PR #214490)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 10:05:48 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 {
----------------
eas wrote:

```suggestion
  const DenseMap<Value *, const SCEV *> &getCompressedPtrSCEVs() const {
```

nit, feel free to ignore.

https://github.com/llvm/llvm-project/pull/214490


More information about the llvm-commits mailing list