[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 11:27:23 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a8c9cd1d96e: Fix PR45442: Bail out when MemorySSA information is not available (authored by hiraditya).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85881/new/

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
===================================================================
--- llvm/test/Transforms/GVNHoist/pr45442.ll
+++ llvm/test/Transforms/GVNHoist/pr45442.ll
@@ -1,32 +1,32 @@
 ; RUN: opt < %s -gvn-hoist -S | FileCheck %s
 
 ; gvn-hoist shouldn't crash in this case.
-; CHECK-LABEL: @func()
+; CHECK-LABEL: @func(i1 %b)
 ; CHECK:       entry:
 ; CHECK-NEXT:  br i1
 ; CHECK:  bb1:
-; CHECK-NEXT:  unreachable
+; CHECK-NEXT:  ret void
 ; CHECK:  bb2:
 ; CHECK-NEXT:  call
 ; CHECK-NEXT:  call
-; CHECK-NEXT:  unreachable
+; CHECK-NEXT:  ret void
 
 define void @v_1_0() #0 {
 entry:
   ret void
 }
 
-define void @func()  {
+define void @func(i1 %b) {
 entry:
-  br i1 undef, label %bb1, label %bb2
+  br i1 %b, label %bb1, label %bb2
 
 bb1:
-  unreachable
+  ret void
 
 bb2:
   call void @v_1_0()
   call void @v_1_0()
-  unreachable
+  ret void
 }
 
 attributes #0 = { nounwind readonly }
Index: llvm/lib/Transforms/Scalar/GVNHoist.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -521,10 +521,6 @@
     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();
@@ -609,9 +605,10 @@
         if (safeToHoistScalar(BB, Insn->getParent(), NumBBsOnAllPaths))
           Safe.push_back(CHI);
       } else {
-        MemoryUseOrDef *UD = MSSA->getMemoryAccess(Insn);
-        if (safeToHoistLdSt(BB->getTerminator(), Insn, UD, K, NumBBsOnAllPaths))
-          Safe.push_back(CHI);
+        auto *T = BB->getTerminator();
+        if (MemoryUseOrDef *UD = MSSA->getMemoryAccess(Insn))
+          if (safeToHoistLdSt(T, Insn, UD, K, NumBBsOnAllPaths))
+            Safe.push_back(CHI);
       }
     }
   }


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


More information about the llvm-commits mailing list