------- Comment #1 from scovich at gmail dot com 2007-07-11 16:36 ------- (In reply to comment #0) > // g++ -mtune=core2 -O3 -S -dp Oops... that doesn't actually unroll loop() all, though it still peels loop_few().
Adding -funroll-loops (supposedly enabled by -O3?) unrolls loop() Adding -funroll-all-loops does nothing Nested loops also have issues: void nested_loop(int* dest, int* src) { for(int i=0; i < 2; i++) for(int j=0; j < 2; j++) dest[4*i+j] = src[4*j+i]; } becomes _Z11nested_loopPiS_: .LFB533: xorl %edx, %edx # 39 *movdi_xor_rex64 [length = 2] .L47: movl (%rsi), %ecx # 13 *movsi_1/1 [length = 2] movl %ecx, (%rdi,%rdx,4) # 14 *movsi_1/2 [length = 3] movl 16(%rsi), %eax # 15 *movsi_1/1 [length = 3] addq $4, %rsi # 17 *adddi_1_rex64/1 [length = 4] movl %eax, 4(%rdi,%rdx,4) # 16 *movsi_1/2 [length = 4] addq $4, %rdx # 18 *adddi_1_rex64/1 [length = 4] cmpq $8, %rdx # 20 cmpdi_1_insn_rex64/1 [length = 4] jne .L47 # 21 *jcc_1 [length = 2] rep ; ret # 40 return_internal_long [length = 1] -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32729