[rs6000] Avoid useless masking of count operand for rotation

Eric Botcazou botcazou@adacore.com
Tue Sep 29 10:26:28 GMT 2020


Hi,

the Interfaces package of the Ada library defines a pair of rotation operators

   function Rotate_Left  (Value : Unsigned_n; Amount : Natural)
      return Unsigned_n;
   function Rotate_Right (Value : Unsigned_n; Amount : Natural)
      return Unsigned_n;

on modular (aka unsigned) types of n bits.  The translation in GENERIC for the 
Rotate_Left on a 32-bit modular type is:

  Value r<< ((UNSIGNED_32) Amount & 31)

and the masking is present all the way down to the assembly at -O2:

        rlwinm 4,4,0,27,31
        rotlw 3,3,4

Now this masking is redundant since it's done by the hardware so it would be 
nice to get rid of it.  I have attached a couple of patches to that effect: 
the first one adds new instructions while the second one only adds splitters.

Tested on PowerPC64/Linux, OK (which one) for the mainline?


2020-09-29  Eric Botcazou  <ebotcazou@adacore.com>

	* config/rs6000/rs6000.md (*rotl<mode>3_mask): New.
	(*rotlsi3_mask_64): Likewise.
	(*rotl<mode>3_dot): Change to use P mode iterator.
	(*rotl<mode>3_mask_dot): New.
	(*rotl<mode>3_dot2): Change to use P mode iterator.
	(*rotl<mode>3_mask_dot2): New.


2020-09-29  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/rotate1.adb: New test.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p1.diff
Type: text/x-patch
Size: 5639 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200929/99e21bdb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p2.diff
Type: text/x-patch
Size: 5760 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200929/99e21bdb/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rotate1.adb
Type: text/x-adasrc
Size: 280 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200929/99e21bdb/attachment-0002.bin>


More information about the Gcc-patches mailing list