Bug 41340 - [4.5 Regression] GCC produces different code with and without -g option
Summary: [4.5 Regression] GCC produces different code with and without -g option
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.5.0
: P2 normal
Target Milestone: 4.5.0
Assignee: Jakub Jelinek
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2009-09-11 21:33 UTC by Dmitry Gorbachev
Modified: 2009-10-23 09:15 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-10-19 17:14:34


Attachments
gzipped preprocessed source file (63.69 KB, application/x-gzip)
2009-09-11 21:33 UTC, Dmitry Gorbachev
Details
gzipped preprocessed source file (159.43 KB, application/x-gzip)
2009-10-16 20:12 UTC, Dmitry Gorbachev
Details
gcc45-pr41340.patch (851 bytes, patch)
2009-10-20 09:39 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2009-09-11 21:33:04 UTC
GCC 4.5.0 20090903, 20090910: bootstrap with `--enable-build-with-cxx' failed.

cc1plus -O2 -g rtl.ii
Comment 1 Dmitry Gorbachev 2009-09-11 21:33:29 UTC
Created attachment 18567 [details]
gzipped preprocessed source file
Comment 2 Dave Korn 2009-09-19 09:20:20 UTC
Unsurprisingly, adding -g0 to the build line results in an expr.o without the undefined reference.

/gnu/gcc/obj.no.pr41357/./prev-gcc/xgcc -B/gnu/gcc/obj.no.pr41357/./prev-gcc/ -B/opt/gcc-tools/i686-pc-cygwin/bin/ -B/opt/gcc-tools/i686-pc-cygwin/bin/ -B/opt/gcc-tools/i686-pc-cygwin/lib/ -isystem /opt/gcc-tools/i686-pc-cygwin/include -isystem /opt/gcc-tools/i686-pc-cygwin/sys-include    -c  -g -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -Wold-style-definition -Wc++-compat -fno-common  -DHAVE_CONFIG_H -I ../gcc -Ijava -I/gnu/gcc/gcc-unpatched/gcc -I/gnu/gcc/gcc-unpatched/gcc/java -I/gnu/gcc/gcc-unpatched/gcc/../include -I/gnu/gcc/gcc-unpatched/gcc/../libcpp/include -I/usr/include -I/usr/include -I/gnu/gcc/gcc-unpatched/gcc/../libdecnumber -I/gnu/gcc/gcc-unpatched/gcc/../libdecnumber/dpd -I../libdecnumber    /gnu/gcc/gcc-unpatched/gcc/java/expr.c -o java/expr.o --save-temps -g0
Comment 3 Dave Korn 2009-09-19 09:21:21 UTC
(In reply to comment #2)
> Unsurprisingly, 

Oops, sorry, wrong PR!  I was on the wrong browser tab.  Apologies.
Comment 4 Alexandre Oliva 2009-10-15 18:17:00 UTC
Is this just because of the use of random number generators to name symbols with internal linkage, or is there some actual difference that -fcompare-debug detects?  (-fcompare-debug uses -frandom-seed to avoid the differences).
Comment 5 Dmitry Gorbachev 2009-10-16 20:09:53 UTC
There is a real difference, i.e.

- 179:  mov    0x8(%ebp),%edx
- 17c:  movzwl (%edx),%eax
+ 179:  mov    0x8(%ebp),%esi
+ 17c:  movzwl (%esi),%eax

[...]

- 1a0:  mov    %edx,(%esp)
- 1a3:  mov    %edx,-0x24(%ebp)
- 1a6:  call   1a7 <_Z8copy_rtxP7rtx_def+0x37>
- 1ab:  mov    %eax,%ecx
- 1ad:  movzbl 0x3(%eax),%eax
- 1b1:  mov    %eax,%esi
- 1b3:  and    $0xffffffdf,%eax

[...]

+ 1a0:  mov    %esi,(%esp)
+ 1a3:  call   1a4 <_Z8copy_rtxP7rtx_def+0x34>
+ 1a8:  mov    %eax,%edi
+ 1aa:  movzbl 0x3(%eax),%eax
+ 1ae:  mov    %eax,%ecx
+ 1b0:  and    $0xffffffdf,%eax
+ 1b3:  mov    %al,0x3(%edi)

etc.

-fcompare-debug produces  -fcompare-debug failure (length)
Comment 6 Dmitry Gorbachev 2009-10-16 20:12:02 UTC
Created attachment 18813 [details]
gzipped preprocessed source file

Another case. Compile with:

cc1 -O3 -march=i686 -g tree-eh.i


-    2fb6:      sub    $0xdc,%esp
+    2fb6:      sub    $0xcc,%esp

[...]

-    38f2:      mov    $0x1,%edi
-    38f7:      movb   $0x0,-0x98(%ebp)
-    38fe:      mov    %edx,-0x9c(%ebp)
-    3904:      cmp    %eax,(%ecx)
-    3906:      jne    3ad9 <execute_cleanup_eh+0xb29>

[...]

+    38f2:      xor    %edi,%edi
+    38f4:      cmp    %eax,(%ecx)
+    38f6:      jne    3ac3 <execute_cleanup_eh+0xb13>
+    38fc:      mov    0x0,%eax
+    3901:      xor    %esi,%esi
Comment 7 Jakub Jelinek 2009-10-19 17:05:02 UTC
Confirmed, for -m32 -march=i686 -O3 -g vs. -g0 generates different code on:
typedef struct { int t; } *T;
struct S1 { unsigned s1; };
struct S2 { struct S1 s2; };
struct S3 { unsigned s3; struct S2 **s4; };
struct S5 { struct S2 *s5; };

extern void fn0 (void) __attribute__ ((__noreturn__));
T fn6 (struct S3);
void fn7 (void);

int
fn1 (const struct S1 *x)
{
  return x->s1;
}

int
fn2 (const struct S1 *x, unsigned y)
{
  if (y >= x->s1)
    fn0 ();
  return 0;
}

int
fn3 (struct S3 x)
{
  return (x.s3 == fn1 (*x.s4 ? &(*x.s4)->s2 : 0));
}

int
fn4 (struct S3 x)
{
  return fn2 (&(*x.s4)->s2, x.s3);
}

int
fn5 (struct S3 x, T *y)
{
  if (!fn3 (x))
    {
      *y = (T) (long) fn4 (x);
      return 1;
    }
  return 0;
}

void
test (struct S5 *x)
{
  struct S3 a;
  T b;
  unsigned char c = 0;
  a.s4 = &x->s5;
  while (fn5 (a, &b))
    if (!(b->t & 8))
      c = 1;
  a.s4 = &x->s5;
  while ((b = fn6 (a)))
    ;
  if (!c)
    fn7 ();
}
Comment 8 Jakub Jelinek 2009-10-19 17:14:33 UTC
NONDEBUG_INSN_P differences start appearing in DSE1, looking into it.
Comment 9 Jakub Jelinek 2009-10-19 18:35:11 UTC
Actually, it is not DSE1 but already loop-invariant.c, and the difference is in max_reg_pressure of the current loop (4 vs. 5 for one of the classes).
Comment 10 Jakub Jelinek 2009-10-20 09:39:55 UTC
Created attachment 18832 [details]
gcc45-pr41340.patch

Patch I'm going to bootstrap/regtest.
Comment 11 Jakub Jelinek 2009-10-20 13:29:20 UTC
Subject: Bug 41340

Author: jakub
Date: Tue Oct 20 13:29:08 2009
New Revision: 153011

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153011
Log:
	PR debug/41340
	* loop-invariant.c (calculate_loop_reg_pressure): Don't count regs
	referenced just in DEBUG_INSNs.

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

Added:
    trunk/gcc/testsuite/gcc.dg/pr41340.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/loop-invariant.c
    trunk/gcc/testsuite/ChangeLog

Comment 12 Jakub Jelinek 2009-10-20 14:32:38 UTC
The original rtl.ii.gz testcase compiles just fine with -fcompare-debug too (though, it surely used to be something different, as those loop-invariant.c changes are from end of September).
Comment 13 Dmitry Gorbachev 2009-10-23 09:15:33 UTC
The original testcase still fails with -fcompare-debug with GCC 4.5.0 20091022. This bug is now tracked here: bug 41806.

The second bug is indeed fixed.