diff --git a/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index 568382bac15..d70e197cbcb 100644 --- a/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -636,15 +636,12 @@ void WebAssemblyLowerEmscriptenEHSjLj::rebuildSSA(Function &F) { SSAUpdater SSA; for (BasicBlock &BB : F) { for (Instruction &I : BB) { + SSA.Initialize(I.getType(), I.getName()); + SSA.AddAvailableValue(&BB, &I); for (auto UI = I.use_begin(), UE = I.use_end(); UI != UE;) { Use &U = *UI; ++UI; - SSA.Initialize(I.getType(), I.getName()); - SSA.AddAvailableValue(&BB, &I); auto *User = cast(U.getUser()); - if (User->getParent() == &BB) - continue; - if (auto *UserPN = dyn_cast(User)) if (UserPN->getIncomingBlock(U) == &BB) continue; diff --git a/test/CodeGen/WebAssembly/lower-em-sjlj.ll b/test/CodeGen/WebAssembly/lower-em-sjlj.ll index 5dfdd440fbc..540b13bdbd8 100644 --- a/test/CodeGen/WebAssembly/lower-em-sjlj.ll +++ b/test/CodeGen/WebAssembly/lower-em-sjlj.ll @@ -226,6 +226,26 @@ entry: unreachable } +; Tests if SSA rewrite works when a use and its def are within the same BB. +define void @ssa_rewite_in_same_bb() { +entry: + call void @foo() + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + ; CHECK: %{{.*}} = phi i32 [ %var[[VARNO:.*]], %for.inc.split ] + %0 = phi i32 [ %var, %for.inc ], [ undef, %entry ] + %var = add i32 0, 0 + br label %for.inc + +for.inc: ; preds = %for.cond + %call5 = call i32 @setjmp(%struct.__jmp_buf_tag* undef) #0 + br label %for.cond + +; CHECK: for.inc.split: + ; CHECK: %var[[VARNO]] = phi i32 [ %var, %for.inc ] +} + declare void @foo() ; Function Attrs: returns_twice declare i32 @setjmp(%struct.__jmp_buf_tag*) #0