Re: Why gcc's code is so much slower than clang's?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 23 Oct 2023, Georg-Johann Lay wrote:

> For the C code below, I am getting execution times of around 8 to 8.3
> seconds with gcc (v11.3 and v13.2) and around 5 seconds with clang v17.
> 
> Only options I used were -O3 (-Os or -Ofast didn't make a difference).
> 
> Architecture is x86_64-linux-gnu, Dual Core Intel Core2
> 
> I ran the code below with
> 
> > gcc coll.c -o coll.x -O3 && time -p ./coll.x
> 
> I wouldn't ask this question if I hadn't observed similar thing
> with other programs already, any I am wondering if I am missing
> something crucial like supplying GCC with better options?

In this specific program, Clang translates

    i = (i & 1)
        ? (3 * i + 1) >> 1
        : i >> 1;

into a straight-line code involving a conditional move, while GCC
emits a conditional branch. That branch turns out to be poorly
predictable, causing GCC-compiled program to run slower, even though
it executes much fewer instructions (~13 billion vs ~20 billion).

(I used 'perf stat' to obtain the instruction counts)

For other programs the cause of disparity may be different.

Alexander



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux