[llvm] [profcheck] Add unknown branch weights for inlined strcmp/strncmp (PR #160455)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 08:06:31 PDT 2025


================
@@ -1283,11 +1284,14 @@ void StrNCmpInliner::inlineCompare(Value *LHS, StringRef RHS, uint64_t N,
     Value *VR =
         ConstantInt::get(CI->getType(), static_cast<unsigned char>(RHS[i]));
     Value *Sub = Swapped ? B.CreateSub(VR, VL) : B.CreateSub(VL, VR);
-    if (i < N - 1)
-      B.CreateCondBr(B.CreateICmpNE(Sub, ConstantInt::get(CI->getType(), 0)),
-                     BBNE, BBSubs[i + 1]);
-    else
+    if (i < N - 1) {
+      BranchInst *CondBrInst = B.CreateCondBr(
+          B.CreateICmpNE(Sub, ConstantInt::get(CI->getType(), 0)), BBNE,
+          BBSubs[i + 1]);
+      setExplicitlyUnknownBranchWeights(*CondBrInst, DEBUG_TYPE);
----------------
mtrofin wrote:

Set this only if the function entry count is non-zero. See this discussion: https://github.com/llvm/llvm-project/pull/158743#issuecomment-3298886673

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


More information about the llvm-commits mailing list