]> granicus.if.org Git - llvm/commitdiff
[NewGVN] Skip uses in unreachable blocks.
authorDavide Italiano <davide@freebsd.org>
Thu, 26 Jan 2017 00:42:42 +0000 (00:42 +0000)
committerDavide Italiano <davide@freebsd.org>
Thu, 26 Jan 2017 00:42:42 +0000 (00:42 +0000)
Otherwise we ask for a domtree node that's not there, and we crash.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293122 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/NewGVN.cpp
test/Transforms/NewGVN/pr31758.ll [new file with mode: 0644]

index fe5a43872f544b58b515889580452c65faa390a0..747c913278ff7de9b2faadb695e1c34e1124e96a 100644 (file)
@@ -1936,6 +1936,12 @@ void NewGVN::convertDenseToDFSOrdered(
           IBlock = I->getParent();
           VD.LocalNum = InstrDFS.lookup(I);
         }
+
+        // Skip uses in unreachable blocks, as we're going
+        // to delete them.
+        if (ReachableBlocks.count(IBlock) == 0)
+          continue;
+
         DomTreeNode *DomNode = DT->getNode(IBlock);
         VD.DFSIn = DomNode->getDFSNumIn();
         VD.DFSOut = DomNode->getDFSNumOut();
diff --git a/test/Transforms/NewGVN/pr31758.ll b/test/Transforms/NewGVN/pr31758.ll
new file mode 100644 (file)
index 0000000..ca33299
--- /dev/null
@@ -0,0 +1,37 @@
+; RUN: opt -newgvn %s -S -o - | FileCheck %s
+
+%struct.dipsy = type {}
+%struct.fluttershy = type { %struct.dipsy* }
+%struct.patatino = type {}
+
+define void @tinkywinky() {
+bb:
+  br label %bb90
+
+bb90:
+  %tmp = getelementptr inbounds %struct.fluttershy, %struct.fluttershy* undef, i64 0, i32 0
+  %tmp91 = bitcast %struct.dipsy** %tmp to %struct.patatino**
+  %tmp92 = load %struct.patatino*, %struct.patatino** %tmp91, align 8
+  %tmp99 = getelementptr inbounds %struct.patatino, %struct.patatino* %tmp92
+  %tmp134 = getelementptr inbounds %struct.fluttershy, %struct.fluttershy* undef, i64 0, i32 0
+  %tmp135 = bitcast %struct.dipsy** %tmp134 to %struct.patatino**
+  %tmp136 = load %struct.patatino*, %struct.patatino** %tmp135, align 8
+  br label %bb90
+
+bb138:
+  %tmp139 = getelementptr inbounds %struct.patatino, %struct.patatino* %tmp136
+  br label %bb138
+}
+
+; CHECK-LABEL: tinkywinky
+; CHECK-NEXT: bb:
+; CHECK-NEXT:   br label %bb90
+; CHECK-NEXT
+; CHECK:  bb90:
+; CHECK:  %tmp91 = bitcast %struct.dipsy** undef to %struct.patatino**
+; CHECK-NEXT:  %tmp92 = load %struct.patatino*, %struct.patatino** %tmp91, align 8
+; CHECK-NEXT:  %tmp136 = load %struct.patatino*, %struct.patatino** %tmp91, align 8
+; CHECK-NEXT:  br label %bb90
+; CHECK:  bb138:
+; CHECK-NEXT:  br label %bb138
+; CHECK-NEXT: }