https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110007

--- Comment #3 from Richard Yao <richard.yao at alumni dot stonybrook.edu> ---
(In reply to Andrew Pinski from comment #2)
> (In reply to Richard Yao from comment #0)
> > Having the ability to specify __builtin_unpredictable() as a hint to
> > encourage the compiler to use cmov would be useful for implementing
> > algorithms like binary search that have unpredictable branches.
> > __builtin_expect_with_probability() looks like a possible substitute, but
> > Clang does not support it and it does not always work as described in
> > #110001.
> 
> PR 110001 has nothing to do with __builtin_expect_with_probability and

I mentioned it briefly in PR 110001, but I guess I should make it explicit. See
line 58 here:

https://gcc.godbolt.org/z/ef3Yfchzv

That is made into a jump, when all that is necessary is cmov, which is what
Clang generates. In the example I had posted in PR 110001, I had not used
__builtin_expect_with_probability() because it made no difference, but here I
am using it to show that cmov is not used.

Earlier in the output, GCC 12.3 uses cmov for every 3rd instruction, so I
suspect that this is not a case of two cmovs being too close to each other.

Should I file another issue explicitly for that so this could be left for the
request that we have __builtin_unpredictable()?

> __builtin_expect_with_probability will do exactly the same as
> __builtin_unpredictable will do really.

__builtin_unpredictable() is easier to read than
__builtin_expect_with_probability() and it would be nice for both Clang and GCC
to support the same builtins.

Reply via email to