Index: lib/Transforms/Scalar/GVNHoist.cpp =================================================================== --- lib/Transforms/Scalar/GVNHoist.cpp +++ 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: test/Transforms/GVNHoist/pr36787.ll =================================================================== --- /dev/null +++ test/Transforms/GVNHoist/pr36787.ll @@ -0,0 +1,76 @@ +; RUN: opt < %s -gvn-hoist -S | FileCheck %s + +@g = external dso_local constant i8* + +declare i32 @gxx_personality(...) +declare dso_local void @f0() +declare dso_local void @f1() +declare dso_local void @f2() + +; Make sure opt won't crash and that the load +; is not hoisted from label6 to label4 + +;CHECK-LABEL: @func + +define dso_local void @func() personality i8* bitcast (i32 (...)* @gxx_personality to i8*) { + invoke void @f0() + to label %3 unwind label %1 + +;