This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] Introduce a new BITREVERSE node along with a corresponding LLVM intrinsic
ClosedPublic

Authored by jmolloy on Nov 11 2015, 3:52 AM.

Details

Summary

Several backends have instructions to reverse the order of bits in an integer. Conceptually matching such patterns is similar to @llvm.bswap, and it was mentioned in http://reviews.llvm.org/D14234 that it would be best if these patterns were matched in InstCombine instead of reimplemented in every different target.

This patch introduces an intrinsic @llvm.bitreverse.i* that operates similarly to @llvm.bswap. For plumbing purposes there is also a new ISD node ISD::BITREVERSE, with simple expansion and promotion support.

The intention is that InstCombine's BSWAP detection logic will be extended to support BITREVERSE too, and @llvm.bitreverse intrinsics emitted (if the backend supports lowering it efficiently).

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy updated this revision to Diff 39898.Nov 11 2015, 3:52 AM
jmolloy retitled this revision from to [SDAG] Introduce a new BITREVERSE node along with a corresponding LLVM intrinsic.
jmolloy updated this object.
jmolloy added reviewers: arsenm, hfinkel, majnemer.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.
hfinkel accepted this revision.Nov 11 2015, 7:41 AM
hfinkel edited edge metadata.

We need a few more tests, especially for the generic expansion. PPC (because you should hit the integer promotion logic) and x86 would be good options, and I think it is perfectly reasonable to test the i8, or even i16, expansions completely. Otherwise, LGTM.

In follow-up, we should make sure we optimize bitreverse(bitreverse(x)) -> x.

This revision is now accepted and ready to land.Nov 11 2015, 7:41 AM
jmolloy closed this revision.Dec 12 2015, 5:37 AM

r253024.

docs/LangRef.rst
10397

i16 should be iN here.