Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ class EffectAnalyzer {

void visitCall(Call* curr) {
if (Intrinsics(parent.module).isCallWithoutEffects(curr)) {
// The only effect this can have is to branch (which is an effect of the
// return, not the call).
if (curr->isReturn) {
Comment thread
stevenfontanella marked this conversation as resolved.
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