Bug 11440 - [3.3 regression] gcc-3.3.1 miscompiles c++ code with -O2, -fno-gcse cures it
Summary: [3.3 regression] gcc-3.3.1 miscompiles c++ code with -O2, -fno-gcse cures it
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.3.1
Assignee: Franz Sirl
URL:
Keywords: wrong-code
: 11542 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-07-05 10:02 UTC by olh
Modified: 2003-07-17 08:58 UTC (History)
3 users (show)

See Also:
Host: powerpc-unknown-linux
Target: powerpc-unknown-linux
Build: powerpc-unknown-linux
Known to work:
Known to fail:
Last reconfirmed: 2003-07-11 07:03:30


Attachments
/tmp/render.tar.bz2 (506.20 KB, application/octet-stream)
2003-07-05 10:03 UTC, olh
Details
Reduced testcase to the miscompiled routine (161.50 KB, application/octet-stream)
2003-07-10 21:51 UTC, Franz Sirl
Details
before GCSE (1.62 KB, text/plain)
2003-07-10 21:52 UTC, Franz Sirl
Details
After GCSE (3.10 KB, text/plain)
2003-07-10 21:52 UTC, Franz Sirl
Details
Provisional patch (476 bytes, patch)
2003-07-11 16:46 UTC, Franz Sirl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description olh 2003-07-05 10:02:18 UTC
konqueror from KDE_3_1_BRANCH does not render http://www.spiegel.de/ correctly. 
the reason is a miscompilation in libkhtml.so.4.1.0, render_box.cpp is miscompiled. 
 
gcc-3.2.3 produces correct results, gcc-3.3.1 with -O1 as well, -O2 breaks it. 
adding -fno-gcse after -O2 produces correct code. 
 
g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../kimgio -I../../kio -I../../dcop -I../../kfile -I../../khtml -I../.. 
-I../../dcop -I../../libltdl -I../../kdecore -I../../kdeui -I../../kio -I../../kio/kio -I../../kio/kfile -I../.. 
-I/usr/qt/3/include -I/usr/X11R6/include -I/home/kdebeta/kde31-cvs/include 
-DQT_THREAD_SUPPORT -D_REENTRANT -Wnon-virtual-dtor -Wno-long-long -Wundef -Wall 
-pedantic -W -Wpointer-arith -Wwrite-strings -ansi -D_XOPEN_SOURCE=500 
-D_BSD_SOURCE -Wcast-align -Wconversion -O1 -O2 -fno-gcse -fsigned-char -g 
-fmessage-length=0 -fno-exceptions -fno-check-new -DQT_NO_TRANSLATION 
-DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST -DQT_NO_COMPAT -c 
render_box.cpp -MT render_box.lo -MD -MP -MF .deps/render_box.TPlo  -fPIC -DPIC -o  
.libs/render_box.o 
 
see attachment.
Comment 1 olh 2003-07-05 10:03:49 UTC
Created attachment 4348 [details]
/tmp/render.tar.bz2

.ii files and .s files, + logs
Comment 2 Andrew Pinski 2003-07-05 13:05:48 UTC
Might be related to bug 9745 or not.
Comment 3 olh 2003-07-05 14:23:35 UTC
-O1 -fstrict-aliasing did not show the bug. 
Comment 4 Franz Sirl 2003-07-07 08:23:32 UTC
regression, worked fine in 3.2.3.
The suggested fixes for PR9745/PR10021 don't fix this one.
Comment 5 Franz Sirl 2003-07-10 21:51:07 UTC
Created attachment 4381 [details]
Reduced testcase to the miscompiled routine
Comment 6 Franz Sirl 2003-07-10 21:52:03 UTC
Created attachment 4382 [details]
before GCSE
Comment 7 Franz Sirl 2003-07-10 21:52:28 UTC
Created attachment 4383 [details]
After GCSE
Comment 8 Franz Sirl 2003-07-10 21:55:59 UTC
I wonder if the addition of the REG_EQUAL notes by GCSE is correct: 
 
 (insn# # # 0x33f37e00 (set (reg/v:SI 134) 
         (const_int 1 [0x1]))# {*movsi_internal1} (nil) 
     (expr_list:REG_EQUAL (const_int 1 [0x1]) 
         (nil))) 
 
 (insn# # # 0x33f37e40 (set (reg:SI 135) 
         (mem/s/j:SI (plus:SI (reg/v/u/f:SI 118) 
                 (const_int 24 [0x18])) [0 S4 A32]))# {*movsi_internal1} (nil) 
     (nil)) 
 
 (insn# # # 0x33f37e40 (set (zero_extract:SI (reg:SI 135) 
             (const_int 1 [0x1]) 
             (const_int 20 [0x14])) 
         (reg/v:SI 134))# {insvsi} (nil) 
-    (nil)) 
+    (expr_list:REG_EQUAL (const_int 1 [0x1]) 
+        (nil))) 
 
shouldn't that result in a REG_EQUAL (reg:SI 135) if anything? 
 
Comment 9 Andrew Pinski 2003-07-11 00:05:32 UTC
No GCSE should not put the REG_EQUAL there.
Here is the definition of zero_extract's agruments:
/* Reference to a signed bit-field of specified size and position.   
   Operand 0 is the memory unit (usually SImode or QImode) which
   contains the field's first bit.  Operand 1 is the width, in bits.
   Operand 2 is the number of bits in the memory unit before the 
   first bit of this field.
   If BITS_BIG_ENDIAN is defined, the first bit is the msb and
   operand 2 counts from the msb of the memory unit.
   Otherwise, the first bit is the lsb and operand 2 counts from
   the lsb of the memory unit.  */
Comment 10 Franz Sirl 2003-07-11 16:46:45 UTC
Created attachment 4389 [details]
Provisional patch

This patch against the 3_3-branch fixes the testcase for me (no
bootstrap/regtest so far). I'm not 100% sure if it's the right place to reject
the note, but it looks reasonable to me. And do I need to reject
STRICT_LOW_PART and SUBREG too?
Comment 11 CVS Commits 2003-07-14 09:21:48 UTC
Subject: Bug 11440

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	sirl@gcc.gnu.org	2003-07-14 09:21:45

Modified files:
	gcc            : gcse.c ChangeLog 

Log message:
	2003-07-14  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
	
	PR optimization/11440
	* gcse.c (try_replace_reg): Don't attach notes to ZERO_EXTRACT or
	SIGN_EXTRACT SETs.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gcse.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.223.2.6&r2=1.223.2.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.655&r2=1.16114.2.656

Comment 12 CVS Commits 2003-07-14 09:30:03 UTC
Subject: Bug 11440

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sirl@gcc.gnu.org	2003-07-14 09:29:57

Modified files:
	gcc            : gcse.c ChangeLog 

Log message:
	2003-07-14  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
	
	PR optimization/11440
	* gcse.c (try_replace_reg): Don't attach notes to ZERO_EXTRACT or
	SIGN_EXTRACT SETs.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gcse.c.diff?cvsroot=gcc&r1=1.258&r2=1.259
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.485&r2=2.486

Comment 13 CVS Commits 2003-07-14 16:03:32 UTC
Subject: Bug 11440

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sirl@gcc.gnu.org	2003-07-14 16:03:29

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20030714-1.c 

Log message:
	2003-07-14  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
	
	PR optimization/11440
	* gcc.c-torture/execute/20030714-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030714-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2872&r2=1.2873

Comment 14 CVS Commits 2003-07-14 16:04:45 UTC
Subject: Bug 11440

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	sirl@gcc.gnu.org	2003-07-14 16:04:42

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20030714-1.c 

Log message:
	2003-07-14  Franz Sirl  <Franz.Sirl-kernel@lauterbach.com>
	
	PR optimization/11440
	* gcc.c-torture/execute/20030714-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20030714-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.231&r2=1.2261.2.232

Comment 15 Franz Sirl 2003-07-14 16:15:57 UTC
Bug fixed and testcase added in mainline and branch. 
 
Comment 16 Franz Sirl 2003-07-16 09:10:03 UTC
*** Bug 11542 has been marked as a duplicate of this bug. ***