------- Comment #7 from ubizjak at gmail dot com 2007-04-04 08:05 ------- This is the minimal test case for this bug:
--cut here-- extern void foo(void); double *data; double test() { double sum = 123.321; int i; for (i=0; i<4; i++) sum += data[i]; foo(); foo(); return sum; } --cut here-- Without the second call to foo(), function compiles to (gcc version 4.3.0 20070403 (experimental)): test: subq $24, %rsp movq data(%rip), %rdx movl $1, %eax movsd .LC0(%rip), %xmm0 addsd (%rdx), %xmm0 .L2: addsd (%rdx,%rax,8), %xmm0 addq $1, %rax cmpq $4, %rax jne .L2 movsd %xmm0, (%rsp) call foo movsd (%rsp), %xmm0 addq $24, %rsp ret When the second call to foo() is added, RA gets confused and pushes sum variable to stack: test: subq $8, %rsp movq data(%rip), %rdx movl $1, %eax movsd .LC0(%rip), %xmm0 addsd (%rdx), %xmm0 movsd %xmm0, (%rsp) <= here .L2: movsd (%rsp), %xmm0 <= here addsd (%rdx,%rax,8), %xmm0 addq $1, %rax cmpq $4, %rax movsd %xmm0, (%rsp) <= here jne .L2 call foo call foo movsd (%rsp), %xmm0 addq $8, %rsp ret -- ubizjak at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ubizjak at gmail dot com Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Known to fail| |4.3.0 Last reconfirmed|0000-00-00 00:00:00 |2007-04-04 08:05:01 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31396