13250 – [3.4 only] [SH] Gcc code for rotation clobbers the register, but gcc continues to use the register as if it was not clobbered (original) (raw)
Bug 13250 - [3.4 only] [SH] Gcc code for rotation clobbers the register, but gcc continues to use the register as if it was not clobbered
Summary: [3.4 only] [SH] Gcc code for rotation clobbers the register, but gcc continue...
| Description Valeriy E. Ushakov 2003-12-01 01:49:25 UTC 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 Comment 2 Dara Hazeghi 2004-01-21 04:03:24 UTC Confirmed on both branches (and mainline). Any sh expert want to take a look? Comment 3 Kazumoto Kojima 2004-05-27 03:19:06 UTC 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])); Comment 4 Valeriy E. Ushakov 2004-05-27 21:03:43 UTC 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 Comment 8 Drea Pinski 2004-06-01 00:13:44 UTC Fixed. Comment 10 Drea Pinski 2004-07-26 00:52:50 UTC Fixed also in 3.3.5 | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |