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, Xi Ruoyao via Gcc-help wrote:

> GCC even uses branch instead of cmov for:
> 
> int test(int x)
> {
> 	return x & 1 ? 3 * x + 1 : x / 2;
> }
> 
> Should we create a ticket in bugzilla or is there some reason not to use
> cmov here?

There's a long-standing problem that RTL if-conversion passes do not emit
important information such as estimated costs and attempted transforms,
so it's impossible to say if it's "working as designed" without gdb'ing
the compiler. I suspect something is not working as it should on this
example.

In general:

For predictable branches, cmov can stitch computations into one long
dependency chain, making the resulting code latency-bound. For unpredictable
branches, cmov avoids the costs resulting from mispredictions.

The compiler cannot tell if a branch is going to be well-predictable or not.
My view is that compilers should offer __builtin_branchless_select so people
can express what they need. So far it didn't happen. LLVM offers
__builtin_unpredictable, which in my eyes is just an indirect way to request
branchless code.

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