[zebes:~] astrange% /usr/local/bin/gcc -v Using built-in specs. Target: powerpc-apple-darwin7.7.0 Configured with: ../configure --enable-threads=posix --with-threads=posix Thread model: posix gcc version 4.1.0 20050226 (experimental)
Command line: /usr/local/bin/gcc -O3 -mcpu=7400 -mtune=7400 -fdump-tree-optimized -c mod_loop.c Code: void mod_loop(unsigned char *array, int len, unsigned char repeat) { unsigned char i; for (i = 0; i < len; i++) array[i] = i%repeat; } void mod_loop2(unsigned char *array, int len, unsigned char repeat) { unsigned char i,i2=0; for (i = 0; i < len; i++) {array[i] = i2++; if (i2 == repeat) i2 = 0;} } Although the two functions are equivalent and mod_loop2 is better (avoiding an expensive divide), GCC doesn't transform the first into the second. -- Summary: missed optimization of loop IV modulus Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: astrange at ithinksw dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: powerpc-apple-darwin7.7.0 GCC host triplet: powerpc-apple-darwin7.7.0 GCC target triplet: powerpc-apple-darwin7.7.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20231