Patchwork PR45834: make restrict qualifier work for char pointer type.

login
register
mail settings
Submitter Bingfeng Mei
Date Oct. 21, 2010, 2:26 p.m.
Message ID <7FB04A5C213E9943A72EE127DB74F0ADA691645C5F@SJEXCHCCR02.corp.ad.broadcom.com>
Download mbox | patch
Permalink /patch/68610/
State New
Headers show

Comments

Bingfeng Mei - Oct. 21, 2010, 2:26 p.m.
Hi, 

This patch fixes bug PR45834. In alias.c, a check for QImode prevents later 
alias analysis based on restrict qualifier for char pointer type.
This check is based on ancient code (at least 1997), and other modern
way has been implemented for dealing that (MEM_ALIAS_SET == 0)
according to Richard. 

Bootstrapped and tested for x86_64-unknown-linux-gnu. 

Before the patch  powerpc-elf-gcc -O2 tst.c -S

void foo (char * __restrict a, char *__restrict b, char * __restrict c)
{
  *a = *b;
  *(a+1) = *c;
}
foo:
	lbz 0,0(4)
	stb 0,0(3)
	lbz 0,0(5)
	stb 0,1(3)
	blr

After the patch
foo:
	lbz 0,0(4)
	lbz 9,0(5)
	stb 0,0(3)
	stb 9,1(3)
	blr

Not sure how to add it into testsuite though. 

Cheers,
Bingfeng Mei

2010-10-21  Bingfeng Mei  <bmei@broadcom.com>
	* alias.c (true_dependence_1): Remove check for QImode, 
        which prevents accurate alias info of char pointer type 
        with restrict qualifier. The check is handled by
        better and more modern method now.
        (may_alias_p): Ditto.
Richard Guenther - Oct. 21, 2010, 2:41 p.m.
On Thu, Oct 21, 2010 at 4:26 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> Hi,
>
> This patch fixes bug PR45834. In alias.c, a check for QImode prevents later
> alias analysis based on restrict qualifier for char pointer type.
> This check is based on ancient code (at least 1997), and other modern
> way has been implemented for dealing that (MEM_ALIAS_SET == 0)
> according to Richard.
>
> Bootstrapped and tested for x86_64-unknown-linux-gnu.
>
> Before the patch  powerpc-elf-gcc -O2 tst.c -S
>
> void foo (char * __restrict a, char *__restrict b, char * __restrict c)
> {
>  *a = *b;
>  *(a+1) = *c;
> }
> foo:
>        lbz 0,0(4)
>        stb 0,0(3)
>        lbz 0,0(5)
>        stb 0,1(3)
>        blr
>
> After the patch
> foo:
>        lbz 0,0(4)
>        lbz 9,0(5)
>        stb 0,0(3)
>        stb 9,1(3)
>        blr
>
> Not sure how to add it into testsuite though.
>
> Cheers,
> Bingfeng Mei
>
> 2010-10-21  Bingfeng Mei  <bmei@broadcom.com>
>        * alias.c (true_dependence_1): Remove check for QImode,
>        which prevents accurate alias info of char pointer type
>        with restrict qualifier. The check is handled by
>        better and more modern method now.
>        (may_alias_p): Ditto.

Just say

        * alias.c (true_dependence_1): Remove obsolete check for QImode.

Ok with that change.

Richard.


> Index: alias.c
> ===================================================================
> --- alias.c     (revision 165637)
> +++ alias.c     (working copy)
> @@ -2459,7 +2459,7 @@ true_dependence_1 (const_rtx mem, enum m
>
>   /* We cannot use aliases_everything_p to test MEM, since we must look
>      at MEM_ADDR, rather than XEXP (mem, 0).  */
> -  if (mem_mode == QImode || GET_CODE (mem_addr) == AND)
> +  if (GET_CODE (mem_addr) == AND)
>     return 1;
>
>   /* ??? In true_dependence we also allow BLKmode to alias anything.  Why
> @@ -2655,7 +2655,7 @@ may_alias_p (const_rtx mem, const_rtx x)
>
>   /* We cannot use aliases_everything_p to test MEM, since we must look
>      at MEM_ADDR, rather than XEXP (mem, 0).  */
> -  if (GET_MODE (mem) == QImode || GET_CODE (mem_addr) == AND)
> +  if (GET_CODE (mem_addr) == AND)
>     return 1;
>
>   if (fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr,
>
>
>
>

Patch

Index: alias.c
===================================================================
--- alias.c     (revision 165637)
+++ alias.c     (working copy)
@@ -2459,7 +2459,7 @@  true_dependence_1 (const_rtx mem, enum m

   /* We cannot use aliases_everything_p to test MEM, since we must look
      at MEM_ADDR, rather than XEXP (mem, 0).  */
-  if (mem_mode == QImode || GET_CODE (mem_addr) == AND)
+  if (GET_CODE (mem_addr) == AND)
     return 1;

   /* ??? In true_dependence we also allow BLKmode to alias anything.  Why
@@ -2655,7 +2655,7 @@  may_alias_p (const_rtx mem, const_rtx x)

   /* We cannot use aliases_everything_p to test MEM, since we must look
      at MEM_ADDR, rather than XEXP (mem, 0).  */
-  if (GET_MODE (mem) == QImode || GET_CODE (mem_addr) == AND)
+  if (GET_CODE (mem_addr) == AND)
     return 1;

   if (fixed_scalar_and_varying_struct_p (mem, x, mem_addr, x_addr,