CGP: Clear data structures at the end of a loop iteration instead of the beginning.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 23 Oct 2018 21:23:18 +0000 (21:23 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 23 Oct 2018 21:23:18 +0000 (21:23 +0000)
Clearing LargeOffsetGEPMap at the end fixes a bug where if a large
offset GEP is in a dead basic block, we fail an assertion when trying
to delete the block due to the asserting VH in LargeOffsetGEPMap.

Differential Revision: https://reviews.llvm.org/D53464

llvm-svn: 345082

llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/CodeGen/Thumb2/unreachable-large-offset-gep.ll [new file with mode: 0644]

index fa5cc4d..6e73f7d 100644 (file)
@@ -436,11 +436,6 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
   bool MadeChange = true;
   while (MadeChange) {
     MadeChange = false;
-    SeenChainsForSExt.clear();
-    ValToSExtendedUses.clear();
-    RemovedInsts.clear();
-    LargeOffsetGEPMap.clear();
-    LargeOffsetGEPID.clear();
     for (Function::iterator I = F.begin(); I != F.end(); ) {
       BasicBlock *BB = &*I++;
       bool ModifiedDTOnIteration = false;
@@ -460,6 +455,11 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
       I->deleteValue();
 
     EverMadeChange |= MadeChange;
+    SeenChainsForSExt.clear();
+    ValToSExtendedUses.clear();
+    RemovedInsts.clear();
+    LargeOffsetGEPMap.clear();
+    LargeOffsetGEPID.clear();
   }
 
   SunkAddrs.clear();
diff --git a/llvm/test/CodeGen/Thumb2/unreachable-large-offset-gep.ll b/llvm/test/CodeGen/Thumb2/unreachable-large-offset-gep.ll
new file mode 100644 (file)
index 0000000..641787b
--- /dev/null
@@ -0,0 +1,22 @@
+; RUN: llc -o - %s | FileCheck %s
+
+; CHECK: .LBB0_1:
+; CHECK: b .LBB0_1
+
+target triple = "thumbv8m-unknown-linux-android"
+
+define void @d(i32* %c) {
+entry:
+  br i1 false, label %f.exit, label %i.d
+
+i.d:
+  br label %i.d
+
+f.exit:
+  %0 = getelementptr i32, i32* %c, i32 57
+  br label %if.g
+
+if.g:
+  store i32 0, i32* %0
+  ret void
+}