Bug 44921 - [4.6 Regression] Failed to bootstrap
Summary: [4.6 Regression] Failed to bootstrap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 18:37 UTC by H.J. Lu
Modified: 2010-07-23 12:37 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-07-12 22:44:40


Attachments
The test case (131.62 KB, application/octet-stream)
2010-07-13 09:51 UTC, Jie Zhang
Details
The reduced test case (5.20 KB, text/plain)
2010-07-13 16:20 UTC, Jie Zhang
Details
The reduced test case (5.23 KB, text/plain)
2010-07-13 16:40 UTC, Jie Zhang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-07-12 18:37:48 UTC
On Linux/ia32, revision 162085 gave:

../../src-trunk/gcc/postreload.c: In function 'reload_cse_regs':
../../src-trunk/gcc/postreload.c:1327:57: error: 'min_regno' may be used uninitialized in this function [-Werror=uninitialized]
../../src-trunk/gcc/postreload.c:1284:7: note: 'min_regno' was declared here
cc1: all warnings being treated as errors

It may be caused by revision 162085:

http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg00439.html
Comment 1 H.J. Lu 2010-07-12 18:46:33 UTC
This patch:

Index: postreload.c
===================================================================
--- postreload.c	(revision 162085)
+++ postreload.c	(working copy)
@@ -1281,7 +1281,7 @@ move2add_use_add3_insn (rtx reg, rtx sym
   rtx src = SET_SRC (pat);
   int regno = REGNO (reg);
   int min_cost = INT_MAX;
-  int min_regno;
+  int min_regno = -1;
   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
   int i;
 
@@ -1317,7 +1317,7 @@ move2add_use_add3_insn (rtx reg, rtx sym
 	  }
       }
 
-  if (min_cost < rtx_cost (src, SET, speed))
+  if (min_regno >= 0 && min_cost < rtx_cost (src, SET, speed))
     {
       rtx tem;
 
works for me.
Comment 2 Jorn Wolfgang Rennecke 2010-07-12 22:54:22 UTC
(In reply to comment #1)
> This patch:
> 
> Index: postreload.c
> ===================================================================
> --- postreload.c        (revision 162085)
> +++ postreload.c        (working copy)
> @@ -1281,7 +1281,7 @@ move2add_use_add3_insn (rtx reg, rtx sym
>    rtx src = SET_SRC (pat);
>    int regno = REGNO (reg);
>    int min_cost = INT_MAX;
> -  int min_regno;
> +  int min_regno = -1;
>    bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
>    int i;
> 
> @@ -1317,7 +1317,7 @@ move2add_use_add3_insn (rtx reg, rtx sym
>           }
>        }
> 
> -  if (min_cost < rtx_cost (src, SET, speed))
> +  if (min_regno >= 0 && min_cost < rtx_cost (src, SET, speed))
>      {
>        rtx tem;
> 
> works for me.

The variable can not actually be used uninitalized, since min_cost is
initalized to INT_MAX, and the return type of rtx_cost is int.
So it is enough to shut up the compiler warning, no need to add an
extra test there.  I.e. the first hunk should be sufficient.
Comment 3 H.J. Lu 2010-07-12 23:33:19 UTC
(In reply to comment #2)
> The variable can not actually be used uninitalized, since min_cost is
> initalized to INT_MAX, and the return type of rtx_cost is int.
> So it is enough to shut up the compiler warning, no need to add an
> extra test there.  I.e. the first hunk should be sufficient.
> 

Does the first chunk count as obvious?
Comment 4 H.J. Lu 2010-07-12 23:34:11 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > The variable can not actually be used uninitalized, since min_cost is
> > initalized to INT_MAX, and the return type of rtx_cost is int.
> > So it is enough to shut up the compiler warning, no need to add an
> > extra test there.  I.e. the first hunk should be sufficient.
> > 
> 
> Does the first chunk count as obvious?

Maybe

int min_regno = 0;

is faster.
 

Comment 5 Jorn Wolfgang Rennecke 2010-07-12 23:45:02 UTC
(In reply to comment #3)
> Does the first chunk count as obvious?

I'd say yes.

My boostraps using that hunk with and without --enable-build-with-cxx on i686-pc-linux-gnu
have progressed past the stage2/stage3 comparison.

(In reply to comment #4)

> int min_regno = 0;
> 
> is faster.

Yes, it's a cheaper constant on a number of processors in term of
size and speed.

If we really care about compiler run-time efficiency here (and efficiency
for programs that use the same warning regime), we should introduce an
attribute to tell the compiler to treat a variable as initialized even if
it isn't, so that attribute can be used in these cases of the variable
always being assigned before used even if no proof exists inside the rule
system of the compiler.
Comment 6 hjl@gcc.gnu.org 2010-07-13 00:52:07 UTC
Subject: Bug 44921

Author: hjl
Date: Tue Jul 13 00:51:43 2010
New Revision: 162120

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162120
Log:
Silence gcc warning on min_regno.

2010-07-12  H.J. Lu  <hongjiu.lu@intel.com>

	PR bootstrap/44921
	* postreload.c (move2add_use_add3_insn): Silence gcc warning
	on min_regno.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/postreload.c

Comment 7 amylaar@spamcop.net 2010-07-13 01:55:05 UTC
Subject: Re:  [4.6 Regression] Failed to bootstrap

Quoting hjl dot tools at gmail dot com <gcc-bugzilla@gcc.gnu.org>:
> Maybe
>
> int min_regno = 0;
>
> is faster.

Considering performance, your first patch was better - it avoids a call to
rtx_cost when no optimization can be performed.  OTOH with the expensive
loop through all hard registers that's in the noise.
Or compared to the cycles wasted on failed bootstraps or this discussion ;-)
Comment 8 Jie Zhang 2010-07-13 09:51:11 UTC
Created attachment 21189 [details]
The test case

The test case
Comment 9 Jie Zhang 2010-07-13 09:52:32 UTC
I think this one caused it:

http://gcc.gnu.org/ml/gcc-patches/2010-06/msg03103.html

The test case is attached.

$ ./cc1 -O2 -Wall testcase.i -quiet
testcase.i: In function 'reload_cse_regs':
testcase.i:18129:64: warning: 'min_regno' may be used uninitialized in this function [-Wuninitialized]
testcase.i:18095:7: note: 'min_regno' was declared here
Comment 10 Jie Zhang 2010-07-13 16:20:01 UTC
Created attachment 21191 [details]
The reduced test case
Comment 11 Jie Zhang 2010-07-13 16:40:05 UTC
Created attachment 21192 [details]
The reduced test case
Comment 12 Richard Biener 2010-07-23 12:37:07 UTC
This bug is no longer about bootstrap failure.  Which is fixed.