gcc 3.5-tree-ssa-lno 20040823 (merged 20040718) gcc doesn't optimize shift count modulo word size, but curiously it does when adding one more bit: unsigned long f(unsigned long x, unsigned long y) { return x >> (y % 64); } unsigned long g(unsigned long x, unsigned long y) { return x >> (y % 128); } f: and $17,63,$17 srl $16,$17,$0 ret g: srl $16,$17,$0 ret It seems this is not a regression, already 2.95 behaved like this.
Confirmed, patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02483.html>.
Subject: Bug 17151 CVSROOT: /cvs/gcc Module name: gcc Changes by: sayle@gcc.gnu.org 2004-09-26 14:55:38 Modified files: gcc : ChangeLog combine.c Log message: PR middle-end/17151 * combine.c (force_to_mode): Remove dubious early return test that inhibits further optimization. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5630&r2=2.5631 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/combine.c.diff?cvsroot=gcc&r1=1.455&r2=1.456
Fixed.
This breaks ia64 by miscompiling the stage2 compiler. ./xgcc -B./ -B/usr/local/ia64-suse-linux/bin/ -isystem /usr/local/ia64-suse-linux/include -isystem /usr/local/ia64-suse-linux/sys-include -L/tmp/cvs/gcc-test-200409262100/Build/gcc/../ld -O2 -DIN_GCC -DUSE_LIBUNWIND_EXCEPTIONS -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -DUSE_GAS_SYMVER -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -c -o crtfastmath.o \ ../../gcc/config/ia64/crtfastmath.c ../../gcc/config/ia64/crtfastmath.c: In function '__ia64_set_fast_math': ../../gcc/config/ia64/crtfastmath.c:37: internal compiler error: in bundling, at config/ia64/ia64.c:6575
Removing patch keyword as this was reopened for bootstrap failure.
I'm now able to confirm the bootstrap failure on ia64-unknown-linux-gnu (now that the other bootstrap failures have been resolved), and reverting my patch fixes the problem. I've managed to identify the problem as the miscompilation to the file bitmap.o.