[llvm] [VPlan] Model first memory runtime checks as VPlan recipes. (PR #221483)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 15:47:52 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;
}
----------------
artagnon wrote:
I just had an idea to avoid this -- is it possible to re-use SCEVExpander::isHighCostExpansionHelper? Seems unnecessary to generate IR to just cost something, right?
https://github.com/llvm/llvm-project/pull/221483
More information about the llvm-commits
mailing list