diff mbox

[-fcompare-debug] find jump before debug insns in expand

Message ID orzij83e6b.fsf@lxoliva.fsfla.org
State New
Headers show

Commit Message

Alexandre Oliva Jan. 3, 2017, 5:28 a.m. UTC
A debug insn after the final jump of a basic block may cause the
expander to emit a dummy move where the non-debug compile won't
because it finds the jump insn at the end of the insn stream.

Fix the condition so that, instead of requiring the jump as the last
insn, it also matches a jump followed by debug insns.

This fixes the compilation of libgcc/libgcov-profiler.c with
-fcompare-debug on i686-linux-gnu.

Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?

for  gcc/ChangeLog

	* cfgexpand.c (expand_gimple_basic_block): Disregard debug
	insns after final jump in test to emit dummy move.
---
 gcc/cfgexpand.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Richard Sandiford Jan. 3, 2017, 2:08 p.m. UTC | #1
Alexandre Oliva <aoliva@redhat.com> writes:
> A debug insn after the final jump of a basic block may cause the
> expander to emit a dummy move where the non-debug compile won't
> because it finds the jump insn at the end of the insn stream.
>
> Fix the condition so that, instead of requiring the jump as the last
> insn, it also matches a jump followed by debug insns.
>
> This fixes the compilation of libgcc/libgcov-profiler.c with
> -fcompare-debug on i686-linux-gnu.
>
> Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?
>
> for  gcc/ChangeLog
>
> 	* cfgexpand.c (expand_gimple_basic_block): Disregard debug
> 	insns after final jump in test to emit dummy move.
> ---
>  gcc/cfgexpand.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
> index 97dc648..76bb614 100644
> --- a/gcc/cfgexpand.c
> +++ b/gcc/cfgexpand.c
> @@ -5767,7 +5767,9 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
>    if (single_succ_p (bb)
>        && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
>        && (last = get_last_insn ())
> -      && JUMP_P (last))
> +      && (JUMP_P (last)
> +	  || (DEBUG_INSN_P (last)
> +	      && JUMP_P (prev_nondebug_insn (last)))))

Would it be worth adding a get_last_nondebug_insn in case other patterns
like this crop up?

Thanks,
Richard
Alexandre Oliva Jan. 3, 2017, 8 p.m. UTC | #2
On Jan  3, 2017, Richard Sandiford <rdsandiford@googlemail.com> wrote:

>>        && (last = get_last_insn ())
>> -      && JUMP_P (last))
>> +      && (JUMP_P (last)
>> +	  || (DEBUG_INSN_P (last)
>> +	      && JUMP_P (prev_nondebug_insn (last)))))

> Would it be worth adding a get_last_nondebug_insn in case other patterns
> like this crop up?

I didn't think so.  Most of the RTL passes use the BB-based interfaces
nowadays, so it seemed that cfgexpand would be pretty much the only
place where this could be used.  That was my reasoning anyway; I didn't
actually check that this was indeed the case.
Richard Biener Jan. 4, 2017, 12:15 p.m. UTC | #3
On Tue, Jan 3, 2017 at 6:28 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
> A debug insn after the final jump of a basic block may cause the
> expander to emit a dummy move where the non-debug compile won't
> because it finds the jump insn at the end of the insn stream.
>
> Fix the condition so that, instead of requiring the jump as the last
> insn, it also matches a jump followed by debug insns.
>
> This fixes the compilation of libgcc/libgcov-profiler.c with
> -fcompare-debug on i686-linux-gnu.
>
> Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?

Ok.

RIchard.

> for  gcc/ChangeLog
>
>         * cfgexpand.c (expand_gimple_basic_block): Disregard debug
>         insns after final jump in test to emit dummy move.
> ---
>  gcc/cfgexpand.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
> index 97dc648..76bb614 100644
> --- a/gcc/cfgexpand.c
> +++ b/gcc/cfgexpand.c
> @@ -5767,7 +5767,9 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
>    if (single_succ_p (bb)
>        && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
>        && (last = get_last_insn ())
> -      && JUMP_P (last))
> +      && (JUMP_P (last)
> +         || (DEBUG_INSN_P (last)
> +             && JUMP_P (prev_nondebug_insn (last)))))
>      {
>        rtx dummy = gen_reg_rtx (SImode);
>        emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);
>
>
> --
> Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
> You must be the change you wish to see in the world. -- Gandhi
> Be Free! -- http://FSFLA.org/   FSF Latin America board member
> Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
diff mbox

Patch

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 97dc648..76bb614 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -5767,7 +5767,9 @@  expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
   if (single_succ_p (bb)
       && (single_succ_edge (bb)->flags & EDGE_FALLTHRU)
       && (last = get_last_insn ())
-      && JUMP_P (last))
+      && (JUMP_P (last)
+	  || (DEBUG_INSN_P (last)
+	      && JUMP_P (prev_nondebug_insn (last)))))
     {
       rtx dummy = gen_reg_rtx (SImode);
       emit_insn_after_noloc (gen_move_insn (dummy, dummy), last, NULL);