Bug 56023 - [4.6 Regression]: [alpha] -fcompare-debug failure due to sched1 pass
Summary: [4.6 Regression]: [alpha] -fcompare-debug failure due to sched1 pass
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.6.4
: P3 normal
Target Milestone: 4.6.4
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on: 48403
Blocks:
  Show dependency treegraph
 
Reported: 2013-01-17 22:02 UTC by Uroš Bizjak
Modified: 2013-01-21 18:09 UTC (History)
4 users (show)

See Also:
Host: x86_64-linux-gnu
Target: alpha-linux-gnu
Build:
Known to work: 4.7.3
Known to fail:
Last reconfirmed: 2013-01-17 00:00:00


Attachments
Preprocessed source of the file that miscompares during bootstrap (86.73 KB, text/plain)
2013-01-17 22:08 UTC, Uroš Bizjak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2013-01-17 22:02:54 UTC
Following compare-debug failure breaks bootstrap on alpha-linux-gnu on 4.6:

--cut here--
void
foo (char *c)
{
  unsigned int x = 0;
  unsigned int i;

  for (i = 0; c[i]; i++)
    {
      if (i >= 5 && x != 1)
	break;
      else if (c[i] == ' ')
	x = i;
      else if (c[i] == '/' && c[i + 1] != ' ' && i)
	x = i + 1;
    }
}
--cut here--

The compare-debug failure can be reproduced on a cross to alpha-linux-gnu:

~/gcc-build-alpha/gcc/xgcc -B ~/gcc-build-alpha/gcc -O2 -fcompare-debug -S t.c
xgcc: error: t.c: -fcompare-debug failure

~/gcc-build-alpha/gcc/xgcc -v
Using built-in specs.
COLLECT_GCC=/home/uros/gcc-build-alpha/gcc/xgcc
Target: alpha-linux-gnu
Configured with: ../gcc-svn/branches/gcc-4_6-branch/configure --target=alpha-linux-gnu
Thread model: posix
gcc version 4.6.4 20130117 (prerelease) [gcc-4_6-branch revision 195276] (GCC)

The resulting assembly differs in:

--with g--
$L8:
$LM8:
	cmpeq $5,1,$5	 # 30	*setcc_internal	[length = 4]
	cmpult $8,$2,$2	 # 35	*setcc_internal	[length = 4]
	cmpeq $5,0,$5	 # 31	*setcc_internal	[length = 4]
(*)	addl $3,1,$3	 # 43	*addsi_se/1	[length = 4]
	and $5,$2,$2	 # 39	anddi3/1	[length = 4]
	cpys $f31,$f31,$f31	 # 171	fnop	[length = 4]
(**)	addl $4,1,$4	 # 41	*addsi_se/1	[length = 4]
	bne $2,$L1	 # 44	*bcc_normal	[length = 4]
$L9:
--/with g--

--without g--
$L8:
	cmpeq $5,1,$5	 # 26	*setcc_internal	[length = 4]
	cmpult $8,$2,$2	 # 31	*setcc_internal	[length = 4]
	cmpeq $5,0,$5	 # 27	*setcc_internal	[length = 4]
(**)	addl $4,1,$4	 # 37	*addsi_se/1	[length = 4]
	and $5,$2,$2	 # 35	anddi3/1	[length = 4]
	cpys $f31,$f31,$f31	 # 143	fnop	[length = 4]
(*)	addl $3,1,$3	 # 39	*addsi_se/1	[length = 4]
	bne $2,$L1	 # 40	*bcc_normal	[length = 4]
$L9:
--/without g--

Insns (*) and (**) switched places when compiled w/ or w/o "-g".

The problem is in sched1 pass, where the first difference occurs, and adding -fno-schedule-insns to compile flags avoids the failure.
Comment 1 Uroš Bizjak 2013-01-17 22:08:50 UTC
Created attachment 29197 [details]
Preprocessed source of the file that miscompares during bootstrap

This is the preprocessed source of the file that miscompares during bootstrap.

~/gcc-build-alpha/gcc/xgcc -B ~/gcc-build-alpha/gcc -O2 -fcompare-debug -S opts.i
xgcc: error: opts.i: -fcompare-debug failure
Comment 2 Uroš Bizjak 2013-01-17 23:00:38 UTC
Confirm bug and add CC.
Comment 3 Richard Biener 2013-01-18 10:18:51 UTC
Can you fill out known-to-work?  Especially whether 4.7.x works and whether
4.6.3 worked?
Comment 4 Uroš Bizjak 2013-01-18 17:04:39 UTC
4.7.3 [1] bootstraps OK, also passes -fcompare-debug test.

[1] gcc version 4.7.3 20130118 (prerelease) [gcc-4_7-branch revision 195292]
Comment 5 Uroš Bizjak 2013-01-18 17:38:23 UTC
Bookkeeping seems somehow broken to me in sched1 pass:

-O2 -fcompare-debug -fdump-rtl-sched1-slim -S:

_.c.190r.sched1:

;;   ======================================================
;;   -- basic block 5 from 48 to 49 -- before reload
;;   ======================================================

changing bb of uid 64
  from 8 to 5
;;	  0-->    64 r137=zxn(r76#0)
;;	  1-->    48 r111=r90==0x20
changing bb of uid 65
  from 8 to 5
;;	  2-->    65 r119=r95+r137
;;	  2-->    49 pc={(r111==0)?L59:pc}
;;	Ready list (final):  
;;   total time = 2
;;   new head = 48
;;   new tail = 49

New head is 64, *not* 48.

And here comes the difference:

_.c.190r.sched1:

;;   ======================================================
;;   -- basic block 10 from 94 to 94 -- before reload
;;   ======================================================

changing bb of uid 25
  from 4 to 10
;;	  1-->    25 r100=zxn(r75#0)
;;	  1-->    94 pc={(r90!=0)?L93:pc}
;;	Ready list (final):    39/b6:18  37/b6:17
;;   total time = 1
;;   new head = 94
;;   new tail = 94

Again wrong head w/o -g.

_.c.gk.190r.sched1

;;   ======================================================
;;   -- basic block 10 from 99 to 102 -- before reload
;;   ======================================================

;;	  0-->    99: debug i => r76#0
;;	  0-->   100: debug x => r75#0
changing bb of uid 29
  from 4 to 10
;;	  1-->    29 r100=zxn(r75#0)
;;	  1-->   102 pc={(r90!=0)?L101:pc} 
;;	Ready list (final):    43/b6:20  41/b6:19
;;   total time = 1
;;   new head = 99
;;   new tail = 102

Here we account debug instructions as head. I suspect that this is the cause of the difference in a follow-up block, where we schedule in a different ways:

_.c.190r.sched1:

;;   ======================================================
;;   -- basic block 4 from 26 to 40 -- before reload
;;   ======================================================

;;	  1-->    26 r102=r100==0x1
;;	  2-->    31 r105=ltu(r138,r137)
;;	  3-->    27 r101=r102==0
;;	  4-->    37 r92=sxn(r92#0+0x1)
;;	  5-->    35 r79=r101&r105
;;	  6-->    39 r76=sxn(r76#0+0x1)
;;	  6-->    40 pc={(r79!=0)?L97:pc}

_.c.gk.190r.sched1

;;   ======================================================
;;   -- basic block 4 from 30 to 44 -- before reload
;;   ======================================================

;;	  0-->    43 r76=sxn(r76#0+0x1)
;;	  1-->    30 r102=r100==0x1
;;	  2-->    35 r105=ltu(r138,r137)
;;	  3-->    31 r101=r102==0
;;	  4-->    41 r92=sxn(r92#0+0x1)
;;	  5-->    39 r79=r101&r105
;;	  6-->    44 pc={(r79!=0)?L105:pc}

In the later dump, (insn 43) was scheduled above all others.
Comment 6 Uroš Bizjak 2013-01-18 17:49:33 UTC
(In reply to comment #5)
> Bookkeeping seems somehow broken to me in sched1 pass:

*IF* this is problematic, then 4.7+ releases have the same problem.
Comment 7 Uroš Bizjak 2013-01-19 10:06:06 UTC
Similar to (or the same as) PR 48403.
Comment 8 Uroš Bizjak 2013-01-19 10:17:43 UTC
The scheduler passes block boundary here and schedules insns from the next block. This is the difference to the compilation w/o -g and to gcc-4_7 branch.

;;   ======================================================
;;   -- basic block 10 from 99 to 102 -- before reload
;;   ======================================================

;;   --------------- forward dependences: ------------ 

;;   --- Region Dependences --- b 10 bb 5 
;;      insn  code    bb   dep  prio  cost   reservation
;;      ----  ----    --   ---  ----  ----   -----------
;;       99    -1    10     0     0     0   nothing	: 43 100 
;;      100    -1    10     1     0     0   nothing	: 
;;      102   184    10     0     2     2   (ev4_ib1+ev4_bbox),ev4_bbox	: 44 


;;   --- Region Dependences --- b 4 bb 6 
;;      insn  code    bb   dep  prio  cost   reservation
;;      ----  ----    --   ---  ----  ----   -----------
;;       29    52     4     0     9     2   (ev4_ib0+ev4_ebox)	: 44 30 
;;       30   159     4     1     7     2   (ev4_ib0+ev4_ebox)	: 44 31 
;;       31   159     4     1     5     2   (ev4_ib0+ev4_ebox)	: 44 39 
;;       35   159     4     0     5     2   (ev4_ib0+ev4_ebox)	: 44 39 
;;       37 NOTE_INSN_DELETED
;;       38 NOTE_INSN_DELETED
;;       39    41     4     2     3     2   (ev4_ib0+ev4_ebox)	: 44 
;;       40 NOTE_INSN_DELETED
;;       41     3     4     0     2     2   (ev4_ib0+ev4_ebox)	: 44 
;;       42 NOTE_INSN_DELETED
;;       43     3     4     0     2     2   (ev4_ib0+ev4_ebox)	: 44 
;;       44   184     4     8     2     2   (ev4_ib1+ev4_bbox),ev4_bbox	: 

;;		dependencies resolved: insn 99
;;		tick updated: insn 99 into ready
;;		dependencies resolved: insn 102
;;		Ready-->Q: insn 102: queued for 2 cycles.
;;		tick updated: insn 102 into queue with cost=2
;;		dependencies resolved: insn 29/b6
;;		Ready-->Q: insn 29/b6: queued for 2 cycles.
;;		tick updated: insn 29/b6 into queue with cost=2
;;		dependencies resolved: insn 35/b6
;;		Ready-->Q: insn 35/b6: queued for 2 cycles.
;;		tick updated: insn 35/b6 into queue with cost=2
;;		dependencies resolved: insn 41/b6
;;		Ready-->Q: insn 41/b6: queued for 2 cycles.
;;		tick updated: insn 41/b6 into queue with cost=2
;;		dependencies resolved: insn 43/b6
;;		Ready-->Q: insn 43/b6: queued for 2 cycles.
;;		tick updated: insn 43/b6 into queue with cost=2
;;	Advanced a state.
;;      ...
Comment 9 Uroš Bizjak 2013-01-19 19:46:12 UTC
Following patch fixes bootstrap comparison failure:

--cut here--
Index: haifa-sched.c
===================================================================
--- haifa-sched.c       (revision 195276)
+++ haifa-sched.c       (working copy)
@@ -3684,6 +3684,9 @@ fix_inter_tick (rtx head, rtx tail)
              INSN_TICK (head) = tick;
            }
 
+         if (DEBUG_INSN_P (head))
+           continue;
+
          FOR_EACH_DEP (head, SD_LIST_RES_FORW, sd_it, dep)
            {
              rtx next;
--cut here--

We should not update tick status of instructions, dependent on debug insn.
Comment 10 Uroš Bizjak 2013-01-19 21:07:06 UTC
Patch at [1].

[1] http://gcc.gnu.org/ml/gcc-patches/2013-01/msg01011.html
Comment 11 uros 2013-01-21 17:51:38 UTC
Author: uros
Date: Mon Jan 21 17:51:23 2013
New Revision: 195342

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195342
Log:
	PR rtl-optimization/56023
	* haifa-sched.c (fix_inter_tick): Do not update ticks of instructions,
	dependent on debug instruction.

testsuite/ChangeLog:

	PR rtl-optimization/56023
	* gcc.dg/pr56023.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/pr56023.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/haifa-sched.c
    trunk/gcc/testsuite/ChangeLog
Comment 12 uros 2013-01-21 17:59:34 UTC
Author: uros
Date: Mon Jan 21 17:59:28 2013
New Revision: 195344

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195344
Log:
	PR rtl-optimization/56023
	* haifa-sched.c (fix_inter_tick): Do not update ticks of instructions,
	dependent on debug instruction.

testsuite/ChangeLog:

	PR rtl-optimization/56023
	* gcc.dg/pr56023.c: New test.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/pr56023.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/haifa-sched.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 13 uros 2013-01-21 18:03:07 UTC
Author: uros
Date: Mon Jan 21 18:02:57 2013
New Revision: 195345

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195345
Log:
	PR rtl-optimization/56023
	* haifa-sched.c (fix_inter_tick): Do not update ticks of instructions,
	dependent on debug instruction.

testsuite/ChangeLog:

	PR rtl-optimization/56023
	* gcc.dg/pr56023.c: New test.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/pr56023.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/haifa-sched.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 14 Uroš Bizjak 2013-01-21 18:09:31 UTC
Fixed everywhere.