[llvm] [VPlan] Model first memory runtime checks as VPlan recipes. (PR #221483)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 02:53:05 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:
> The IR block built by GeneratedRTChecks::create() is still needed to cost the checks and to detect that they folded to a constant.
Hm, this is a bit unfortunate -- we create the IR for runtime checks and then erase them later if it's possible to do it in VPlan, generate them in VPlan, and re-lower them to IR in execution? Seems very roundabout, and it's one of the reasons I stayed away from this problem for the moment? Not sure what the best way to make forward-progress is, but maybe replace non-diff RT checks with VPlan wholesale (with costing), and avoid this dance?
https://github.com/llvm/llvm-project/pull/221483
More information about the llvm-commits
mailing list