https://llvm.org/bugs/show_bug.cgi?id=31399
Bug ID: 31399 Summary: [CodeGen] suboptimal code for ffs() Product: libraries Version: trunk Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: Common Code Generator Code Assignee: unassignedb...@nondot.org Reporter: dav...@freebsd.org CC: fil...@gmail.com, llvm-bugs@lists.llvm.org, llvm-...@redking.me.uk, simon.f.whitta...@gmail.com Classification: Unclassified Given #include <strings.h> int f(int x) { return ffs(x) + 1; } compiled with -O3, clang 3.9.0 generates f(int): # @f(int) bsfl %edi, %ecx addl $2, %ecx testl %edi, %edi movl $1, %eax cmovnel %ecx, %eax retq while gcc 6.2 generates: f(int): bsf eax, edi mov edx, -1 cmove eax, edx add eax, 2 ret We could save a test instruction. I don't think it matters a lot in practice, but maybe a fun exercise if somebody wants to take a look (cc:ing Simon W. who was looking for small codegen bugs to fix). (Note that we lower ffs() to (x != 0) ? llvm.cttz(x) + 1 : 0 in SimplifyLibCalls.cpp) -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs