http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50037
Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rakdver at gcc dot gnu.org --- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-10 15:42:19 UTC --- Confirmed with int foo (int n, int *addr) { int count, sum; for ( count = n & 0x3; count > 0; count--, addr++ ) sum += *addr; return sum; } and -O2 -funroll-loops. Using int foo (int n, int *addr) { int count, sum; for ( count = n & 0x3; count >= 0; count--, addr++ ) sum += *addr; return sum; } it works. It looks like RTL number of iteration analysis is confused by the adjustment (insn 28 27 29 3 (parallel [ (set (reg:SI 92) (plus:SI (reg/v:SI 77 [ count ]) (const_int -1 [0xffffffffffffffff]))) (clobber (reg:CC 17 flags)) ]) t.c:1 251 {*addsi_1} (expr_list:REG_DEAD (reg/v:SI 77 [ count ]) (expr_list:REG_UNUSED (reg:CC 17 flags) (nil)))) neither works with int foo (int n, int *addr) { int count, sum; for ( count = 0; count < n & 0x3; count++, addr++ ) sum += *addr; return sum; } or int foo (int n, int *addr) { int count, sum; for ( count = 0; count <= n & 0x3; count++, addr++ ) sum += *addr; return sum; }