Bug 17151 - x >> (y % WORDSIZE) not optimized
Summary: x >> (y % WORDSIZE) not optimized
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2004-08-23 13:30 UTC by Falk Hueffner
Modified: 2004-09-30 23:48 UTC (History)
3 users (show)

See Also:
Host: alphaev68-unknown-linux-gnu
Target: alphaev68-unknown-linux-gnu
Build: alphaev68-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2004-09-24 02:53:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Falk Hueffner 2004-08-23 13:30:29 UTC
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.
Comment 1 Andrew Pinski 2004-09-24 02:53:38 UTC
Confirmed, patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02483.html>.
Comment 2 GCC Commits 2004-09-26 14:55:40 UTC
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

Comment 3 Andrew Pinski 2004-09-26 15:16:57 UTC
Fixed.
Comment 4 Andreas Schwab 2004-09-27 14:04:11 UTC
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 
 
Comment 5 Andrew Pinski 2004-09-30 03:05:53 UTC
Removing patch keyword as this was reopened for bootstrap failure.
Comment 6 roger 2004-09-30 16:31:58 UTC
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.
Comment 7 Andrew Pinski 2004-09-30 23:48:47 UTC
Fixed.