[PATCH] D85881: Fix PR45442: Bail out when MemorySSA information is not available

Aditya Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 00:08:08 PDT 2020


hiraditya created this revision.
hiraditya added reviewers: sebpop, uabelho.
Herald added subscribers: llvm-commits, Prazek.
Herald added a project: LLVM.
hiraditya requested review of this revision.

https://reviews.llvm.org/D85881

Files:
  llvm/lib/Transforms/Scalar/GVNHoist.cpp
  llvm/test/Transforms/GVNHoist/pr45442.ll


Index: llvm/test/Transforms/GVNHoist/pr45442.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVNHoist/pr45442.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -gvn-hoist -S | FileCheck %s
+
+; gvn-hoist shouldn't crash in this case.
+; CHECK-LABEL: @func()
+; CHECK:       entry:
+; CHECK-NEXT:  br i1
+; CHECK-NEXT:  bb1
+; CHECK-NEXT:  unreachable
+; CHECK-NEXT:  bb2:
+; CHECK-NEXT:  call
+; CHECK-NEXT:  call
+; CHECK-NEXT:  unreachable
+
+define void @v_1_0() #0 {
+entry:
+  ret void
+}
+
+define void @func()  {
+entry:
+  br i1 undef, label %bb1, label %bb2
+
+bb1:
+  unreachable
+
+bb2:
+  call void @v_1_0()
+  call void @v_1_0()
+  unreachable
+}
+
+attributes #0 = { nounwind readonly }
Index: llvm/lib/Transforms/Scalar/GVNHoist.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -521,6 +521,10 @@
     if (NewPt == OldPt)
       return true;
 
+    // MemoryUseDef information is not available, bail out.
+    if (!U)
+      return false;
+
     const BasicBlock *NewBB = NewPt->getParent();
     const BasicBlock *OldBB = OldPt->getParent();
     const BasicBlock *UBB = U->getBlock();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85881.285268.patch
Type: text/x-patch
Size: 1264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200813/a3693e9e/attachment.bin>


More information about the llvm-commits mailing list