gcc-3.3.2 and 3.4 miscompile sha256 digest code for SuperH, minimized test case attached. The sha256 transformation computes a sum that has (amongst others) the following subexpressions: + (... ^ ((((e)) >> (25)) | (((e)) << (32 - (25))))) + (((e) & (f)) ^ ((~(e)) & (g))) Code generated with -O is: swap.w r4,r1 ! r4 contains "e" shll8 r4 ! "e" in r4 gets clobbered shlr8 r1 or r4,r1 rotr r1 ! rotate "e" 25 bits xor r1,r2 mov.l @(8,r14),r1 add r1,r2 ! enclosing sum mov r4,r3 ! <-- gcc thinks r4 still has the value of "e" !!! and r13,r3 ! e & f not r4,r1 ! ~e and r6,r1 ! ~e & g xor r1,r3 ! (e & f) ^ (~e & g) add r3,r2 ! add into the sum
Created attachment 5247 [details] test case that demonstrates the problem
Confirmed on both branches (and mainline). Any sh expert want to take a look?
This looks an SH target specific problem when generating rtl for rotation like (e << 8) | (e >> 24). It seems the patch below for sh.md fixes this. I'll propose it to gcc-patch list after bootstrap and regtest. --- ORIG/gcc/gcc/config/sh/sh.md 2004-05-14 10:08:34.000000000 +0900 +++ LOCAL/gcc/gcc/config/sh/sh.md 2004-05-27 08:32:37.000000000 +0900 @@ -2194,7 +2194,7 @@ parts[0] = gen_reg_rtx (SImode); parts[1] = gen_reg_rtx (SImode); emit_insn (gen_rotlsi3_16 (parts[2-choice], operands[1])); - parts[choice-1] = operands[1]; + emit_move_insn (parts[choice-1], operands[1]); emit_insn (gen_ashlsi3 (parts[0], parts[0], GEN_INT (8))); emit_insn (gen_lshrsi3 (parts[1], parts[1], GEN_INT (8))); emit_insn (gen_iorsi3 (operands[0], parts[0], parts[1]));
Subject: Re: [SH] Gcc code for rotation clobbers the register, but gcc continues to use the register as if it was not clobbered With this fix applied the test case program passes its tests. -uwe
FYI, I've proposed the above patch: http://gcc.gnu.org/ml/gcc-patches/2004-05/msg01782.html
Subject: Bug 13250 CVSROOT: /cvs/gcc Module name: gcc Changes by: kkojima@gcc.gnu.org 2004-05-28 05:47:37 Modified files: gcc : ChangeLog gcc/config/sh : sh.md Log message: PR target/13250 * config/sh/sh.md (rotlsi3): Use emit_move_insn. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3767&r2=2.3768 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.md.diff?cvsroot=gcc&r1=1.171&r2=1.172
Subject: Bug 13250 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: kkojima@gcc.gnu.org 2004-06-01 00:07:52 Modified files: gcc : ChangeLog gcc/config/sh : sh.md Log message: PR target/13250 Backport from mainline: 2004-05-28 Kaz Kojima <kkojima@gcc.gnu.org> * config/sh/sh.md (rotlsi3): Use emit_move_insn. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.461&r2=2.2326.2.462 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.md.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.165.4.2&r2=1.165.4.3
Fixed.
Subject: Bug 13250 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: kkojima@gcc.gnu.org 2004-07-26 00:48:24 Modified files: gcc : ChangeLog gcc/config/sh : sh.md t-linux libstdc++-v3 : ChangeLog configure Added files: gcc/config/sh : libgcc-std.ver Log message: PR target/13250 Backport from mainline: * config/sh/sh.md (rotlsi3): Use emit_move_insn. PR target/15647 Backport from mainline: * config/sh/t-linux (SHLIB_MAPFILES): Use sh specific libgcc-std.ver. * config/sh/libgcc-std.ver: New file. PR bootstrap/15120 * libstdc++-v3/configure: Rebuilt. Patches: 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.1006&r2=1.16114.2.1007 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/libgcc-std.ver.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.2.10.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.133.2.3&r2=1.133.2.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/t-linux.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.6.20.2&r2=1.6.20.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.188&r2=1.1464.2.189 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/configure.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.286.2.22&r2=1.286.2.23
Fixed also in 3.3.5