This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Combine funnel shifts to AArch64 rotate opcodes.
AbandonedPublic

Authored by aemerson on Mar 24 2021, 10:19 AM.

Details

Summary

Adds AArch64::G_ROR opcode to allow us to import patterns for selection.

This fixes the 0.5% size regression on ClamAV introduced when G_FSHL/G_FSHR started being lowered instead of falling back.

The 0.7% regression on consumer-typeset is still remaining.

Diff Detail

Event Timeline

aemerson created this revision.Mar 24 2021, 10:19 AM
aemerson requested review of this revision.Mar 24 2021, 10:19 AM

@arsenm @foad Is it worth making this rotate op generic? I'm happy to keep it in AArch64, but wasn't sure what the overall plan was for optimizing funnels to rotates.

@arsenm @foad Is it worth making this rotate op generic? I'm happy to keep it in AArch64, but wasn't sure what the overall plan was for optimizing funnels to rotates.

The DAG has rotates, so probably

There are a bunch of rotate combines in the DAGCombiner, so it would make sense to have a generic G_ROR and G_ROL. Looks like some low-hanging fruit.

  // fold (or (shl x, C1), (srl x, C2)) -> (rotl x, C1)

  // fold (or (shl x, C1), (srl x, C2)) -> (rotr x, C2)

  // fold (xor (shl 1, x), -1) -> (rotl ~1, x)

  // (or (and (shl (A, 8)), 0xff00ff00), (and (srl (A, 8)), 0x00ff00ff)) -> (rotr (bswap A), 16)

  // fold (or (shl x, (*ext y)),
  //          (srl x, (*ext (sub 32, y)))) ->
  //   (rotl x, y) or (rotr x, (sub 32, y))

  // fold (or (shl x, (*ext (sub 32, y))),
  //          (srl x, (*ext y))) ->
  //   (rotr x, y) or (rotl x, (sub 32, y))
  
... and so on ...
aemerson abandoned this revision.Mar 26 2021, 3:47 PM

Implementing as generic operations in other patches.