-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
Description
Bugzilla Link | 3253 |
Resolution | FIXED |
Resolved on | Jan 29, 2009 11:21 |
Version | trunk |
OS | Linux |
CC | @asl,@lattner,@efriedma-quic,@sunfishcode |
Extended Description
Consider this code:
int foo(char *c)
{
return strcspn(c, ":\r\n");
}
llvm-gcc translates this into this (which is better than gcc, which does 3 cmpb!):
.text
.align 16
.globl foo
.type foo,@function
foo:
xorl %eax, %eax
jmp .LBB1_2 # bb24
.LBB1_1: # bb23
incq %rax
.LBB1_2: # bb24
movb (%rdi,%rax), %cl
movl $1, %edx
shlq %cl, %rdx
cmpb $58, %cl
ja .LBB1_1 # bb23
.LBB1_3: # bb24
movabsq $288230376151720961, %rcx
testq %rcx, %rdx
je .LBB1_1 # bb23
.LBB1_4: # bb35
ret
.size foo, .-foo
Tron on #llvm suggested that it could be improved even further:
- movl $1, %rdx; shl %cl, %rdx; test %ecx, %edx == bt
- loading the huge constant (the instruction is 10 bytes long!) should be moved out of the loop