This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix abs(sub nsw) -> absd
ClosedPublic

Authored by rjj on Feb 20 2023, 4:21 AM.

Details

Summary

This partially reverts a regression introduced in 8f25e382c5b1 for AArch64 targets. In particular, we restore the logic of (abs (sub nsw x, y)) -> abds(x, y) for all targets except X86, which keeps the logic introduced in 8f25e382c5b1. See also https://reviews.llvm.org/D142288.

Depends on D144399

Diff Detail

Event Timeline

rjj created this revision.Feb 20 2023, 4:21 AM
rjj requested review of this revision.Feb 20 2023, 4:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2023, 4:21 AM

Can you make sure you upload with full context (-U999999), as per https://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch. It can help to make the patch easier to review.

llvm/include/llvm/CodeGen/TargetLowering.h
801

Perhaps preferABDSToABSWithNSW? It would be good to add the "nsw" part, as there are other ways to produce ABDS

llvm/test/CodeGen/AArch64/neon-saba.ll
1 ↗(On Diff #498794)

Nothing in this file seems to change. We already have abd tests for the nsw cases in neon-abd.ll.

If you would like to add saba tests too, perhaps split this off into a separate commit? It can be good to do that anyway to see the differences in generated code in the patch.

Thanks for looking into this.
I will let @RKSimon comment on the usage of the TTI hook.

I had a couple of nits about the tests, see inlined.
You can consider to "precommit" the tests: put them up for review separately, then rebase this patch on top of that. The codegen differences are easy to spot here, so not necessary, but up to you if you want to get that out of the way first.

llvm/test/CodeGen/AArch64/neon-saba.ll
5 ↗(On Diff #498794)

If this is NEON, then we probably don't want to be passing +sve2 here.
And +neon is passed twice.

llvm/test/CodeGen/AArch64/sve-saba.ll
5

sve is implied by sve2, and I think neon is implied too, so just sve2 will suffice.

I don't have a strong opinion on this, but you can also use llc -mattr=+sve2 so you don't need these attributes at all.

rjj updated this revision to Diff 498883.Feb 20 2023, 8:57 AM
rjj edited the summary of this revision. (Show Details)
  • Split tests to D144399
  • Rename preferABDSToABS -> preferABDSToABSWithNSW
rjj marked an inline comment as done.Feb 20 2023, 10:06 AM
RKSimon added inline comments.Feb 20 2023, 1:51 PM
llvm/include/llvm/CodeGen/TargetLowering.h
802

just return true by default - isOperationLegalOrCustom can cause problems after custom lowering if it re-expands the ABDS pattern

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
10523–10524

It would be better to use hasOperation() && TLI.preferABDSToABSWithNSW and remove the Legal/Custom checks from the callback - otherwise you can potentially end up in loops where the custom lowering re-expands the abds pattern and its gets matched over and over again....

llvm/lib/Target/X86/X86ISelLowering.cpp
57121

just return false - x86 doesn't have any ABDS instructions

rjj updated this revision to Diff 499113.Feb 21 2023, 4:38 AM

Remove Legal/Custom checks from the callback as suggested by @RKSimon.

rjj marked 4 inline comments as done.Feb 21 2023, 4:39 AM
RKSimon accepted this revision.Feb 21 2023, 2:57 PM

LGTM - cheers

This revision is now accepted and ready to land.Feb 21 2023, 2:57 PM
This revision was landed with ongoing or failed builds.Feb 22 2023, 1:17 AM
This revision was automatically updated to reflect the committed changes.