[PATCH] D71891: [PowerPC] Exploit the rlwinm + rlwinm when "and" with constant

qshanz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 26 02:17:51 PST 2019


steven.zhang created this revision.
steven.zhang added reviewers: jsji, nemanjai, shchenz, hfinkel, PowerPC.
Herald added subscribers: wuzish, kbarton, hiraditya.
Herald added a project: LLVM.

If it is "and" with constant, for some special pattern, we could use the rotate and instructions instead of the "andi." which requires us to generate the mask using several instructions.  i.e. If the mask looks like this. That is, it has two groups of ones, and all of them are within the bits [32, 63].

      MB  MB2    ME2 ME           
  +----------------------+    
  |0001111100000011111000| 
  +----------------------+    
   0 32                 64   

We could optimize it as:

1. Clear the bit (MB2, ME2) first. It is a warpping mask. RLWINM 0, ME2, MB2

      MB  MB2    ME2 ME           MB  MB2    ME2 ME
  +----------------------+    +----------------------+
  |1111111111111111111111| -> |1111111100000011111111+
  +----------------------+    +----------------------+
   0 32                 64     0 32                  64

2. Clear the bit (ME, MB). Notice that, as RLWINM will update the bit [0, 31], we can only do this optimization if MB >= 32.

      MB  MB2    ME2 ME           MB  MB2    ME2 ME
  +----------------------+    +----------------------+
  |1111111100000011111111| -> |0001111100000011111000+
  +----------------------+    +----------------------+
   0 32                 64     0 32                 64


https://reviews.llvm.org/D71891

Files:
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/test/CodeGen/PowerPC/and-mask.ll
  llvm/test/CodeGen/PowerPC/cmpb.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71891.235330.patch
Type: text/x-patch
Size: 4600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191226/57d9328b/attachment-0001.bin>


More information about the llvm-commits mailing list