Open
Description
Bugzilla Link | 20197 |
Version | trunk |
OS | Linux |
Blocks | #4440 |
CC | @legrosbuffle,@echristo,@isanbard,@josephcsible,@nickdesaulniers,@zygoloid,@tstellar |
Extended Description
When multiple alternatives in an inline asm constraint are given we ignore all of them but the most "general". This gives nasty artifacts in the code.
int bsr(unsigned v) {
int ret;
__asm__("bsr %1, %0" : "=&r"(ret) : "rm"(v) : "cc");
return ret;
}
$ clang -O3 -S -o - t.c
bsr:
movl %edi, -4(%rsp)
#APP
bsrl -4(%rsp), %eax
#NO_APP
retq
The spilling is totally unnecessary. GCC gets this one right. On 32 bit x86 it's even worse:
$ clang -O3 -S -o - t.c -m32
bsr:
pushl %eax
movl 8(%esp), %eax
movl %eax, (%esp)
#APP
bsrl (%esp), %eax
#NO_APP
popl %edx
retl
GCC knows a better way:
$ gcc-4.8 -O3 -S -o - t.c -m32
bsr:
#APP
bsr 4(%esp), %eax
#NO_APP
ret
The constraint "g" is just as bad, being translated into "imr" internally.