This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] try to canonicalize logical shift after bswap
ClosedPublic

Authored by spatel on Mar 29 2022, 7:00 AM.

Details

Summary

When shifting by a byte-multiple:
bswap (shl X, C) --> lshr (bswap X), C
bswap (lshr X, C) --> shl (bswap X), C

This is the backend version of D122010 and an alternative suggested in D120648. There's an extra check to make sure the shift amount is valid that was not in the rough draft.

I'm not sure if there is a larger motivating case for RISCV (bug report?), but the ARM diffs show a benefit from having a late version of the transform (because we do not combine the loads in IR).

Diff Detail

Event Timeline

spatel created this revision.Mar 29 2022, 7:00 AM
spatel requested review of this revision.Mar 29 2022, 7:00 AM

As bswap nodes tend to be generated in the DAG via load combines I agree we need this fold here as well as instcombine

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

Add comment describing the fold

spatel updated this revision to Diff 418892.Mar 29 2022, 8:39 AM
spatel marked an inline comment as done.

Added code comment to describe the transform.

RKSimon accepted this revision.Mar 30 2022, 2:29 AM

LGTM - cheers

This revision is now accepted and ready to land.Mar 30 2022, 2:29 AM
This revision was landed with ongoing or failed builds.Mar 30 2022, 6:30 AM
This revision was automatically updated to reflect the committed changes.