This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Combine ISD::AND into AArch64ISD::ANDS
ClosedPublic

Authored by dmgreen on Jan 31 2022, 12:55 AM.

Details

Summary

If we already have a AArch64ISD::ANDS node with identical operands, we can merge any ISD::AND into it, reducing the instruction count by calculating the value and the flags in a single operation. This code is taken from the X86 backend, and could also handle AArch64ISD::ADDS and AArch64ISD::SUBS, but I couldn't find any test cases where it came up.

Diff Detail

Event Timeline

dmgreen created this revision.Jan 31 2022, 12:55 AM
dmgreen requested review of this revision.Jan 31 2022, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2022, 12:55 AM
david-arm added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14372

Is there any need to pass in GenericOpc as it seems to always be ISD::AND?

14382

Do you have to do this given we're not merging any results together? For example, does it work if you just do

return DCI.DAG.getNode(GenericOpc, DL, VT, LHS, RHS);

?

dmgreen added inline comments.Feb 1 2022, 12:44 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14372

Did you see the Note 2 lines up :)

This code can also be used for AArch64::ADDS and AArch64::SUBS, I just couldn't find a testcase where it modified things yet. On X86 they lower certain x86 intrinsics straight to the nodes with make them easier to write tests for.

14382

Hmm. A node that produces 2 results needs to be replaced by a node the produces 2 results.

david-arm added inline comments.Feb 1 2022, 12:55 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14372

I did indeed. :) And despite that I still wondered if it was worth adding the extra argument at this point given there isn't any evidence that it's needed yet.

dmgreen added inline comments.Mar 1 2022, 6:45 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
14372

Hmm. I think it makes the function less generic, and it would be good to re-use it for ADDS/SUBS. I feel like that's just worse. But then I did rename the functions already (I didn't like the old name it had), and never found a good test case for the ADDS/SUBS which was a shame.

dmgreen updated this revision to Diff 412082.Mar 1 2022, 6:45 AM

Remove the GenericOpc argument.

samtebbs accepted this revision.Mar 10 2022, 2:16 AM

Nice one. LGTM if david has no other comments

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

ANDS -> ADDS

This revision is now accepted and ready to land.Mar 10 2022, 2:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2022, 2:16 AM
david-arm accepted this revision.Mar 10 2022, 2:44 AM

LGTM as well! Sorry I'd forgotten about this and should have responded much earlier!

This revision was landed with ongoing or failed builds.Mar 17 2022, 2:44 AM
This revision was automatically updated to reflect the committed changes.