wasmtime
wasmtime copied to clipboard
cranelift: add icmp-of-icmp rules for comparisons with 1
Suggested by @cfallin in this zulip thread: https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/disassemly.20seems.20.28relatively.29.20unoptimized
The icmp-of-icmp rules only included comparisons with 0. So this
(x == y) != 0
gets simplified to
x == y
But the equivalent
(x == y) == 1
did not get simplified, even though the rules to apply are just the inverse of the rules for 0.
I've added the rules for icmp(..) == 1 and icmp(..) != 1 and tried to add some more comments to the existing rules.
I need some help to figure out how I could write a test for this, because I haven't found the tests in the codebase :)
@tertsdiepraam thanks for this! The tests are in cranelift/filetests/filetests/; you can find midend-optimizer-specific tests that assert on expected simplified IR in egraph/, and tests that check execution results in runtests/. Probably both would be good for this case?
I've added tests both in egraph/ and runtests/ and fixed up the comment. I hope it's good now.