[llvm] 8814623 - SeparateConstOffsetFromGEP: Fix stack overflow in unreachable code
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 14 17:03:33 PDT 2021
Author: Matt Arsenault
Date: 2021-09-14T19:49:38-04:00
New Revision: 88146230e1b21aa042da481e5fd702fab82408fc
URL: https://github.com/llvm/llvm-project/commit/88146230e1b21aa042da481e5fd702fab82408fc
DIFF: https://github.com/llvm/llvm-project/commit/88146230e1b21aa042da481e5fd702fab82408fc.diff
LOG: SeparateConstOffsetFromGEP: Fix stack overflow in unreachable code
ConstantOffsetExtractor::Find was infinitely recursing on the add
referencing itself.
Added:
llvm/test/Transforms/SeparateConstOffsetFromGEP/crash-in-unreachable-code.ll
Modified:
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index e8c965c543df6..fe221326b652f 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -1164,6 +1164,9 @@ bool SeparateConstOffsetFromGEP::run(Function &F) {
DL = &F.getParent()->getDataLayout();
bool Changed = false;
for (BasicBlock &B : F) {
+ if (!DT->isReachableFromEntry(&B))
+ continue;
+
for (BasicBlock::iterator I = B.begin(), IE = B.end(); I != IE;)
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I++))
Changed |= splitGEP(GEP);
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/crash-in-unreachable-code.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/crash-in-unreachable-code.ll
new file mode 100644
index 0000000000000..b61c9bb229206
--- /dev/null
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/crash-in-unreachable-code.ll
@@ -0,0 +1,14 @@
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -separate-const-offset-from-gep %s
+
+ at gv = external local_unnamed_addr addrspace(3) global [16 x i8], align 16
+
+; The add referencing itself is illegal, except it's in an unreachable block.
+define weak amdgpu_kernel void @foo() {
+entry:
+ ret void
+
+for.body28.i: ; preds = %for.body28.i
+ %arrayidx3389.i = getelementptr inbounds [16 x i8], [16 x i8] addrspace(3)* @gv, i32 0, i32 %inc38.7.i.1
+ %inc38.7.i.1 = add nuw nsw i32 %inc38.7.i.1, 16
+ br label %for.body28.i
+}
More information about the llvm-commits
mailing list