This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][PeepholeOpt]Optimize ALU + compare to flag-setting ALU
ClosedPublic

Authored by mingmingl on Mar 24 2023, 9:11 AM.

Details

Summary

The motivating example is in https://godbolt.org/z/45nbdYMK9

  • For this example, subs is generated for the good case; sub followed by cmp is generated for the bad case. Since signed overflow is undefined behavior in C/C++ (indicated as nsw flag in LLVM IR), subs should be generated for the good case as well.

This patch relaxes one restriction from "quit optimization when V is used" to "continue if MI produces poison value when signed overflow occurs". This is not meant to be C/C++ specific since it looks at 'NoSWrap' since it looks at MachineInstr flags.

Diff Detail

Event Timeline

mingmingl created this revision.Mar 24 2023, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 9:11 AM
mingmingl requested review of this revision.Mar 24 2023, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 9:11 AM
mingmingl updated this revision to Diff 508128.Mar 24 2023, 9:14 AM
mingmingl edited the summary of this revision. (Show Details)
mingmingl added reviewers: dmgreen, efriedma, fhahn.
dmgreen accepted this revision.Mar 27 2023, 10:21 AM

I see, I like it. I sometimes worry about poison in the backend but this looks like a good idea.
LGTM. Thanks

This revision is now accepted and ready to land.Mar 27 2023, 10:21 AM

thanks for reviews! Going to submit this patch and the pre-commit test (D146754) together.

This revision was landed with ongoing or failed builds.Mar 27 2023, 10:56 AM
This revision was automatically updated to reflect the committed changes.