[llvm] [VPlan] Model first memory runtime checks as VPlan recipes. (PR #221483)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 06:50:27 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:
I don't think `SCEVExpander::isHighCostExpansionHelper` is accurate enough for the use case here, as we need to expand multiple expressions (where there may be re-use across expressions) and also generate compares and other logical instruction.
And getting the cost here as accurate as possible is quite important, because it impacts the minimum iteration threshold.
https://github.com/llvm/llvm-project/pull/221483
More information about the llvm-commits
mailing list