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

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

Thinking more about this, maybe I was wrong about Dom/PostDom. Nothing in the IR guarantees this instruction can't be hoisted out of the conditional block. Sorry for confusion.

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


More information about the llvm-commits mailing list