[PATCH] [tree-optimization] Fix for PR96701

2020-10-29 Thread Eugene Rozenfeld via Gcc-patches
This patch adds a pattern for folding

x >> x

to

  0

as described in PR96701.


Without this patch the x86_64-pc-linux-gnu code generated for this function



int

foo (int i)

{

  return i >> i;

}



is



movecx,edi

saredi,cl

test   edi,edi

setne  al

ret



With the patch the code is


xoreax,eax
ret


Tested on x86_64-pc-linux-gnu.

Eugene


0001-Optimize-self-right-shift-to-0.patch
Description: 0001-Optimize-self-right-shift-to-0.patch


[PATCH] [tree-optimization] Fix for PR96701

2020-10-29 Thread Eugene Rozenfeld via Gcc-patches
This patch adds a pattern for folding 
x >> x
to
  0
as described in PR96701.

Without this patch the x86_64-pc-linux-gnu code generated for this function

int
foo (int i)
{
  return i >> i;
}

is

mov    ecx,edi
sar    edi,cl
test   edi,edi
setne  al
ret

With the patch the code is 

xor    eax,eax
ret  

Tested on x86_64-pc-linux-gnu.

Eugene


0001-Optimize-self-right-shift-to-0.patch
Description: 0001-Optimize-self-right-shift-to-0.patch


Re: [PATCH] [tree-optimization] Fix for PR96701

2020-11-05 Thread Jeff Law via Gcc-patches


On 10/29/20 8:36 PM, Eugene Rozenfeld via Gcc-patches wrote:
> This patch adds a pattern for folding
>
> x >> x
>
> to
>
>   0
>
> as described in PR96701.
>
>
> Without this patch the x86_64-pc-linux-gnu code generated for this function
>
>
>
> int
>
> foo (int i)
>
> {
>
>   return i >> i;
>
> }
>
>
>
> is
>
>
>
> movecx,edi
>
> saredi,cl
>
> test   edi,edi
>
> setne  al
>
> ret
>
>
>
> With the patch the code is
>
>
> xoreax,eax
> ret
>
>
> Tested on x86_64-pc-linux-gnu.
>
> Eugene
>
> 0001-Optimize-self-right-shift-to-0.patch
>
> From 2e952db4925e34674afabd2fed2330d91289a398 Mon Sep 17 00:00:00 2001
> From: Eugene Rozenfeld 
> Date: Thu, 29 Oct 2020 19:23:46 -0700
> Subject: [PATCH] Optimize self right-shift to 0.
>
> Simplify x >> x to 0. This fixes PR96701.

Thanks.  Installed on the trunk. 


jeff




Re: [PATCH] [tree-optimization] Fix for PR96701

2020-10-30 Thread Richard Biener via Gcc-patches
On Fri, Oct 30, 2020 at 3:38 AM Eugene Rozenfeld via Gcc-patches
 wrote:
>
> This patch adds a pattern for folding
>
> x >> x
>
> to
>
>   0
>
> as described in PR96701.
>
>
> Without this patch the x86_64-pc-linux-gnu code generated for this function
>
>
>
> int
>
> foo (int i)
>
> {
>
>   return i >> i;
>
> }
>
>
>
> is
>
>
>
> movecx,edi
>
> saredi,cl
>
> test   edi,edi
>
> setne  al
>
> ret
>
>
>
> With the patch the code is
>
>
> xoreax,eax
> ret
>
>
> Tested on x86_64-pc-linux-gnu.

OK.

Thanks,
Richard.

> Eugene