-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
riscv64: Add fmsub
/fnmsub
/fnmadd
instruction lowerings
#8588
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This is neat! Out of curiosity, can't you use these same fnmsub/fnmadd instructions if That said, I'm a little worried about whether fusing negation into an Anyway, I thought way too much about this and I think you can fold those 16 cases into four rules based on how many of
With the right helpers you can write the four rules all at the same priority. This is a little awkward and would be easier if ISLE had or-patterns or match expressions or something, but I think the following should work and generate about as good of a pattern-matching tree as we're capable of right now.
Also I think you might be able to handle |
I'm not entirely sure, for these 4 instructions I pretty much copied the LLVM lowerings for them. I also briefly looked at our x64 backend and noted that it had some similar rules for
That case isn't represented in our X64 backend, and I'm not entirely sure how to prove it. My z3 skills are non existent, but I probably can implement it for the x64 backend and fuzz it for a few days. I also don't think magnitudes should matter here, Edit: I was searching for related fma transformations and found this alive2 testcase that seems like a good starting point to try to play around and prove these transformations. I've never used alive, but I'll give it a go this afternoon, seems like it should be fairly easy.
Adding the |
So, I played around with alive for a bit. Really cool tool! Unfortunately the compiler explorer for alive2 has a short timeout so I had to run these locally.
Yes you can! Here's the proof that I built for this and it does validate. Result
This one doesn't seem to pan out, it seems to have the issue with the signed zero. Proof Result
I can't really test this using alive, since it doesn't have a fmsub intrinsic. But I did something similar using Result
We should probably add a mid end rule for this case!
I'm not too worried about this case because it's already covered by a mid end rule. That being said, it looks like It comes pretty much for free with the solution that you proposed above, so might as well have it. I'm going to write up a PR using that. Thanks for looking at this in so much detail! |
👋 Hey,
This PR adds lowering rules for the
fmsub
/fnmsub
/fnmadd
instructions.These instructions were already implemented in the backend, but had no lowering rules associated with them, so they were never emitted.