@@ -36,7 +36,7 @@ index 235f0da86..13461ffd0 100644
3636 EVT VT = N->getValueType(0);
3737 if (VT != MVT::i16 && VT != MVT::i32 && VT != MVT::i64)
3838diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
39- index 983a75e1d..0e5cff400 100644
39+ index 983a75e1d..a280616ca 100644
4040--- a/llvm/lib/Transforms/Scalar/SROA.cpp
4141+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
4242@@ -121,6 +121,10 @@ static cl::opt<bool> SROAStrictInbounds("sroa-strict-inbounds", cl::init(false),
@@ -72,3 +72,29 @@ index 983a75e1d..0e5cff400 100644
7272 Type *Ty;
7373 if (auto *LI = dyn_cast<LoadInst>(S.getUse()->getUser()))
7474 Ty = LI->getType();
75+ @@ -4707,6 +4719,15 @@ AllocaInst *SROAPass::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
76+ return NewAI;
77+ }
78+
79+ + /// Return true if \p AS has any overlapping slices. \p AS must be sorted by
80+ + /// begin offset; overlap is detected by adjacent pairs.
81+ + static bool hasOverlappingSlices(AllocaSlices &AS) {
82+ + for (auto I = AS.begin(), E = AS.end(); I != E && std::next(I) != E; ++I)
83+ + if (I->endOffset() > std::next(I)->beginOffset())
84+ + return true;
85+ + return false;
86+ + }
87+ +
88+ /// Walks the slices of an alloca and form partitions based on them,
89+ /// rewriting each of their uses.
90+ bool SROAPass::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
91+ @@ -4776,6 +4797,9 @@ bool SROAPass::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
92+ if (!IsSorted)
93+ llvm::sort(AS);
94+
95+ + if (hasOverlappingSlices(AS))
96+ + return Changed;
97+ +
98+ /// Describes the allocas introduced by rewritePartition in order to migrate
99+ /// the debug info.
100+ struct Fragment {
0 commit comments