Bug 43280 - [4.5 Regression] gcc4.5 -m32 -O2: misoptimizes sha256!
Summary: [4.5 Regression] gcc4.5 -m32 -O2: misoptimizes sha256!
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.0
: P1 major
Target Milestone: 4.5.0
Assignee: Andreas Krebbel
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-03-07 12:18 UTC by Török Edwin
Modified: 2010-03-11 14:06 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2010-03-08 08:54:15


Attachments
sha256.c (4.15 KB, text/plain)
2010-03-07 12:19 UTC, Török Edwin
Details
preprocessed sha256.c (7.13 KB, text/plain)
2010-03-07 12:19 UTC, Török Edwin
Details
Experimental patch (1.08 KB, patch)
2010-03-10 16:31 UTC, Andreas Krebbel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Török Edwin 2010-03-07 12:18:46 UTC
gcc-4.5 -O2 -m32 misoptimizes sha256:

$ ~/gcc/install/bin/gcc-4.5 sha256.c -L/home/edwin/gcc/install/lib/gcc/x86_64-unknown-linux-gnu/lib32 -O2 -m32
$ ./a.out
sha256 test vector #1 failed
sha256 test vector #2 failed
sha256 test vector #3 failed
Aborted

Without -m32 it works:
$ ~/gcc/install/bin/gcc-4.5 sha256.c -L/home/edwin/gcc/install/lib/gcc/x86_64-unknown-linux-gnu/lib64 -O2
$ ./a.out
$

And -m32 -O1 works too:
$ ~/gcc/install/bin/gcc-4.5 sha256.c -L/home/edwin/gcc/install/lib/gcc/x86_64-unknown-linux-gnu/lib32 -O1 -m32
$ ./a.out
$

gcc version:

~/gcc/install/bin/gcc-4.5 -v
Using built-in specs.
COLLECT_GCC=/home/edwin/gcc/install/bin/gcc-4.5
COLLECT_LTO_WRAPPER=/home/edwin/gcc/install/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c --enable-checking=release --enable-ssp --disable-libssp --disable-plugin --disable-libmudflap --with-system-zlib --enable-version-specific-runtime-libs --program-suffix=-4.5 --enable-linux-futex -without-system-libunwind --with-arch-32=i586 --with-tune=generic --with-mpfr=/opt/cfarm/mpfr-2.4.1 --with-gmp=/opt/cfarm/gmp-4.2.4 --with-libelf=/opt/cfarm/libelf-0.8.12 --with-mpc=/opt/cfarm/mpc-0.8 --disable-bootstrap : (reconfigured) ../gcc-trunk/configure --prefix=/home/edwin/gcc/install --enable-languages=c --enable-checking=release --enable-ssp --disable-libssp --disable-plugin --disable-libmudflap --with-system-zlib --enable-version-specific-runtime-libs --program-suffix=-4.5 --enable-linux-futex -without-system-libunwind --with-arch-32=i586 --with-tune=generic --with-mpfr=/opt/cfarm/mpfr-2.4.1 --with-gmp=/opt/cfarm/gmp-4.2.4 --with-libelf=/opt/cfarm/libelf-0.8.12 --with-mpc=/opt/cfarm/mpc-0.8 --disable-bootstrap
Thread model: posix
gcc version 4.5.0 20100307 (experimental) (GCC)

Bug initially reported against openSUSE 11.3 factory's gcc-4.5, but I reproduced with upstream gcc-4.5 SVN r157262.

See https://wwws.clamav.net/bugzilla/show_bug.cgi?id=1862 for the original report.
Comment 1 Török Edwin 2010-03-07 12:19:03 UTC
Created attachment 20038 [details]
sha256.c
Comment 2 Török Edwin 2010-03-07 12:19:17 UTC
Created attachment 20039 [details]
preprocessed sha256.c
Comment 3 Richard Biener 2010-03-07 15:47:23 UTC
Confirmed.  This is exposed by the new bswap pass.
Comment 4 H.J. Lu 2010-03-07 16:56:41 UTC
It is caused by revision 148848:

http://gcc.gnu.org/ml/gcc-cvs/2009-06/msg00831.html
Comment 5 Andreas Krebbel 2010-03-10 16:31:01 UTC
Created attachment 20074 [details]
Experimental patch

This patch fixes the problem for me. Testsuites are still running.
Comment 6 H.J. Lu 2010-03-10 17:50:34 UTC
(In reply to comment #5)
> Created an attachment (id=20074) [edit]
> Experimental patch
> 
> This patch fixes the problem for me. Testsuites are still running.
> 

Why does the new testcase have

+/* { dg-require-effective-target lp64 } */

when the failure is shown with -m32 on x86-64?

Comment 7 Andreas Krebbel 2010-03-11 13:51:17 UTC
Subject: Bug 43280

Author: krebbel
Date: Thu Mar 11 13:51:00 2010
New Revision: 157386

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157386
Log:
2010-03-11  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	PR tree-optimization/43280
	* tree-ssa-math-opts.c (find_bswap_1): Modify symbolic number generation.
	Move calculation of size out of the if branch.
	(find_bswap): Modify compare number generation.

2010-03-11  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* gcc.dg/optimize-bswapdi-1.c: Add OpenSSL bswap variant.
	* gcc.dg/pr43280.c: New testcase.



Added:
    trunk/gcc/testsuite/gcc.dg/pr43280.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/optimize-bswapdi-1.c
    trunk/gcc/tree-ssa-math-opts.c

Comment 8 Andreas Krebbel 2010-03-11 14:06:21 UTC
(In reply to comment #6)
> Why does the new testcase have
> 
> +/* { dg-require-effective-target lp64 } */
> 
> when the failure is shown with -m32 on x86-64?
> 

I've removed that in the new version. Thanks!