[libc-commits] [libc] [libc][stdlib] Optimize bsearch() by reordering comparison branches (PR #230823)

Kuan-Wei Chiu via libc-commits libc-commits at lists.llvm.org
Mon Oct 12 09:04:15 PDT 2026


visitorckw wrote:

> LGTM.
> 
> Ideally we should be able to have the >0 branch appear second, but I couldn't manage to even using `_builtin_expect`.

Thanks for the review!

I think which check appears second in the generated code shouldn't really make a difference here: once the first branch rules out < 0, the only two cases left are > 0 and == 0, so the cpu always has to evaluate one more conditional branch to tell them apart anyway.


https://github.com/llvm/llvm-project/pull/230823


More information about the libc-commits mailing list