[llvm] [IVDescriptors] Implement MonotonicDescriptor (PR #214490)
Gaƫtan Bossu via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 02:50:07 PDT 2026
================
@@ -1696,3 +1696,125 @@ bool InductionDescriptor::isInductionPHI(
/*InductionBinOp=*/nullptr, /*Casts=*/nullptr, Preds);
return true;
}
+
+bool MonotonicDescriptor::setSCEV(const SCEV *NewExpr) {
+ auto *AddRec = dyn_cast<SCEVAddRecExpr>(NewExpr);
+ if (!AddRec || !AddRec->isAffine())
+ return false;
+ Expr = AddRec;
+ return true;
+}
+
+// Recognize monotonic phi variable by matching the following pattern:
+// loop_header:
+// %monotonic_phi = [%start, %preheader], [%chain_phi0, %latch]
+//
+// step_bb:
+// %step = add/gep %monotonic_phi, %step_val
+//
+// bbN:
+// %chain_phiN = [%monotonic_phi, ], [%step, ]
+//
+// ...
+//
+// bb1:
+// %chain_phi1 = [%monotonic_phi, ], [%chain_phi2, ]
+//
+// latch:
+// %chain_phi0 = [%monotonic_phi, %pred], [%chain_phi1, %pred]
----------------
gbossu wrote:
Drive-by: I find it quite hard to read this example because it does not explain the control flow. Could you add some branch instructions and/or predecessor comments? (Same in the PR description)
https://github.com/llvm/llvm-project/pull/214490
More information about the llvm-commits
mailing list