Gcc puts the section markers incorrect, resulting in a basically dummy effect

Take this simple example:
void simple_test(int X)
{
        if (__builtin_expect((X==3),0))
                call_slowpath_function();
        else
                call_fastpath_function();
}

this leads to the following assembly with 
gcc -O2 -freorder-blocks-and-parittions -s test.c

       .file   "test.c"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB0:
        .text
.LHOTB0:
        .p2align 4,,15
.globl simple_test
        .type   simple_test, @function
simple_test:
.LFB2:
        cmpl    $3, %edi
        je      .L7
        xorl    %eax, %eax
        jmp     call_fastpath_function
.L7:
        xorl    %eax, %eax
        jmp     call_slowpath_function
.LFE2:
        .size   simple_test, .-simple_test
        .section        .text.unlikely
.LCOLDE0:
        .text
.LHOTE0:



as you can see, the .text.unlikely is put after the slowpath code, not when the
slowpath code starts.... which is less than useful.
(it happens for much bigger functions/slowpaths as well so it's not just due to
the small size of the unlikely part here)


-- 
           Summary: -freorder-blocks-and-partition is a dud
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: arjanv at redhat dot com
  GCC host triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26493

Reply via email to