Bug 9279 - [3.2 regression] [ARM, Sparc] combine bug
Summary: [3.2 regression] [ARM, Sparc] combine bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: ---
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
: 8697 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-01-12 01:56 UTC by Matthias Klose
Modified: 2003-07-25 17:33 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2003-01-12 01:56:01 UTC
A regression to 2.95 / 3.0.4 on sparc-linux:

#include <stdio.h> 
 
int main () 
{ 
  FILE *s = fopen("foobar","w"); 
  char a[4] = { 0, 0, -1, 0 }; 
  printf ("%i\n", fwrite_unlocked (a, 1, 4, s)); 
} 
 
$ gcc-2.95 -O2 fbug.c && ./a.out 
4 
$ gcc-3.0 -O2 fbug.c && ./a.out 
4 
$ gcc-3.2 -O2 fbug.c && ./a.out 
2
$ gcc-3.2 -O1 fbug.c && ./a.out 
4
  
Or a simplified example from the fwrite_unlocked macro definition: 
 
int x = 0; 
 
int main () 
{ 
  char a[4] = { -1 }, *q = a; 
  int c; 
  for (c = 2; c > 0; --c) 
    if ((x ? 0 : (unsigned char) (*q = *a)) == -1) 
      break; 
  printf ("%i\n", c); 
} 

Thanks to Frank Heckbach for tracking this down.

Release:
3.2.1 / 3.2 branch

Environment:
sparc-linux, glibc-2.3.1 (-9 Debian release)
Comment 1 Eric Botcazou 2003-01-22 12:38:34 UTC
State-Changed-From-To: open->feedback
State-Changed-Why: Could you precise what the self-contained testcase ouputs when compiled with the different versions of gcc ?
Comment 2 Matthias Klose 2003-01-22 23:23:50 UTC
From: Matthias Klose <doko@cs.tu-berlin.de>
To: ebotcazou@gcc.gnu.org, frank@g-n-u.de, gcc-bugs@gcc.gnu.org,
        gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: optimization/9279: 3.2 regression to 2.95 / 3.0.4 on sparc-linux
Date: Wed, 22 Jan 2003 23:23:50 +0100

 ebotcazou@gcc.gnu.org writes:
 >     Could you precise what the self-contained testcase ouputs when compiled with the different versions of gcc ?
 
 the simplified (second) example:
 
 $ gcc-2.95 -O2 fbug2.c && ./a.out
 0
 
 $ gcc-3.0 -O2 fbug2.c && ./a.out
 0
 
 $ gcc-3.2 -O2 fbug2.c && ./a.out
 2
 
 $ gcc-3.2 -O1 fbug2.c && ./a.out
 0
Comment 3 Eric Botcazou 2003-01-23 19:44:08 UTC
State-Changed-From-To: feedback->analyzed
State-Changed-Why: Confirmed
Comment 4 Christian Ehrhardt 2003-01-24 11:57:26 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org, frank@g-n-u.de,
  nobody@gcc.gnu.org, gcc-prs@gcc.gnu.org, doko@debian.org
Cc:  
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Fri, 24 Jan 2003 11:57:26 +0100

 Hi,
 
 here's an even simpler example:
 
 
 int x = 0;
 char c, * p = &c, a = -1;
 int main ()
 {
 	if ((x?0:(unsigned char)((*p) = a)) == -1)
 		return 0;
 	return 1;
 }
 
 The exitcode of this program should always be 1 but it is zero if
 compiled with -O2.
 
 The problem is that these two insns
 
 (insn 24 23 25 (set (reg:SI 117)
         (zero_extend:SI (reg:QI 116))) 126 {*zero_extendqisi2_insn} (nil)
     (expr_list:REG_DEAD (reg:QI 116)
         (nil)))
 
 (insn 25 24 26 (set (reg:CC 100 %icc)
         (compare:CC (reg:SI 117)
             (const_int -1 [0xffffffffffffffff]))) 0 {*cmpsi_insn} (insn_list 24 (nil))
     (expr_list:REG_DEAD (reg:SI 117)
         (nil)))
 
 are combined into one like this:
 
 (note 24 23 25 NOTE_INSN_DELETED)
 
 (insn 25 24 26 (set (reg:CC 100 %icc)
         (compare:CC (subreg:SI (reg:QI 116) 0)
             (const_int 255 [0xff]))) 0 {*cmpsi_insn} (nil)
     (expr_list:REG_DEAD (reg:QI 116)
         (nil)))
 
    regards  Christian
 
Comment 5 Eric Botcazou 2003-01-24 16:26:59 UTC
Responsible-Changed-From-To: unassigned->ebotcazou
Responsible-Changed-Why: Evaluating a backport from mainline:
    http://gcc.gnu.org/ml/gcc-cvs/2002-07/msg00247.html
Comment 6 Eric Botcazou 2003-01-25 16:02:11 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/9279
Date: 25 Jan 2003 16:02:11 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	ebotcazou@gcc.gnu.org	2003-01-25 16:02:11
 
 Modified files:
 	gcc            : ChangeLog combine.c 
 	gcc/testsuite  : ChangeLog 
 Added files:
 	gcc/testsuite/gcc.c-torture/execute: 20030125-1.c 
 
 Log message:
 	PR optimization/9279
 	
 	Merge from mainline:
 	
 	2002-07-10  Roger Sayle  <roger@eyesopen.com>
 	
 	PR c/2454
 	* combine.c (nonzero_bits): LOAD_EXTEND_OP should only apply
 	to SUBREGs of MEMs.  (num_sign_bit_copies): Likewise.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.187&r2=1.13152.2.657.2.188
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.267.2.13.2.2&r2=1.267.2.13.2.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.82&r2=1.1672.2.166.2.83
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030125-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 
Comment 7 Eric Botcazou 2003-01-25 16:12:13 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed. See http://gcc.gnu.org/ml/gcc-patches/2003-01/msg01941.html
Comment 8 Eric Botcazou 2003-01-27 17:05:35 UTC
State-Changed-From-To: closed->open
State-Changed-Why: The fix introduces a performance regression for PowerPC (and possibly other platforms) on the 3.2 branch.
Comment 9 Eric Botcazou 2003-01-27 18:47:21 UTC
From: Eric Botcazou <ebotcazou@libertysurf.fr>
To: ebotcazou@gcc.gnu.org
Cc: doko@debian.org,
 frank@g-n-u.de,
 gcc-bugs@gcc.gnu.org,
 gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Mon, 27 Jan 2003 18:47:21 +0100

 >     The fix introduces a performance regression for PowerPC (and possibly
 > other platforms) on the 3.2 branch.
 
 Now reverted for this reason on the 3.2 branch so GCC 3.2.2 will ship with 
 the bug.
 
 -- 
 Eric Botcazou

Comment 10 Matthias Klose 2003-01-28 21:46:25 UTC
From: Matthias Klose <doko@cs.tu-berlin.de>
To: Eric Botcazou <ebotcazou@libertysurf.fr>
Cc: ebotcazou@gcc.gnu.org, frank@g-n-u.de, gcc-bugs@gcc.gnu.org,
        gcc-gnats@gcc.gnu.org, gdosreis@sophia.inria.fr
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Tue, 28 Jan 2003 21:46:25 +0100

 Eric Botcazou writes:
 > >     The fix introduces a performance regression for PowerPC (and possibly
 > > other platforms) on the 3.2 branch.
 > 
 > Now reverted for this reason on the 3.2 branch so GCC 3.2.2 will ship with 
 > the bug.
 
 I see you having the choice between two regressions, one performance
 regression (from 3.2.1 to 3.2.2) and one "wrong code" regression (from
 2.95 and 3.0.4 to 3.2.2). Not sure, if I should like your decision.
 
 	Matthias

Comment 11 gdosreis 2003-01-28 23:07:11 UTC
From: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
To: Matthias Klose <doko@cs.tu-berlin.de>
Cc: Eric Botcazou <ebotcazou@libertysurf.fr>, ebotcazou@gcc.gnu.org,
   frank@g-n-u.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Tue, 28 Jan 2003 23:07:11 +0100 (MET)

 | Eric Botcazou writes:
 | > >     The fix introduces a performance regression for PowerPC (and possibly
 | > > other platforms) on the 3.2 branch.
 | > 
 | > Now reverted for this reason on the 3.2 branch so GCC 3.2.2 will ship with 
 | > the bug.
 | 
 | I see you having the choice between two regressions, one performance
 | regression (from 3.2.1 to 3.2.2) and one "wrong code" regression (from
 | 2.95 and 3.0.4 to 3.2.2). Not sure, if I should like your decision.
 
 As I explained to Eric, I would have been pleased to apply that
 patch.  However it turned out that it introduces (1) a performance
 regression; (2) possibly a wrong code generation -- David gave some
 references.  Therefore, to fix the new regressions we would have to grab 
 other patches not known to be safe.  The initial patch was beginning
 to have too much ramifications.  That is why I asked Eric to revert
 his patch.  
 
 I would suggest that, right after 3.2.2 release, interested parties
 investigate the issue and submit a complete patch which we would
 have sufficient time to test.
 
 -- Gaby

Comment 12 Matthias Klose 2003-01-28 23:28:20 UTC
From: Matthias Klose <doko@cs.tu-berlin.de>
To: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
Cc: Eric Botcazou <ebotcazou@libertysurf.fr>, ebotcazou@gcc.gnu.org,
        frank@g-n-u.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Tue, 28 Jan 2003 23:28:20 +0100

 Gabriel Dos_Reis writes:
 > | Eric Botcazou writes:
 > | > >     The fix introduces a performance regression for PowerPC (and possibly
 > | > > other platforms) on the 3.2 branch.
 > | > 
 > | > Now reverted for this reason on the 3.2 branch so GCC 3.2.2 will ship with 
 > | > the bug.
 > | 
 > | I see you having the choice between two regressions, one performance
 > | regression (from 3.2.1 to 3.2.2) and one "wrong code" regression (from
 > | 2.95 and 3.0.4 to 3.2.2). Not sure, if I should like your decision.
 > 
 > As I explained to Eric, I would have been pleased to apply that
 > patch.  However it turned out that it introduces (1) a performance
 > regression; (2) possibly a wrong code generation -- David gave some
 > references.  Therefore, to fix the new regressions we would have to grab 
 > other patches not known to be safe.  The initial patch was beginning
 > to have too much ramifications.  That is why I asked Eric to revert
 > his patch.
 
 Thanks for the clarification, I did miss this information on the gnats
 report.

Comment 13 Eric Botcazou 2003-01-29 00:30:29 UTC
From: Eric Botcazou <ebotcazou@libertysurf.fr>
To: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
Cc: Matthias Klose <doko@cs.tu-berlin.de>,
 frank@g-n-u.de,
 gcc-bugs@gcc.gnu.org,
 gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Wed, 29 Jan 2003 00:30:29 +0100

 > As I explained to Eric, I would have been pleased to apply that
 > patch.  However it turned out that it introduces (1) a performance
 > regression; (2) possibly a wrong code generation -- David gave some
 > references.
 
 Note that, as I said to David, I'm very skeptical about (2) for the patch 
 _alone_ because it simply pessimizes (however rightfully, they are just 
 plain wrong in the general case) the values returned by two predicate 
 functions:
 
 
 /* Given an expression, X, compute which bits in X can be non-zero.
    We don't care about bits outside of those defined in MODE.
 
    For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
    a shift, AND, or zero_extract, we can do better.  */
 
 static unsigned HOST_WIDE_INT
 nonzero_bits (x, mode)
 
 /* Return the number of bits at the high-order end of X that are known to
    be equal to the sign bit.  X will be used in mode MODE; if MODE is
    VOIDmode, X will be used in its own mode.  The returned value  will always
    be between 1 and the number of bits in MODE.  */
 
 static unsigned int
 num_sign_bit_copies (x, mode)
 
 
 > Therefore, to fix the new regressions we would have to grab
 > other patches not known to be safe.  The initial patch was beginning
 > to have too much ramifications.
 
 I can't disagree here.
 
 > I would suggest that, right after 3.2.2 release, interested parties
 > investigate the issue and submit a complete patch which we would
 > have sufficient time to test.
 
 I'm not very optimistic about this happening. I guess most of the developer
 resources will be focused on the 3.3 branch instead.
 
 -- 
 Eric Botcazou

Comment 14 Christian Ehrhardt 2003-01-29 00:59:56 UTC
From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
Cc: Matthias Klose <doko@cs.tu-berlin.de>,
  Eric Botcazou <ebotcazou@libertysurf.fr>, ebotcazou@gcc.gnu.org,
  frank@g-n-u.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Wed, 29 Jan 2003 00:59:56 +0100

 On Tue, Jan 28, 2003 at 11:07:11PM +0100, Gabriel Dos_Reis wrote:
 > As I explained to Eric, I would have been pleased to apply that
 > patch.  However it turned out that it introduces (1) a performance
 > regression;
 
 I think we all agree that a (slight) performance regression is an 
 improvement compared to silent bad code generation.
 
 > (2) possibly a wrong code generation -- David gave some
 > references.
 
 I must have missed this discussion, Could you give me a pointer?
 
    regards  Christian
 
 -- 
 THAT'S ALL FOLKS!

Comment 15 gdosreis 2003-01-29 02:25:50 UTC
From: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
To: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
Cc: Matthias Klose <doko@cs.tu-berlin.de>,
   Eric Botcazou <ebotcazou@libertysurf.fr>, ebotcazou@gcc.gnu.org,
   frank@g-n-u.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Wed, 29 Jan 2003 02:25:50 +0100 (MET)

 | > (2) possibly a wrong code generation -- David gave some
 | > references.
 | 
 | I must have missed this discussion, Could you give me a pointer?
 
 Sorry, that is part of e-mail exhancge I had with Eric Dadid
 yesterday.   Quoting him:
 
 	  This patch and the necessary PowerPC patch exposed other bugs in
   the compiler regarding REG_EQUAL notes in loop unrolling:
 
   2002-10-04  David Edelsohn  <edelsohn@gnu.org>
 
 	  * unroll.c (copy_loop_body): Remove REG_EQUAL note attached to
 	  copied instruction if the note is not loop invariant.
 
   The patches may have other co-dependencies we do not know about.
 
 Eric agreed with him.
 
 I would like to avoid last time minute patch chasing.
 
 -- Gaby

Comment 16 gdosreis 2003-01-29 02:29:15 UTC
From: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>
To: Eric Botcazou <ebotcazou@libertysurf.fr>
Cc: Matthias Klose <doko@cs.tu-berlin.de>, frank@g-n-u.de,
   gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc] combine bug
Date: Wed, 29 Jan 2003 02:29:15 +0100 (MET)

 | > As I explained to Eric, I would have been pleased to apply that
 | > patch.  However it turned out that it introduces (1) a performance
 | > regression; (2) possibly a wrong code generation -- David gave some
 | > references.
 | 
 | Note that, as I said to David, I'm very skeptical about (2) for the patch 
 | _alone_ because it simply pessimizes (however rightfully, they are just 
 | plain wrong in the general case) the values returned by two predicate 
 | functions:
 
 Sorry, I mistranslated your agreement on David's statement:
 
   >       This patch and the necessary PowerPC patch exposed other bugs in
   > the compiler regarding REG_EQUAL notes in loop unrolling:
   >
   > 2002-10-04  David Edelsohn  <edelsohn@gnu.org>
   >
   >         * unroll.c (copy_loop_body): Remove REG_EQUAL note attached to
   >         copied instruction if the note is not loop invariant.
   >
   > The patches may have other co-dependencies we do not know about.
 
   Ok.
 
 [...]
 
 | > I would suggest that, right after 3.2.2 release, interested parties
 | > investigate the issue and submit a complete patch which we would
 | > have sufficient time to test.
 | 
 | I'm not very optimistic about this happening. I guess most of the developer
 | resources will be focused on the 3.3 branch instead.
 
 Well, that is just a suggestion.  I hope 3.3 will be ready in time so 
 that 3.2-branch becomes obselete.
 
 -- Gaby
Comment 17 Eric Botcazou 2003-02-16 15:00:37 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: The problem is clearly identified.
Comment 18 Matthias Klose 2003-02-22 17:31:55 UTC
From: Matthias Klose <doko@cs.tu-berlin.de>
To: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>,
        Eric Botcazou <ebotcazou@libertysurf.fr>
Cc: frank@g-n-u.de, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc & ARM] combine bug
Date: Sat, 22 Feb 2003 17:31:55 +0100

 With today's gcc-3_2-branch I see this on arm-linux as well. I
 couldn't check with 3.3 yet.
 
 	Matthias
 

Comment 19 Eric Botcazou 2003-02-22 17:49:11 UTC
From: Eric Botcazou <ebotcazou@libertysurf.fr>
To: Matthias Klose <doko@cs.tu-berlin.de>
Cc: Gabriel Dos_Reis <gdosreis@sophia.inria.fr>,
 frank@g-n-u.de,
 gcc-bugs@gcc.gnu.org,
 gcc-gnats@gcc.gnu.org
Subject: Re: optimization/9279: [3.2 regression] [Sparc & ARM] combine bug
Date: Sat, 22 Feb 2003 17:49:11 +0100

 > With today's gcc-3_2-branch I see this on arm-linux as well. I
 > couldn't check with 3.3 yet.
 
 The list is actually longer: Sparc, Arm, HP-PA, IA-64, ...
 
 The bug is fixed on the 3.3 branch and the mainline.
 
 -- 
 Eric Botcazou
Comment 20 Eric Botcazou 2003-03-30 13:28:19 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: We definitely won't fix it on the 3.2 branch.