-
Notifications
You must be signed in to change notification settings - Fork 829
Closed
Description
Right now, Binaryen optimizes this:
local.get $condition
if (result i32)
local.get $argument
ref.func $my_func ;; my_func (param i32) (result i32)
call $call.without.effects
else
i32.const 0
endInto this:
local.get $condition
local.get $argument
call $my_func ;; my_func (param i32) (result i32)
i32.const 0
selectBefore, the function was only called if $condition but the optimizer has made the call unconditional. I can think of two situations this is harmful:
- If the call to the function is expensive. Getting rid of the conditional execution means binaryen will eliminate any faster paths trying to avoid the call.
- If the call to the function may have effects when the condition is not kept. For example, a function which crashes for inputs less than 0 might be guarded by a check to make sure the input is less than 0, avoiding the call if so. This call can still be removed if the result is dropped (because it has no other effects), but the condition must not be removed.
I have run into both of these cases trying to implement call.without.effects into my compiler. I was advised to make this into it's own issue from my comment on #7574.
Metadata
Metadata
Assignees
Labels
No labels