[llvm-commits] [llvm] r47458 - /llvm/trunk/lib/Target/X86/README.txt

Evan Cheng evan.cheng at apple.com
Thu Feb 21 15:10:30 PST 2008


On Feb 21, 2008, at 1:16 PM, Eli Friedman wrote:

>
> -Implement CTTZ, CTLZ with bsf and bsr. GCC produces:
> +__builtin_ffs codegen is messy.
>
> -int ctz_(unsigned X) { return __builtin_ctz(X); }
> -int clz_(unsigned X) { return __builtin_clz(X); }
> int ffs_(unsigned X) { return __builtin_ffs(X); }
>
> -_ctz_:
> -        bsfl    4(%esp), %eax
> -        ret
> -_clz_:
> -        bsrl    4(%esp), %eax
> -        xorl    $31, %eax
> +llvm produces:
> +ffs_:
> +        movl    4(%esp), %ecx
> +        bsfl    %ecx, %eax
> +        movl    $32, %edx
> +        cmove   %edx, %eax
> +        incl    %eax
> +        xorl    %edx, %edx
> +        testl   %ecx, %ecx
> +        cmove   %edx, %eax
>         ret
> +
> +vs gcc:
> +
> _ffs_:
>         movl    $-1, %edx
>         bsfl    4(%esp), %eax
> @@ -503,6 +468,15 @@
>         addl    $1, %eax
>         ret
>

Unfortunately we can't do much about this without introducing a x86  
specific ctlz intrinsic. There is a semantics mismatch between  
llvm.ctlz and __builtin_clz. llvm.ctlz returns 32 if the input is zero.

>
> +// 
> = 
> = 
> = 
> --------------------------------------------------------------------- 
> ===//
> +
> +Consider:
> +
> +#include <inttypes.h>
> +uint64_t a;
> +uint16_t b;
> +uint64_t mul(void) {
> +  return a * b;
> +}
> +
> +Currently, we generate the following:
> +
> +mul:
> +        movzwl  b, %ecx
> +        movl    %ecx, %eax
> +        mull    a
> +        imull   a+4, %ecx
> +        addl    %edx, %ecx
> +        movl    %ecx, %edx
> +        ret
> +
> +llvm should be able to commute the addl so that the movl isn't  
> necessary.

Try -coalescer-commute-instrs. This is fixed but not turned on. I want  
to make sure the register allocator doesn't do stupid things.

Evan

>
> +
> +// 
> = 
> = 
> = 
> --------------------------------------------------------------------- 
> ===//
> +
> Consider:
> int test(unsigned long a, unsigned long b) { return -(a < b); }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list