On Mon, 12 Jun 2017, James Greenhalgh wrote:

> 
> Hi,
> 
> As subject, for the testcase in the patch:
> 
>   unsigned long
>   f2 (unsigned long a, int b)
>   {
>     unsigned long x = 1UL << b;
>     return a / x;
>   }
> 
> We currently generate:
> 
>   f2:
>       mov     x2, 1
>       lsl     x1, x2, x1
>       udiv    x0, x0, x1
>       ret
> 
> Which could instead be transformed to:
> 
>   f2:
>       lsr     x0, x0, x1
>       ret
> 
> OK?

+   We can't do the same for signed A, as it might be negative, which 
would
+   introduce undefined behaviour.  */

huh, AFAIR it is _left_ shift of negative values that invokes
undefined behavior.

Note that as you are accepting vectors you need to make sure the
target actually supports arithmetic right shift of vectors
(you only know it supports left shift and division -- so it might
be sort-of-superfluous to check in case there is no arch that supports
those but not the other).

Richard.

> Thanks,
> James
> 
> ---
> gcc/
> 
> 2017-06-12  James Greenhalgh  <james.greenha...@arm.com>
> 
>       * match.pd (A / (1 << B) -> A >> B): New.
> 
> gcc/testsuite/
> 
> 2017-06-12  James Greenhalgh  <james.greenha...@arm.com>
> 
>       * gcc.dg/tree-ssa/forwprop-37.c: New.
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)

Reply via email to