This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][Optimization]Emit FCCMP for AND of two float compares
ClosedPublic

Authored by ipriyanshi1708 on Jun 12 2023, 8:52 AM.

Details

Summary

Transforms and(fcmp(a, b), fcmp(c, d)) into fccmp(fcmp(a, b), c, d)
Issue link: https://github.com/llvm/llvm-project/issues/60819

Diff Detail

Event Timeline

ipriyanshi1708 created this revision.Jun 12 2023, 8:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 8:52 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
ipriyanshi1708 updated this revision to Diff 530532.EditedJun 12 2023, 9:04 AM
This comment has been deleted.
ipriyanshi1708 retitled this revision from Solving the FCCMP issue to [AArch64][Optimization]Solving the FCCMP issue.Jun 12 2023, 9:06 AM
ipriyanshi1708 published this revision for review.Jun 12 2023, 9:06 AM
ipriyanshi1708 edited the summary of this revision. (Show Details)
ipriyanshi1708 added a reviewer: samtebbs.
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 9:07 AM

Generated the desired assembly

Update the tests

Updated the test file

Thank you for fixing up the other test changes, this is looking pretty good. I have some small changes to suggest.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17158–17177

This doesn't quite match the LLVM style guide. You can try running git-clang-format HEAD^ to fix it automatically. If that doesn't work, you can re-style the code manually to make it look like the rest of the file.

17158–17177

I think this code would be nice to have in a function, perhaps named something like performANDSETCCCombine? Some comments about the transformation it performs (turning and(fcmp(a, b), fcmp(c, d)) into fccmp(fcmp(a, b), c, d)) would be good too.

Done the required changes

samtebbs added a comment.EditedJul 4 2023, 6:45 AM

Thanks! Just a few more clean-up changes from me and I'll add another reviewer for a wider audience.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17110

This could be moved to be just before the line it's used on.

17111

This could be moved to be just before where's it's used and AArch64CC seems like a verbose name so maybe just CC is enough.

17112

Same story with Cmp as it could be moved to be just before where it's set,

17128–17133

This can just return the value from DAG.getNode(...)

17135

We'll need a default return of SDValue() in case the if statements above don't pass.

samtebbs added inline comments.
llvm/test/CodeGen/AArch64/andcompare.ll
2525

Oh and a more explaining function name would be good, something like and_fcmp?

ipriyanshi1708 marked 2 inline comments as done.

Updated the code

A couple more comments, then it looks good to me.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17108

Some comments, about what transformation this function performs, would be useful.

17118

Perhaps rename this to CC? It's already clear that it's an AArch64 condition code.

ipriyanshi1708 marked 5 inline comments as done.

Added the comments

samtebbs accepted this revision.Jul 11 2023, 1:30 AM

Just one small change, but otherwise it looks good to me! I can commit this for you once you've moved the comment above the function, and then we can see about getting you commit access yourself.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17133

I think this comment is quite useful and would be good to have on the line above the function definition.

This revision is now accepted and ready to land.Jul 11 2023, 1:30 AM
ipriyanshi1708 marked 2 inline comments as done.

Done the required changes

ipriyanshi1708 retitled this revision from [AArch64][Optimization]Solving the FCCMP issue to [AArch64][Optimization]Solved the FCCMP issue.Jul 11 2023, 2:52 AM
ipriyanshi1708 edited the summary of this revision. (Show Details)
ipriyanshi1708 retitled this revision from [AArch64][Optimization]Solved the FCCMP issue to [AArch64][Optimization]Emit FCCMP for AND of two float compares.Jul 11 2023, 7:03 AM

Fixed the failing test file

samtebbs added inline comments.Jul 13 2023, 2:27 AM
llvm/test/CodeGen/AArch64/select_fmf.ll
15–17 ↗(On Diff #539834)

This change doesn't look beneficial because it adds extra instructions that aren't really needed. I think we'll need to find a way of restricting the code you've written to not transform this example. You can try looking at the debug output with the -print-after-all option added to llc to see what is different for this test case and the one you added. While testing you can copy this test file and remove everything but the two functions we're interested in to reduce the debug output when you run llc on it.

hiraditya added inline comments.Jul 25 2023, 9:11 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17128

Have we already checked for and before calling emitConjunction ?

Fixed the code for the test file

dmgreen added inline comments.Aug 1 2023, 9:20 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17142–17143

I think these may be better as DAG.getConstant(0, DL, VT), as opposed to AArch64::WZR / AArch64::XZR. They should get converted to the same thing eventually, but having zero constant's will be easier for the rest of DAG to reason about.

samtebbs added inline comments.Aug 2 2023, 1:52 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17121

Perhaps add that LowerSELECT can be modified to work with the IR that this function produces, thereby removing the need for this check.

17128

Yep, this function is only called when an AND is found.

ipriyanshi1708 added inline comments.Aug 5 2023, 12:31 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17111

I kept it AArch64CC because CC is giving the error.

17121

Yep! We can update it in the future so that it works with the codegen.

17128

Sorry, I didn't get what you are trying to ask? Can you please elaborate little bit.

17142–17143

Yup! I tried that too but it was generating this instruction "cset w0, ne" instead of this one "cset w0, vs".

17158–17177

Okay! I will try to do it asap.

dmgreen added inline comments.Aug 7 2023, 12:55 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17142–17143

Is that with something like this?

return DAG.getNode(AArch64ISD::CSINC, DL, VT,                      
                   DAG.getConstant(0, DL, VT),
                   DAG.getConstant(0, DL, VT),
                   DAG.getConstant(InvertedCC, DL, MVT::i32), Cmp);
ipriyanshi1708 added inline comments.Aug 7 2023, 1:26 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17142–17143

Ohh! yes it is correct. Earlier I have replaced DAG.getConstant(InvertedCC, DL, MVT::i32), Cmp); with DAG.getConstant(0, DL, VT) that's why it was not working.

Updated the code

dmgreen accepted this revision.Aug 8 2023, 7:03 AM

From what I can see this LGTM. Thanks.

Thanks David. I can commit this for you if you'd like @ipriyanshi1708 . Shall I use the same email address and name as your previous commit?

Thanks David. I can commit this for you if you'd like @ipriyanshi1708 . Shall I use the same email address and name as your previous commit?

Yes! Please do commit it for me using the same email address and name.

This revision was landed with ongoing or failed builds.Aug 9 2023, 7:58 AM
This revision was automatically updated to reflect the committed changes.