This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/46235] inefficient bittest code generation
- From: "tony.poppleton at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 28 Jan 2011 16:55:56 +0000
- Subject: [Bug rtl-optimization/46235] inefficient bittest code generation
- Auto-submitted: auto-generated
- References: <bug-46235-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46235
--- Comment #2 from Tony Poppleton <tony.poppleton at gmail dot com> 2011-01-28 16:55:48 UTC ---
Based on Richard's comment, I tried a modified version of the code replacing
the (1 << x) with just (16).
This shows that GCC (4.6 & 4.5.2) does perform an optimization similar to llvm,
and uses the testb instruction:
movl %edi, %eax
movl $1, %edx
testb $16, %al
cmove %edx, %eax
ret
Therefore, perhaps it would be beneficial to not convert from "a & (n << x)" to
"(a >> x) & n", in the special case where the value n is 1 (or a power of 2
potentially)?
Incidentally, the above code could have been optimized further to remove the
usage of edx entirely (will make a separate PR about that)