This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Exploit the rlwinm + rlwinm when "and" with constant
AbandonedPublic

Authored by Esme on Dec 26 2019, 2:16 AM.

Details

Reviewers
jsji
nemanjai
shchenz
hfinkel
steven.zhang
Group Reviewers
Restricted Project
Summary

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
  1. 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

Diff Detail