Skip to content

Commit 129a354

Browse files
committed
[WebAssemblyOptimizeReturned] Skip lifetime intrinsic uses
Replacing an alloca with a call result in a lifetime intrinsic will cause a verifier error. Fixes #150498.
1 parent 6e04e1e commit 129a354

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyOptimizeReturned.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ void OptimizeReturned::visitCallBase(CallBase &CB) {
6363
if (isa<Constant>(Arg))
6464
continue;
6565
// Like replaceDominatedUsesWith but using Instruction/Use dominance.
66-
Arg->replaceUsesWithIf(&CB,
67-
[&](Use &U) { return DT->dominates(&CB, U); });
66+
Arg->replaceUsesWithIf(&CB, [&](Use &U) {
67+
auto *I = cast<Instruction>(U.getUser());
68+
return !I->isLifetimeStartOrEnd() && DT->dominates(&CB, U);
69+
});
6870
}
6971
}
7072

llvm/test/CodeGen/WebAssembly/returned.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,27 @@ define i32 @test_second_arg(i32 %a, i32 %b) {
8080
%call = call i32 @do_something_else(i32 %a, i32 %b)
8181
ret i32 %b
8282
}
83+
84+
define void @test() {
85+
; CHECK-LABEL: test:
86+
; CHECK: .functype test () -> ()
87+
; CHECK-NEXT: # %bb.0: # %entry
88+
; CHECK-NEXT: global.get $push0=, __stack_pointer
89+
; CHECK-NEXT: i32.const $push1=, 16
90+
; CHECK-NEXT: i32.sub $push7=, $pop0, $pop1
91+
; CHECK-NEXT: local.tee $push6=, $0=, $pop7
92+
; CHECK-NEXT: global.set __stack_pointer, $pop6
93+
; CHECK-NEXT: i32.const $push4=, 12
94+
; CHECK-NEXT: i32.add $push5=, $0, $pop4
95+
; CHECK-NEXT: call $drop=, returns_arg, $pop5
96+
; CHECK-NEXT: i32.const $push2=, 16
97+
; CHECK-NEXT: i32.add $push3=, $0, $pop2
98+
; CHECK-NEXT: global.set __stack_pointer, $pop3
99+
; CHECK-NEXT: return
100+
entry:
101+
%a = alloca i32
102+
call void @llvm.lifetime.start.p0(i64 4, ptr %a)
103+
%ret = call ptr @returns_arg(ptr %a)
104+
call void @llvm.lifetime.end.p0(i64 4, ptr %a)
105+
ret void
106+
}

0 commit comments

Comments
 (0)