Patchwork Try to canonicalize MEM_REFs that are put into MEM_EXPRs for DEBUG_INSNs (PR debug/47283, take 2)

login
register
mail settings
Submitter Jakub Jelinek
Date March 3, 2011, 3:11 p.m.
Message ID <20110303151121.GU30899@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/85293/
State New
Headers show

Comments

Jakub Jelinek - March 3, 2011, 3:11 p.m.
On Thu, Mar 03, 2011 at 03:31:55PM +1000, Richard Henderson wrote:
> Do you really want to fallthru with newexp here?
> In theory it could have folded to anything.  My guess is that
> you want to restart instead...

Here is an updated patch that does that, and also as requested by
Richard Guenther instead of calling set_mem_expr with a type
just clears MEM_EXPR if it isn't suitable for alias oracle.

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

2011-03-03  Jakub Jelinek  <jakub@redhat.com>

	PR debug/47283
	* cfgexpand.c (expand_debug_expr) <case MEM_REF>: If MEM_REF
	first operand is not is_gimple_mem_ref_addr, try to fold it.
	If the operand still isn't is_gimple_mem_ref_addr, clear
	MEM_EXPR on op0.



	Jakub
Richard Guenther - March 3, 2011, 3:43 p.m.
On Thu, Mar 3, 2011 at 4:11 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Mar 03, 2011 at 03:31:55PM +1000, Richard Henderson wrote:
>> Do you really want to fallthru with newexp here?
>> In theory it could have folded to anything.  My guess is that
>> you want to restart instead...
>
> Here is an updated patch that does that, and also as requested by
> Richard Guenther instead of calling set_mem_expr with a type
> just clears MEM_EXPR if it isn't suitable for alias oracle.
>
> Bootstrapped/regtested again on x86_64-linux and i686-linux, ok?

Ok.

Thanks,
Richard.

> 2011-03-03  Jakub Jelinek  <jakub@redhat.com>
>
>        PR debug/47283
>        * cfgexpand.c (expand_debug_expr) <case MEM_REF>: If MEM_REF
>        first operand is not is_gimple_mem_ref_addr, try to fold it.
>        If the operand still isn't is_gimple_mem_ref_addr, clear
>        MEM_EXPR on op0.
>
> --- gcc/cfgexpand.c.jj  2011-02-21 15:37:42.000000000 +0100
> +++ gcc/cfgexpand.c     2011-03-02 11:05:32.000000000 +0100
> @@ -2578,6 +2578,15 @@ expand_debug_expr (tree exp)
>       }
>
>     case MEM_REF:
> +      if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
> +       {
> +         tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
> +                                    TREE_OPERAND (exp, 0),
> +                                    TREE_OPERAND (exp, 1));
> +         if (newexp)
> +           return expand_debug_expr (newexp);
> +       }
> +      /* FALLTHROUGH */
>     case INDIRECT_REF:
>       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
>       if (!op0)
> @@ -2611,6 +2620,9 @@ expand_debug_expr (tree exp)
>
>       op0 = gen_rtx_MEM (mode, op0);
>       set_mem_attributes (op0, exp, 0);
> +      if (TREE_CODE (exp) == MEM_REF
> +         && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
> +       set_mem_expr (op0, NULL_TREE);
>       set_mem_addr_space (op0, as);
>
>       return op0;
>
>
>        Jakub
>

Patch

--- gcc/cfgexpand.c.jj	2011-02-21 15:37:42.000000000 +0100
+++ gcc/cfgexpand.c	2011-03-02 11:05:32.000000000 +0100
@@ -2578,6 +2578,15 @@  expand_debug_expr (tree exp)
       }
 
     case MEM_REF:
+      if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
+	{
+	  tree newexp = fold_binary (MEM_REF, TREE_TYPE (exp),
+				     TREE_OPERAND (exp, 0),
+				     TREE_OPERAND (exp, 1));
+	  if (newexp)
+	    return expand_debug_expr (newexp);
+	}
+      /* FALLTHROUGH */
     case INDIRECT_REF:
       op0 = expand_debug_expr (TREE_OPERAND (exp, 0));
       if (!op0)
@@ -2611,6 +2620,9 @@  expand_debug_expr (tree exp)
 
       op0 = gen_rtx_MEM (mode, op0);
       set_mem_attributes (op0, exp, 0);
+      if (TREE_CODE (exp) == MEM_REF
+	  && !is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
+	set_mem_expr (op0, NULL_TREE);
       set_mem_addr_space (op0, as);
 
       return op0;