diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp index 6cf5408591523..4172fbc96d1e5 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -249,7 +249,8 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf, "WinEHPrepare failed to remove PHIs from imaginary BBs"); continue; } - if (isa(PadInst)) + if (isa(PadInst) && + Personality != EHPersonality::Wasm_CXX) assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs"); } diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index e82f14e878141..2ed39a5696e20 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -918,7 +918,7 @@ void TargetPassConfig::addPassesToHandleExceptions() { // on catchpads and cleanuppads because it does not outline them into // funclets. Catchswitch blocks are not lowered in SelectionDAG, so we // should remove PHIs there. - addPass(createWinEHPass(/*DemoteCatchSwitchPHIOnly=*/false)); + addPass(createWinEHPass(/*DemoteCatchSwitchPHIOnly=*/true)); addPass(createWasmEHPass()); break; case ExceptionHandling::None: diff --git a/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll b/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll index bd577e387c72b..164c138cb7578 100644 --- a/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll +++ b/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll @@ -2,6 +2,7 @@ ; RUN: opt < %s -win-eh-prepare -demote-catchswitch-only -wasm-eh-prepare -S --mattr=+atomics,+bulk-memory | FileCheck %s ; RUN: opt < %s -passes='win-eh-prepare,wasm-eh-prepare' -S | FileCheck %s ; RUN: opt < %s -passes='win-eh-prepare,wasm-eh-prepare' -S --mattr=+atomics,+bulk-memory | FileCheck %s +; RUN: llc < %s -wasm-enable-eh -exception-model=wasm -mattr=+exception-handling -stop-after=wasm-eh-prepare | FileCheck %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-unknown" @@ -245,7 +246,6 @@ bb.true: ; preds = %entry bb.true.0: ; preds = %bb.true br label %merge -; CHECK: bb.false bb.false: ; preds = %entry br label %merge