On Tue, Apr 21, 2015 at 09:08:04PM +0930, Alan Modra wrote:
> +           if (DEBUG_INSN_P (dinsn)
> +               && insn_uses_reg (dinsn, dregno, end_dregno))
> +             {
> +               if (live_bbs.is_empty ())
> +                 /* Put debug info for the insn we'll be moving
> +                    into the destination block.  */
> +                 {
> +                   rtx_insn *newdinsn
> +                     = emit_debug_insn_after (copy_rtx (PATTERN (dinsn)),
> +                                              bb_note (bb));
> +                   df_insn_rescan (newdinsn);
> +                 }

This isn't safe.  There could be a debug_insn for the same decl anywhere in
between the dinsn and bb_note (bb) on the chosen live path, if there is,
this change will break stuff.

> +               /* If the insn is a simple reg-reg copy, then reset
> +                  the debug insn to point to src.  */
> +               if (REG_P (src) && GET_MODE (src) == GET_MODE (dest))
> +                 {
> +                   INSN_VAR_LOCATION_LOC (dinsn)
> +                     = simplify_replace_rtx (INSN_VAR_LOCATION_LOC (dinsn),
> +                                             dest, src);
> +                   df_insn_rescan (dinsn);
> +                 }
> +               else
> +                 {
> +                   /* Otherwise remove anything about this variable.  */
> +                   INSN_VAR_LOCATION_LOC (dinsn)
> +                     = gen_rtx_UNKNOWN_VAR_LOC ();
> +                   df_insn_rescan_debug_internal (dinsn);
> +                 }

This works (though the simplify_replace_rtx alone is dangerous, you'd better
use propagate_for_debug), but is unnecessarily limitting.  You could just 
insert a debug
insn with a debug temp before the original insn and replace all the uses of
the reg with the debug temporary.
And, as you are walking all the bbs on the path insn by insn anyway,
supposedly you could instead use the valtrack APIs for that.
Thus, call
  dead_debug_local_init (&debug, NULL, NULL);
before walking the first bb, then call
  dead_debug_add on each FOR_EACH_INSN_INFO_USE of the debug insns that
overlaps the dest REG, and finally
  dead_debug_insert_temp with DEBUG_TEMP_BEFORE_WITH_VALUE and
finally dead_debug_local_finish.  Of course all this guarded with
MAY_HAVE_DEBUG_INSNS.

        Jakub

Reply via email to