Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@ class EffectAnalyzer {

void visitCall(Call* curr) {
if (Intrinsics(parent.module).isCallWithoutEffects(curr)) {
if (curr->isReturn) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (curr->isReturn) {
// The only effect this can have is to branch (which is an effect of the return, not the call).
if (curr->isReturn) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explains why we special-case it.

parent.branchesOut = true;
}
return;
}

Expand Down
21 changes: 21 additions & 0 deletions test/lit/passes/vacuum-intrinsics.wast
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,25 @@
;; Helper function for the above.
(nop)
)

;; CHECK: (func $const (type $1) (result i32)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
(func $const (result i32)
(i32.const 1)
)

;; CHECK: (func $sets-branch-effect (type $1) (result i32)
;; CHECK-NEXT: (return_call $call.without.effects
;; CHECK-NEXT: (ref.func $const)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $sets-branch-effect (result i32)
;; $call-without-effects still has a branch effect, even though the callee
;; body is assumed to have no effects.
;; Without a branch effect, we'd be free to optimize this to (unreachable).
;; Also, we're free to optimize away the (unreachable).
(return_call $call.without.effects (ref.func $const))
(unreachable)
)
)
Loading