[llvm] [VPlan] Model first memory runtime checks as VPlan recipes. (PR #221483)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 02:56:25 PDT 2026


================
@@ -1809,8 +1799,33 @@ class GeneratedRTChecks {
   }
 
   /// Return true if any runtime checks have been added
-  bool hasChecks() const {
-    return getSCEVChecks().first || getMemRuntimeChecks().first;
+  bool hasChecks() const { return getSCEVChecks().first || HasMemChecks; }
+
+  /// Drop the pre-built memory check block in favour of VPlan recipes.
+  /// TODO: Remove once the checks can be costed in VPlan, before VF selection.
+  void dropMemRuntimeChecks() {
+    assert(MemCheckBlock && pred_empty(MemCheckBlock) &&
+           "cannot drop memory checks that are missing or already connected");
+    eraseMemCheckBlock();
+  }
+
+private:
+  /// Erase the memory check block, its instructions and their SCEV expansions.
+  void eraseMemCheckBlock() {
+    SCEVExpanderCleaner MemCheckCleaner(MemCheckExp);
+    auto &SE = *MemCheckExp.getSE();
+    // Memory runtime check generation creates compares that use expanded
+    // values. Remove them before running the SCEVExpanderCleaner.
+    for (auto &I : make_early_inc_range(reverse(*MemCheckBlock))) {
+      if (MemCheckExp.isInsertedInstruction(&I))
+        continue;
+      SE.forgetValue(&I);
+      I.eraseFromParent();
+    }
+    MemCheckCleaner.cleanup();
+    MemCheckBlock->eraseFromParent();
+    MemCheckBlock = nullptr;
+    MemRuntimeCheckCond = nullptr;
   }
----------------
fhahn wrote:

Agreed that we should use the cost based on VPlan. Although this requires more changes and potentially also changes cost decisions (because we now have potentially better CSE), which is why I would prefer to do this separately.

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


More information about the llvm-commits mailing list