[llvm] 4471685 - Fix PR45442: Bail out when MemorySSA information is not available

Aditya Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 09:32:24 PDT 2020


Author: Aditya Kumar
Date: 2020-08-13T09:31:18-07:00
New Revision: 44716856db599f8988affa16875a6b120189e013

URL: https://github.com/llvm/llvm-project/commit/44716856db599f8988affa16875a6b120189e013
DIFF: https://github.com/llvm/llvm-project/commit/44716856db599f8988affa16875a6b120189e013.diff

LOG: Fix PR45442: Bail out when MemorySSA information is not available

Added: 
    llvm/test/Transforms/GVNHoist/pr45442.ll

Modified: 
    llvm/lib/Transforms/Scalar/GVNHoist.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 9c4cdf2feb56..07f40de6a1f2 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -521,6 +521,10 @@ class GVNHoist {
     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();

diff  --git a/llvm/test/Transforms/GVNHoist/pr45442.ll b/llvm/test/Transforms/GVNHoist/pr45442.ll
new file mode 100644
index 000000000000..db3ecb2a8d87
--- /dev/null
+++ b/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:  bb1:
+; CHECK-NEXT:  unreachable
+; CHECK:  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 }


        


More information about the llvm-commits mailing list