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 @@ private: 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 }