Index: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp +++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp @@ -534,7 +534,7 @@ if (NewBB == DBB && !MSSA->isLiveOnEntryDef(D)) if (auto *UD = dyn_cast(D)) - if (firstInBB(NewPt, UD->getMemoryInst())) + if (!firstInBB(UD->getMemoryInst(), NewPt)) // Cannot move the load or store to NewPt above its definition in D. return false; Index: llvm/trunk/test/Transforms/GVNHoist/pr36787.ll =================================================================== --- llvm/trunk/test/Transforms/GVNHoist/pr36787.ll +++ llvm/trunk/test/Transforms/GVNHoist/pr36787.ll @@ -0,0 +1,76 @@ +; RUN: opt < %s -gvn-hoist -S | FileCheck %s + +@g = external constant i8* + +declare i32 @gxx_personality(...) +declare void @f0() +declare void @f1() +declare void @f2() + +; Make sure opt won't crash and that the load +; is not hoisted from label6 to label4 + +;CHECK-LABEL: @func + +define void @func() personality i8* bitcast (i32 (...)* @gxx_personality to i8*) { + invoke void @f0() + to label %3 unwind label %1 + +;