http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57301
Steven Bosscher <steven at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2013-05-16 CC| |jakub at gcc dot gnu.org Component|c++ |testsuite Ever confirmed|0 |1 --- Comment #3 from Steven Bosscher <steven at gcc dot gnu.org> --- (In reply to Andy Lutomirski from comment #0) > It's well known [citation needed] that modern compilers are excellent at > optimizing simple bit twiddling. :-) > gcc -O2 (4.7 and some random 4.8 build) generates: > > f1: > .LFB0: > .cfi_startproc > movl > %edi, %eax > rolw $8, %ax > ret > .cfi_endproc > > clang -O2 generates: > > f1: # @f1 > > .cfi_startproc > # BB#0: > rolw $8, %di > movzwl %di, %eax > ret > > (I suspect that these are equally good.) The gcc code is slightly better in most cases but it depends on the target. ix86 tuning is as irregular as the architecture itself. > But g++ -O2 generates: > > _Z2f1t: > .LFB0: > .cfi_startproc > movzwl %di, %edi > movl %edi, %eax > sarl $8, %edi > sall $8, %eax > orl %edi, %eax > ret > .cfi_endproc > > Perhaps some decent subset of the gcc testsuite should also be built > with the c++ frontend to make sure it still passes... That is not so easy to do, but apparently it's necessary. gcc and g++ are not supposed to generate different code for such a trivial example. We'd have to figure out a subset of the gcc test suite that actually tests middle-end features (such as your instruction combining/folding example). For GCC 4.9 the middle-end rotation optimizations have been improved by Jakub's patches for bug 55278. For GCC 4.7 and GCC 4.8 I would expect the -fdump-tree-optimized dumps for gcc and g++ to be the same. Can you try that and have a look at those dumps?