This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] combine rlwinm + rlwinm to rlwinm
ClosedPublic

Authored by shchenz on Nov 18 2019, 12:10 AM.

Details

Summary

This patch is to support combining of rlwinm + rlwinm to one rlwinm.
For example:

x3 = rlwinm x3, 27, 5, 31
x3 = rlwinm x3, 19, 0, 12

can be combined to

x3 = rlwinm x3, 14, 0, 12

Diff Detail

Event Timeline

shchenz created this revision.Nov 18 2019, 12:10 AM
steven.zhang added inline comments.Nov 18 2019, 2:08 AM
llvm/test/CodeGen/PowerPC/fold-rlwinm.mir
3

Do we have the real case(IR) to expose this missing combination ? Just MIR test is NOT enough I think.

shchenz updated this revision to Diff 229811.Nov 18 2019, 5:08 AM

add IR testcases

steven.zhang accepted this revision.Nov 18 2019, 7:37 PM

LGTM with some minor nit. But please wait for some days if some one else have more comments.

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
873

Personally, I prefer to add a else here to make the code more clear, then, you don't need the break in line 871 any more. Anyway, it depends on you.

877

I think, this should be moved to line 900 as else clause.

This revision is now accepted and ready to land.Nov 18 2019, 7:37 PM
shchenz updated this revision to Diff 230001.Nov 19 2019, 1:22 AM
shchenz marked 2 inline comments as done.

fix @steven.zhang comment and rebase after https://reviews.llvm.org/D69032 committed.

This revision was automatically updated to reflect the committed changes.
shchenz reopened this revision.EditedNov 27 2019, 12:42 AM

This patch caused failure in http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/21918

Narrow down case:

#define rlwinm( output, input, sh, mb, me ) \
   __asm__( "rlwinm %0, %1, %2, %3, %4" \
          : "=r"(output) \
          : "r"(input), "i"(sh), "i"(mb), "i"(me) \
          : )

int main()
{
   long x = 0x1122334455667788L ;
   long y ;
   long z;

   rlwinm( y, x, 1, 0, 30) ;
   rlwinm( z, y, 31, 1, 0) ;

   printf("0x%016lX -> 0x%016lX -> 0x%016lX\n", x, y, z) ;

   return 0 ;
}

We should get result:

0x1122334455667788 -> 0x00000000AACCEF10 -> 0x5566778855667788

But with this patch,

y = RLWINM x, 1, 0, 30
z = RLWINM y, 31, 1, 0

We will convert z to z = LI 0, this is not right.

This revision is now accepted and ready to land.Nov 27 2019, 12:42 AM
shchenz planned changes to this revision.Nov 27 2019, 12:46 AM
shchenz updated this revision to Diff 231472.Nov 28 2019, 5:24 PM

fix the failure cases found by buildbot.

This revision is now accepted and ready to land.Nov 28 2019, 5:24 PM
shchenz requested review of this revision.Nov 28 2019, 5:26 PM
lkail accepted this revision.EditedDec 2 2019, 1:31 AM
lkail added a subscriber: lkail.

LGTM. Thanks for fixing it. Personally, I would recommend Alive to verify peephole optimizations.

This revision is now accepted and ready to land.Dec 2 2019, 1:31 AM
This revision was automatically updated to reflect the committed changes.