This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner][RISCV] Pre-promote (zext (abs X)) to (abs (sext X)) when X has an illegal type.
ClosedPublic

Authored by craig.topper on Dec 21 2022, 3:18 PM.

Details

Summary

Type legalization will insert a sign extend anyway. By doing it
early we can remove the zext. ComputeNumSignBits can't spot it
after type legalization because type legalization may expand
the abs to sra+xor+sub.

If the zext result type is larger than the type to be promoted to,
we'll promote to a legal type and then zext the rest of the way.
If the legal type is larger than the destination type we can promote
and then truncate.

Diff Detail

Event Timeline

craig.topper created this revision.Dec 21 2022, 3:18 PM
craig.topper requested review of this revision.Dec 21 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2022, 3:18 PM
craig.topper edited the summary of this revision. (Show Details)Dec 21 2022, 3:19 PM
craig.topper added inline comments.
llvm/test/CodeGen/RISCV/iabs.ll
664

Looks like we might be missing a DAG combine to fold back to back SRA?

craig.topper added inline comments.Dec 21 2022, 3:28 PM
llvm/test/CodeGen/RISCV/iabs.ll
664

Nevermind, it's because there is a freeze hiding after the first two shifts.

craig.topper retitled this revision from [DAGCombiner] Pre-promote (zext (abs X)) to (abs (sext X)) when X has an illegal type. to [DAGCombiner][RISCV] Pre-promote (zext (abs X)) to (abs (sext X)) when X has an illegal type..Dec 21 2022, 3:29 PM
RKSimon added inline comments.Jan 5 2023, 7:04 AM
llvm/test/CodeGen/RISCV/iabs.ll
664

D136529 should fix this once I've addressed the remaining regressions

asb accepted this revision.Jan 9 2023, 4:02 AM

LGTM.

This revision is now accepted and ready to land.Jan 9 2023, 4:02 AM
This revision was landed with ongoing or failed builds.Jan 13 2023, 10:41 AM
This revision was automatically updated to reflect the committed changes.