[PATCH] D159354: [SROA] Limit the number of allowed slices when trying to split allocas
Dhruv Chawla via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 1 05:55:37 PDT 2023
0xdc03 created this revision.
0xdc03 added a reviewer: nikic.
Herald added subscribers: StephenFan, JDevlieghere, hiraditya.
Herald added a project: All.
0xdc03 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch adds a hidden CLI option "--sroa-max-alloca-slices", which is
an integer that controls the maximum number of alloca slices SROA can
consider before bailing out. This prevents an issue with exponential compile
time explosion in passes like DSE and MemCpyOpt.
The default value has been chosen to prevent test breakages in the SROA
test suite while being low enough to prevent the unwanted behaviour.
Fixes https://github.com/rust-lang/rust/issues/88580.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159354
Files:
llvm/lib/Transforms/Scalar/SROA.cpp
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -121,6 +121,14 @@
/// Disable running mem2reg during SROA in order to test or debug SROA.
static cl::opt<bool> SROASkipMem2Reg("sroa-skip-mem2reg", cl::init(false),
cl::Hidden);
+
+/// The maximum number of alloca slices allowed when splitting.
+static cl::opt<int>
+ SROAMaxAllocaSlices("sroa-max-alloca-slices", cl::init(32),
+ cl::desc("Maximum number of alloca slices allowed "
+ "after which splitting is not attempted"),
+ cl::Hidden);
+
namespace {
/// Calculate the fragment of a variable to use when slicing a store
@@ -4961,6 +4969,9 @@
if (AS.isEscaped())
return {Changed, CFGChanged};
+ if (std::distance(AS.begin(), AS.end()) > SROAMaxAllocaSlices)
+ return {Changed, CFGChanged};
+
// Delete all the dead users of this alloca before splitting and rewriting it.
for (Instruction *DeadUser : AS.getDeadUsers()) {
// Free up everything used by this instruction.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159354.555346.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230901/99874992/attachment.bin>
More information about the llvm-commits
mailing list