[llvm] [profcheck] Add heuristical profile metadata for lowering table-based cttz. (PR #161898)

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 23:17:09 PDT 2025


================
@@ -599,6 +607,19 @@ static bool tryToRecognizeTableBasedCttz(Instruction &I, const DataLayout &DL) {
     auto Cmp = B.CreateICmpEQ(X1, ConstantInt::get(XType, 0));
     auto Select = B.CreateSelect(Cmp, B.CreateZExt(ZeroTableElem, XType), Cttz);
 
+    // Attach heuristic branch weigths to the newly 'select' instruction that
+    // handles the cttz(0) edge case The assumpltion is tht the input to a cttz
+    // operation is rarely 0, so we add a strong 100-to-1 bias weights to the
+    // 'false' path.
----------------
alanzhao1 wrote:

FWIW in C++ the `[[likely]]` attribute [produces branch weights of 2000 and 1](https://godbolt.org/z/6cjra5dj4) (but I agree `createUnlkielyBranchWeights()` is better should this change in the future).

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


More information about the llvm-commits mailing list