Skip to content

Commit

Permalink
Revert "[WebAssembly] Remove threwValue comparison after __wasm_setjm…
Browse files Browse the repository at this point in the history
…p_test (#86633)"

This reverts commit 52431fd.

The PR assumed `__threwValue` couldn't be 0, but it could be when the
thrown thing is not a longjmp but an exception, so that `if` check was
actually necessary.
  • Loading branch information
aheejin committed Mar 28, 2024
1 parent d9e3e11 commit 6b7ecc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
/// %__THREW__.val = __THREW__;
/// __THREW__ = 0;
/// %__threwValue.val = __threwValue;
/// if (%__THREW__.val != 0) {
/// if (%__THREW__.val != 0 & %__threwValue.val != 0) {
/// %label = __wasm_setjmp_test(%__THREW__.val, functionInvocationId);
/// if (%label == 0)
/// emscripten_longjmp(%__THREW__.val, %__threwValue.val);
Expand Down Expand Up @@ -712,10 +712,12 @@ void WebAssemblyLowerEmscriptenEHSjLj::wrapTestSetjmp(
BasicBlock *ThenBB1 = BasicBlock::Create(C, "if.then1", F);
BasicBlock *ElseBB1 = BasicBlock::Create(C, "if.else1", F);
BasicBlock *EndBB1 = BasicBlock::Create(C, "if.end", F);
Value *ThrewCmp = IRB.CreateICmpNE(Threw, getAddrSizeInt(M, 0));
Value *ThrewValue = IRB.CreateLoad(IRB.getInt32Ty(), ThrewValueGV,
ThrewValueGV->getName() + ".val");
Value *ThrewCmp = IRB.CreateICmpNE(Threw, getAddrSizeInt(M, 0));
IRB.CreateCondBr(ThrewCmp, ThenBB1, ElseBB1);
Value *ThrewValueCmp = IRB.CreateICmpNE(ThrewValue, IRB.getInt32(0));
Value *Cmp1 = IRB.CreateAnd(ThrewCmp, ThrewValueCmp, "cmp1");
IRB.CreateCondBr(Cmp1, ThenBB1, ElseBB1);

// Generate call.em.longjmp BB once and share it within the function
if (!CallEmLongjmpBB) {
Expand Down
7 changes: 4 additions & 3 deletions llvm/test/CodeGen/WebAssembly/lower-em-ehsjlj.ll
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ entry:
to label %try.cont unwind label %lpad

; CHECK: entry.split.split:
; CHECK: %__threwValue.val = load i32, ptr @__threwValue
; CHECK-NEXT: %[[CMP:.*]] = icmp ne i32 %__THREW__.val, 0
; CHECK: %[[CMP0:.*]] = icmp ne i32 %__THREW__.val, 0
; CHECK-NEXT: %__threwValue.val = load i32, ptr @__threwValue
; CHECK-NEXT: %[[CMP1:.*]] = icmp ne i32 %__threwValue.val, 0
; CHECK-NEXT: %[[CMP:.*]] = and i1 %[[CMP0]], %[[CMP1]]
; CHECK-NEXT: br i1 %[[CMP]], label %if.then1, label %if.else1

; This is exception checking part. %if.else1 leads here
Expand Down Expand Up @@ -119,7 +121,6 @@ if.end: ; preds = %entry
; CHECK-NEXT: unreachable

; CHECK: normal:
; CHECK-NEXT: %__threwValue.val = load i32, ptr @__threwValue, align 4
; CHECK-NEXT: icmp ne i32 %__THREW__.val, 0

return: ; preds = %if.end, %entry
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ entry:
; CHECK-NEXT: call cc{{.*}} void @__invoke_void_[[PTR]]_i32(ptr @emscripten_longjmp, [[PTR]] %[[JMPBUF]], i32 1)
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load [[PTR]], ptr @__THREW__
; CHECK-NEXT: store [[PTR]] 0, ptr @__THREW__
; CHECK-NEXT: %[[CMP0:.*]] = icmp ne [[PTR]] %__THREW__.val, 0
; CHECK-NEXT: %[[THREWVALUE_VAL:.*]] = load i32, ptr @__threwValue
; CHECK-NEXT: %[[CMP:.*]] = icmp ne [[PTR]] %__THREW__.val, 0
; CHECK-NEXT: %[[CMP1:.*]] = icmp ne i32 %[[THREWVALUE_VAL]], 0
; CHECK-NEXT: %[[CMP:.*]] = and i1 %[[CMP0]], %[[CMP1]]
; CHECK-NEXT: br i1 %[[CMP]], label %if.then1, label %if.else1

; CHECK: entry.split.split.split:
Expand Down

0 comments on commit 6b7ecc7

Please sign in to comment.