Page MenuHomePhabricator

[X86] Add DAG combine for negation of CMOV absolute value pattern.
ClosedPublic

Authored by craig.topper on Oct 14 2021, 6:28 PM.

Details

Summary

This patch detects the absolute value pattern on the RHS of a
subtract. If we find it we swap the CMOV true/false values and
replace the subtract with an ADD.

There may be a more generic way to do this, but I'm not sure.
Targets that don't have legal or custom ISD::ABS use a generic
expand in DAG combiner already when it sees (neg (abs(x))). I
haven't checked what happens if the neg is a more general subtract.

Fixes PR50991 for X86.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 14 2021, 6:28 PM
craig.topper requested review of this revision.Oct 14 2021, 6:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2021, 6:28 PM

Need some tests where the sub's op0 is not 0 if the fold is for general sub (not just negate)?

clang-format and rebase on top of new tests

RKSimon accepted this revision.Oct 16 2021, 2:23 AM

LGTM - cheers

This revision is now accepted and ready to land.Oct 16 2021, 2:23 AM
spatel accepted this revision.Oct 16 2021, 12:50 PM

LGTM

This revision was landed with ongoing or failed builds.Oct 16 2021, 1:36 PM
This revision was automatically updated to reflect the committed changes.