[llvm] [VPlan] Make canonical IV part of the region (PR #156262)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 21 05:27:14 PDT 2026


================
@@ -4521,23 +4491,34 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
   /// its entry, and its exiting block to its successor.
   void dissolveToCFGLoop();
 
-  /// Returns the canonical induction recipe of the region.
-  VPCanonicalIVPHIRecipe *getCanonicalIV() {
-    VPBasicBlock *EntryVPBB = getEntryBasicBlock();
-    if (EntryVPBB->empty()) {
-      // VPlan native path. TODO: Unify both code paths.
-      EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
-    }
-    return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
+  /// Get the canonical IV increment instruction. If the exiting terminator
+  /// is a BranchOnCount or BranchOnCond with an IV increment, return this
+  /// increment. Otherwise, create a new increment before the terminator and
+  /// return it. The canonical IV increment is subject to DCE if unused, unlike
+  /// the canonical IV itself.
+  VPInstruction *getOrCreateCanonicalIVIncrement();
+
+  /// Return the canonical induction variable of the region, null for
+  /// replicating regions.
+  VPRegionValue *getCanonicalIV() {
+    return CanIVInfo ? CanIVInfo->getRegionValue() : nullptr;
   }
-  const VPCanonicalIVPHIRecipe *getCanonicalIV() const {
-    return const_cast<VPRegionBlock *>(this)->getCanonicalIV();
+  const VPRegionValue *getCanonicalIV() const {
+    return CanIVInfo ? CanIVInfo->getRegionValue() : nullptr;
   }
 
   /// Return the type of the canonical IV for loop regions.
-  Type *getCanonicalIVType() { return getCanonicalIV()->getScalarType(); }
-  const Type *getCanonicalIVType() const {
-    return getCanonicalIV()->getScalarType();
+  Type *getCanonicalIVType() const {
+    return CanIVInfo->getRegionValue()->getType();
+  }
+
+  /// Indicates if NUW is set for the canonical IV increment, for loop regions.
+  bool hasCanonicalIVNUW() const { return CanIVInfo->hasNUW(); }
----------------
fhahn wrote:

Yep, added to findCanonicalIVIncrement, thanks

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


More information about the llvm-commits mailing list