-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove binary_imm64 and int_compare_imm instructions #4721
base: main
Are you sure you want to change the base?
Conversation
cc #3250 One of my arguments against this is that it makes the clif ir harder to read and harder to generate. |
Hah, I guess I accidentally implemented what @cfallin proposed just by being confused. Thanks for digging that link up! It's helpful context. I noticed a couple things that I think are existing bugs while exploring this:
Independent of whether we keep the |
Wow, there is a lot more stuff attached to Is it possible to print a comment with the const value if one of the sides of the For example:
It would also help in cases other than |
I believe that is exactly what will happen with the egraph PR if it gets merged. https://github.com/bytecodealliance/wasmtime/pull/4249/files#diff-a596f1a407284b0b3591c17053fe0eff7f0229b70a2fcd9282fc2aedf9cd38a4 |
I like that! It would resolve my readability concerns. It doesn't resolve my clif ir generation concern though. |
Reading the PR it looks like we keep the Although I do think we should note in the docs that those helpers are not actual instructions by themselves. |
Right, missed that. |
I have no idea yet whether this is a good change, and it definitely should not be merged as-is. The main issues are that there are a bunch of tests I haven't fixed up, and some optimizations I've removed. Also I have no performance measurements yet to see what effect this has on either compile time or generated code quality. I just wanted to understand what the `*_imm` instructions were used for, and trying to grep for them didn't work out well. So I removed them to let the compiler tell me where they're used instead. To avoid having to make as many changes, I introduced a `InstImmBuilder` trait. It provides methods like `iadd_imm` which emit the pair of instructions that legalization would have decomposed that instruction into eventually anyway. I have several questions that this may help with answering: - Is there significant savings, in IR code size and/or compile time, from inlining one immediate operand into some instructions at the frontend? Or is the widespread frontend use of these instructions just for convenience? - Can simple_preopt cleanly identify arithmetic identities involving constants without rewriting to use these combined forms? - Is there a compile-time cost to simple_preopt rewriting into combined forms, only for legalization to rewrite them away again soon after?
@jameysharp thanks for exploring here. As others have pointed out, there's a lot of prior thought on this, and overall I think we do want to remove these variants in due time.
Currently the legalizer rewrites them from
Indeed, that's one of the main effects of my mid-end optimizer work; it will replace Now, regarding I think that breaking the ops into smaller pieces, and keeping Part of the reason for the original So I think the right way forward is in spirit similar to what you've done here, but (i) do it after the mid-end optimizer lands (pending RFC approval!) because there are some immediate followup thoughts in how to make legalization ride on top of it; and (ii) generate the |
966c571
to
abe4268
Compare
This turned out to be really easy to do. I've opened #4725 for that.
Right. So these rules in x64's lower.isle can never match, yeah?
(i) makes sense. (ii) isn't immediately (!) obvious to me: is it that you want to make this pattern available as a convenience on more instructions, or you're worried about the correctness of the hand-written wrappers, or...? |
Basically, generating the code is less error-prone and allows us to extend the pattern to arbitrary instructions as we choose fit; it's a lower-entropy encoding of the system design. We already generate |
Apparently so! We can go ahead and delete those; I suspect fuzz coverage, if we were to get it in terms of ISLE source, would show this as well. |
Great, I've opened #4726 for deleting those.
Okay, I can see that. It's not obvious to me what code that should generate, though, because the current But we can sort that out when it's time to re-visit this after your e-graph work lands. |
I have no idea yet whether this is a good change, and it definitely
should not be merged as-is. The main issues are that there are a bunch
of tests I haven't fixed up, and some optimizations I've removed. Also I
have no performance measurements yet to see what effect this has on
either compile time or generated code quality.
I just wanted to understand what the
*_imm
instructions were used for,and trying to grep for them didn't work out well. So I removed them to
let the compiler tell me where they're used instead.
To avoid having to make as many changes, I introduced a
InstImmBuilder
trait. It provides methods like
iadd_imm
which emit the pair ofinstructions that legalization would have decomposed that instruction
into eventually anyway.
I have several questions that this may help with answering:
Is there significant savings, in IR code size and/or compile time,
from inlining one immediate operand into some instructions at the
frontend? Or is the widespread frontend use of these instructions just
for convenience?
Can simple_preopt cleanly identify arithmetic identities involving
constants without rewriting to use these combined forms?
Is there a compile-time cost to simple_preopt rewriting into combined
forms, only for legalization to rewrite them away again soon after?