Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented Jul 8, 2024

Anything else right before an unreachable is removed by the main DCE pass
anyhow, but because of the structured form of BinaryenIR we can't remove a
drop. That is, this is the difference between

(i32.eqz (i32.const 42) (unreachable) )

and

(drop (call $foo) ) (unreachable)

In both cases the unreachable is preceded by something we don't need, but in the latter case
it must remain in BinaryenIR for validation.

To optimize this, add a rule in StackIR.

Fixes #6715

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

In principle this could go even further. We could remove both drops here:

(drop (call $foo) ) (drop (call $bar) ) (unreachable) 
@kripken
Copy link
Member Author

kripken commented Jul 8, 2024

Yeah, that looks possible too, if we analyze the stack backwards. I'll add a TODO.

@kripken kripken merged commit e93babc into WebAssembly:main Jul 8, 2024
@kripken kripken deleted the drop-unreachable branch July 8, 2024 21:18
@tlively
Copy link
Member

tlively commented Jul 9, 2024

Another opportunity here would be to remove drops preceding branches:

(drop ;; can be removed (call $foo) ) (br $l ;; could be any control flow transfer (call $bar) ) 
@gkdn gkdn mentioned this pull request Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants