diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/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 SROASkipMem2Reg("sroa-skip-mem2reg", cl::init(false), cl::Hidden); + +/// The maximum number of alloca slices allowed when splitting. +static cl::opt + 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.