3 ms·
I think it is used for code layout: typically you want to make the most often taken branch as fallthrough as it can be slightly faster even when perfectly predi
by gpderetta 3y ago
I think it is used for code layout: typically you want to make the most often taken branch as fallthrough as it can be slightly faster even when perfectly predicted.
I also tried (and failed) to use expect with probability to generate a cmov, but in retrospect it is obvious: the parameter is not the prediction probability, but the taken/not-taken probability, and even a branch that goes either way with 50% probability can still be predicted perfectly (for example a branch that switches every other iteration), so the parameter can't be used to decide between predication and prediction.
edit: what we really need is an [[unpredictable]] attribute.
- twoodfin 3y agoIndeed: A branch taken 50% of the time can be readily predicted 100% of the time if it follows a pattern the CPU can infer. Why you have to be careful choosing realistic input data if you are microbenchmarking at this level for a real purpose.
- pixelesque 3y agoclang has one: https://clang.llvm.org/docs/LanguageExtensions.html#builtin-unpredictable https://clang.llvm.org/docs/LanguageExtensions.html#builtin-...
- ot 3y agoWhich also does not affect cmov conversion. Every time this comes up I bring up this long-standing LLVM bug: https://bugs.llvm.org/show_bug.cgi?id=40027 https://bugs.llvm.org/show_bug.cgi?id=40027
- dzaima 3y ago__builtin_unpredictable is gonna be fixed in LLVM/clang 17: https://github.com/llvm/llvm-project/commit/09515f2c20111628ce81ad5f40e12e5f6af5ed2f https://github.com/llvm/llvm-project/commit/09515f2c20111628... (also, bugs.llvm.org is old; the more up-to-date (but still open) issue is https://github.com/llvm/llvm-project/issues/39374 https://github.com/llvm/llvm-project/issues/39374)
- ot 3y agoAmazing, finally!!!
- foldr 3y ago>typically you want to make the most often taken branch as fallthrough as it can be slightly faster even when perfectly predicted. Sure, but that application doesn't require a fine-grained probability estimate.