This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine][AArch64][ARM] Combine abd(sub(x, y)) to abd if the sub is nsw
ClosedPublic

Authored by dmgreen on Jan 13 2023, 12:54 AM.

Details

Summary

This implements the fold (abs (sub nsw x, y)) -> abds(x, y). Providing the sub is nsw this appears to be valid without the extensions that are usually used for abds. https://alive2.llvm.org/ce/z/XHVaB3. The equivalent abdu combine seems to not be valid.

Diff Detail

Event Timeline

dmgreen created this revision.Jan 13 2023, 12:54 AM
dmgreen requested review of this revision.Jan 13 2023, 12:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2023, 12:54 AM
RKSimon added inline comments.Jan 13 2023, 2:15 PM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
10168

Worth moving this inside combineABSToABD?

dmgreen updated this revision to Diff 489565.Jan 16 2023, 8:05 AM

Moved into combineABSToABD.

RKSimon accepted this revision.Jan 16 2023, 8:21 AM

LGTM - cheers

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
10120

You can probably hoist this before the sext/zext test?

This revision is now accepted and ready to land.Jan 16 2023, 8:21 AM
dmgreen added inline comments.Jan 18 2023, 2:10 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
10120

The idea is that if we have a sext/zext pair then is better to use them in the abd, creating the smaller type. We use the wrapping flags if that fails.

This revision was landed with ongoing or failed builds.Jan 18 2023, 2:11 AM
This revision was automatically updated to reflect the committed changes.