[PATCH] Try to canonicalize MEM_REFs that are put into MEM_EXPRs for DEBUG_INSNs (PR debug/47283)

Richard Guenther richard.guenther@gmail.com
Thu Mar 3 10:02:00 GMT 2011


On Thu, Mar 3, 2011 at 8:22 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Mar 03, 2011 at 03:31:55PM +1000, Richard Henderson wrote:
>> On 03/03/2011 03:40 AM, Jakub Jelinek wrote:
>> >      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)
>> > +       exp = newexp;
>> > +   }
>> > +      /* FALLTHROUGH */
>> >      case INDIRECT_REF:
>>
>> 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...
>
> fold_binary only optimizes:
> /* MEM[&MEM[p, CST1], CST2] -> MEM[p, CST1 + CST2].  */
> and
> /* MEM[&a.b, CST2] -> MEM[&a, offsetof (a, b) + CST2].  */
>
> But if you prefer, I can certainly do there
>        if (newexp)
>          return expand_debug_expr (newexp);
> instead.

It's probably more safe, at least for 4.7, in case we ever start to do
constant folding here.

Btw, I don't really like another caller of set_mem_attributes that
passes a type rather than an expression ... OTOH, the folding
should never fail to generate a canonical MEM ref (I bet asserting
that the MEM_REF is a proper one after folding passes bootstrap
just ok), so maybe just drop the debug expr on the floor in this
case (eventually ICE when checking is enabled)?  At least I can't
see how we could end up with a non-canonicalizable address.

Richard.



More information about the Gcc-patches mailing list