-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 2191 |
| Resolution | FIXED |
| Resolved on | Jan 21, 2009 00:23 |
| Version | unspecified |
| OS | Linux |
| CC | @asl,@isanbard,@sunfishcode,@nlewycky |
Extended Description
Using llvm-gcc SVN r49213 on the simple testcase below generates code with extra mov instructions.
unsigned sum(unsigned a, unsigned b)
{
do {
a ^= b;
b &= ~a;
} while (b <<= 1);
return a;
}
This is the assembly generated, note the extra movl, and testl after the and:
sum:
.align 16
.LBB1_1: # bb
xorl %esi, %edi
movl %edi, %eax
xorl $2147483647, %eax
andl %esi, %eax
addl %eax, %eax
testl %eax, %eax
movl %eax, %esi
jne .LBB1_1 # bb
.LBB1_2: # bb12
movl %edi, %eax
ret
.size sum, .-sum
This should be a more optimized version (maybe xor could be changed to a not, not sure):
sum:
.align 16
.LBB1_1: # bb
xorl %esi, %edi
movl %edi, %eax
xorl $2147483647, %eax
andl %eax, %esi
addl %esi, %esi
jne .LBB1_1 # bb
.LBB1_2: # bb12
movl %edi, %eax
ret
.size sum, .-sum
FWIW, gcc doesn't generate the optimized version either, here is what I get with gcc-4.3 -O3:
sum:
.align 16
.LBB1_1: # bb
xorl %esi, %edi
movl %edi, %eax
xorl $2147483647, %eax
andl %esi, %eax
addl %eax, %eax
testl %eax, %eax
movl %eax, %esi
jne .LBB1_1 # bb
.LBB1_2: # bb12
movl %edi, %