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(); 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: 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 }