prevent REG_EQUAL on set-mem insns

Richard Guenther richard.guenther@gmail.com
Sat Sep 11 10:14:00 GMT 2010


On Fri, Sep 10, 2010 at 6:26 PM, Olivier Hainque <hainque@adacore.com> wrote:
> Hello,
>
> At least a couple of spots in the middle end sometimes end up
> attaching a REG_EQUAL note to insns that don't set a REG.
>
> For example, we observe:
>
>  (insn 7 6 61 2 q.adb:7 (set (mem/v:SI (reg/f:SI 124) [0 S4 A32])
>        (reg:SI 125)) 325 {*movsi_internal1}
>    (expr_list:REG_EQUAL (const_int 12 [0xc])
>    ...
>
> for the store from this Ada testcase:
>
>   procedure q is
>     x : integer;
>     for x'address use system.null_address;
>   begin
>     x := 12;
>   exception
>      when others => null;
>   end;
>
> out of fwprop1 on powerpc-aix with -O.
>
> This is invalid according to what rtl.texi clearly advertises:
>
>  << item REG_EQUIV
>    @itemx REG_EQUAL
>    This note is only valid on an insn that sets only one register and
>    indicates that that register will be equal to @var{op} at run time;
>    the scope of this equivalence differs between the two types of notes.
>  >>
>
> And this becomes problematic when (for example) purge_dead_edges takes
> advantage of that definition, considering that insns with a (REG_EQUAL
> const) note cannot trap:
>
>  /* If this instruction cannot trap, remove REG_EH_REGION notes.  */
>  if (NONJUMP_INSN_P (insn)
>      && (note = find_reg_note (insn, REG_EH_REGION, NULL)))
>    {
>      rtx eqnote;
>
>      if (! may_trap_p (PATTERN (insn))
>          || ((eqnote = find_reg_equal_equiv_note (insn))
>              && ! may_trap_p (XEXP (eqnote, 0))))
>        remove_note (insn, note);
>    }
>
> On the testcase at hand, this results in the removal of the insn
> quoted above from its EH region, eventhough that insn may (and does)
> trap at runtime.
>
> This is particularily visible here, because the insn happens to
> be the only insn in the region, and its removal results in the entire
> removal of the code expected to catch the Ada exception raised from
> the trap handler.
>
> The attached patch fixes this by preventing the invalid REG_EQUAL note
> attachement from a couple of places where we have witnessed it.
>
> This fixes the testcase on powerpc-aix and was successfully bootstrapped
> and regtested on x86_64-suse-linux.
>
> OK ?

Ok.

Thanks,
Richard.

> Thanks in advance,
>
> Olivier
>
> 2010-09-10  Olivier Hainque  <hainque@adacore.com>
>
>        * fwprop.c (forward_propagate_and_simplify): Only attach a
>        REG_EQUAL note to an insn if the destination is a register.
>        * gcse.c (try_replace_reg): Likewise.
>
>        testsuite/
>        * gnat.dg/memtrap.adb: New test.
>



More information about the Gcc-patches mailing list