Bug 47881 - [4.6 Regression] -fcompare-debug failure (length) with -O -fno-dce -funroll-loops -fno-web
Summary: [4.6 Regression] -fcompare-debug failure (length) with -O -fno-dce -funroll-l...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.6.0
: P2 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords: compare-debug-failure
Depends on:
Blocks: 47919
  Show dependency treegraph
 
Reported: 2011-02-24 13:17 UTC by Zdenek Sojka
Modified: 2022-01-18 23:30 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail: 4.6.0
Last reconfirmed: 2011-03-06 13:55:09


Attachments
reduced testcase (186 bytes, text/plain)
2011-02-24 13:17 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2011-02-24 13:17:48 UTC
Created attachment 23452 [details]
reduced testcase

Compiler output:
$ gcc -O -fcompare-debug -fno-dce -funroll-loops -fno-web testcase.c -m32
gcc: error: testcase.c: -fcompare-debug failure (length)

$ diff testcase.*gkd
943c943
< (insn# 0 0 39 (set (reg:SI 4 si)
---
> (insn# 0 0 39 (set (reg:SI 5 di)
947,948c947,948
<             (set (reg:SI 4 si)
<                 (plus:SI (reg:SI 4 si)
---
>             (set (reg:SI 5 di)
>                 (plus:SI (reg:SI 5 di)
...

Tested revisions:
r170450 - fail
4.5 r170013 - OK
4.5.2 - OK
Comment 1 Jakub Jelinek 2011-03-07 10:12:04 UTC
While this started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167390,
it looks just as it uncovered a latent IRA bug.
My guess is that the differences are related to ira-emit.c (change_loop) creating
some new pseudos, whose live ranges then don't ignore debug insns (normally debug insns would be changed or reset to avoid different lr ranges caused by debug insns, but probably as this happens still within IRA it won't be adjusted).
Comment 2 Jakub Jelinek 2011-03-07 11:32:53 UTC
Problems start when the combiner leaves in a trivially dead insn by substing it later on in some subsequent insn.  Nothing until IRA calls delete_trivially_dead_insns, and when IRA calls it, it removes that insn, which effectively shortens the lifetime of one of the pseudos.  Unfortunately that psuedo is set multiple times (probably -funroll-loops is the reason), so delete_trivially_dead_insns isn't trying to reset or change related debug insns, it doesn't have enough infrastructure to do so.  Normally DF would then reset them, but DF isn't recomputed until IRA finishes.
Comment 3 Jakub Jelinek 2011-03-07 11:41:17 UTC
--- gcc/ira.c.jj	2011-02-21 15:37:42.000000000 +0100
+++ gcc/ira.c	2011-03-07 12:33:59.000000000 +0100
@@ -3232,7 +3232,8 @@ ira (FILE *f)
     check_allocation ();
 #endif
 
-  delete_trivially_dead_insns (get_insns (), max_reg_num ());
+  if (delete_trivially_dead_insns (get_insns (), max_reg_num ()))
+    df_analyze ();
 
   init_reg_equiv_memory_loc ();
 
indeed fixes this testcase, haven't tried to bootstrap/regtest it nor have any idea whether some IRA bookkeeping will need to be updated in that case.
Comment 4 Jakub Jelinek 2011-03-08 15:51:18 UTC
Author: jakub
Date: Tue Mar  8 15:51:12 2011
New Revision: 170780

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170780
Log:
	PR debug/47881
	* ira.c (ira): Call df_analyze again if delete_trivially_dead_insns
	removed anything.

	* gcc.dg/pr47881.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr47881.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/ira.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2011-03-08 15:54:57 UTC
Fixed.