diff mbox

Fix ICE with TARGET_MEM_REF (PR rtl-optimization/49235)

Message ID 20110531121810.GQ17079@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek May 31, 2011, 12:18 p.m. UTC
Hi!

Since richi's create_mem_ref_raw change to avoid creating TMR if base
is not ADDR_EXPR we can ICE, if base is NULL and offset some non-zero
constant, because (plus:DI (const_int 0) (const_int 16)) is created.
The second hunk fixes it by not adding the 0 in (the routine ends with
if (!*addr) *addr = const0_rtx; so it is fine not to add it), the third
hunk is an alternative fix, because it is fine to create MEM_REF in that
case too (both base and offset are constants).  Either of the hunks
fixes this, but it doesn't hurt to put in both.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2011-05-31  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/49235
	* tree-ssa-address.c (gen_addr_rtx): Ignore base if it is const0_rtx.
	(create_mem_ref_raw): Create MEM_REF even if base is INTEGER_CST.

	* gcc.dg/pr49235.c: New test.


	Jakub

Comments

Richard Biener May 31, 2011, 12:27 p.m. UTC | #1
On Tue, May 31, 2011 at 2:18 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> Since richi's create_mem_ref_raw change to avoid creating TMR if base
> is not ADDR_EXPR we can ICE, if base is NULL and offset some non-zero
> constant, because (plus:DI (const_int 0) (const_int 16)) is created.
> The second hunk fixes it by not adding the 0 in (the routine ends with
> if (!*addr) *addr = const0_rtx; so it is fine not to add it), the third
> hunk is an alternative fix, because it is fine to create MEM_REF in that
> case too (both base and offset are constants).  Either of the hunks
> fixes this, but it doesn't hurt to put in both.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2011-05-31  Jakub Jelinek  <jakub@redhat.com>
>
>        PR rtl-optimization/49235
>        * tree-ssa-address.c (gen_addr_rtx): Ignore base if it is const0_rtx.
>        (create_mem_ref_raw): Create MEM_REF even if base is INTEGER_CST.
>
>        * gcc.dg/pr49235.c: New test.
>
> --- gcc/tree-ssa-address.c.jj   2011-05-31 08:03:10.000000000 +0200
> +++ gcc/tree-ssa-address.c      2011-05-31 09:34:21.000000000 +0200
> @@ -1,5 +1,5 @@
>  /* Memory address lowering and addressing mode selection.
> -   Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010
> +   Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2011
>    Free Software Foundation, Inc.
>
>  This file is part of GCC.
> @@ -129,7 +129,7 @@ gen_addr_rtx (enum machine_mode address_
>       *addr = act_elem;
>     }
>
> -  if (base)
> +  if (base && base != const0_rtx)
>     {
>       if (*addr)
>        *addr = simplify_gen_binary (PLUS, address_mode, base, *addr);
> @@ -365,7 +365,7 @@ create_mem_ref_raw (tree type, tree alia
>      ???  As IVOPTs does not follow restrictions to where the base
>      pointer may point to create a MEM_REF only if we know that
>      base is valid.  */
> -  if (TREE_CODE (base) == ADDR_EXPR
> +  if ((TREE_CODE (base) == ADDR_EXPR || TREE_CODE (base) == INTEGER_CST)
>       && (!index2 || integer_zerop (index2))
>       && (!addr->index || integer_zerop (addr->index)))
>     return fold_build2 (MEM_REF, type, base, addr->offset);
> --- gcc/testsuite/gcc.dg/pr49235.c.jj   2011-05-31 09:42:50.000000000 +0200
> +++ gcc/testsuite/gcc.dg/pr49235.c      2011-05-31 09:40:02.000000000 +0200
> @@ -0,0 +1,25 @@
> +/* PR rtl-optimization/49235 */
> +/* { dg-do compile { target { int32plus } } } */
> +/* { dg-options "-O -fno-delete-null-pointer-checks -fno-tree-scev-cprop -ftree-vectorize -fno-vect-cost-model -w" } */
> +
> +void
> +foo (void)
> +{
> +  unsigned i;
> +  unsigned *p = 0;
> +  for (i = 0; i < 4; ++i)
> +    *p++ = 0;
> +  for (i = 0; i < 4; ++i)
> +    *p++ = 0;
> +}
> +
> +void
> +bar (void)
> +{
> +  unsigned i;
> +  unsigned *p = (unsigned *) (__UINTPTR_TYPE__) 0x12340000;
> +  for (i = 0; i < 4; ++i)
> +    *p++ = 0;
> +  for (i = 0; i < 4; ++i)
> +    *p++ = 0;
> +}
>
>        Jakub
>
diff mbox

Patch

--- gcc/tree-ssa-address.c.jj	2011-05-31 08:03:10.000000000 +0200
+++ gcc/tree-ssa-address.c	2011-05-31 09:34:21.000000000 +0200
@@ -1,5 +1,5 @@ 
 /* Memory address lowering and addressing mode selection.
-   Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -129,7 +129,7 @@  gen_addr_rtx (enum machine_mode address_
       *addr = act_elem;
     }
 
-  if (base)
+  if (base && base != const0_rtx)
     {
       if (*addr)
 	*addr = simplify_gen_binary (PLUS, address_mode, base, *addr);
@@ -365,7 +365,7 @@  create_mem_ref_raw (tree type, tree alia
      ???  As IVOPTs does not follow restrictions to where the base
      pointer may point to create a MEM_REF only if we know that
      base is valid.  */
-  if (TREE_CODE (base) == ADDR_EXPR
+  if ((TREE_CODE (base) == ADDR_EXPR || TREE_CODE (base) == INTEGER_CST)
       && (!index2 || integer_zerop (index2))
       && (!addr->index || integer_zerop (addr->index)))
     return fold_build2 (MEM_REF, type, base, addr->offset);
--- gcc/testsuite/gcc.dg/pr49235.c.jj	2011-05-31 09:42:50.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr49235.c	2011-05-31 09:40:02.000000000 +0200
@@ -0,0 +1,25 @@ 
+/* PR rtl-optimization/49235 */
+/* { dg-do compile { target { int32plus } } } */
+/* { dg-options "-O -fno-delete-null-pointer-checks -fno-tree-scev-cprop -ftree-vectorize -fno-vect-cost-model -w" } */
+
+void
+foo (void)
+{
+  unsigned i;
+  unsigned *p = 0;
+  for (i = 0; i < 4; ++i)
+    *p++ = 0;
+  for (i = 0; i < 4; ++i)
+    *p++ = 0;
+}
+
+void
+bar (void)
+{
+  unsigned i;
+  unsigned *p = (unsigned *) (__UINTPTR_TYPE__) 0x12340000;
+  for (i = 0; i < 4; ++i)
+    *p++ = 0;
+  for (i = 0; i < 4; ++i)
+    *p++ = 0;
+}