[llvm] [profcheck] Add unknown branch weights for inlined strcmp/strncmp (PR #160455)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 00:34:28 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Jin Huang (jinhuang1102)
<details>
<summary>Changes</summary>
The strcmp/strncmp inliner creates new conditional branches but was failing to add profile metadata. This caused the ProfileVerifierPass to fail when profcheck is enabled.
This patch fixes the issue by explicitly adding unknown branch weights to these branches.
---
Full diff: https://github.com/llvm/llvm-project/pull/160455.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp (+8-4)
``````````diff
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index 40de36d81ddd2..d00a3bc86d6b8 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -29,6 +29,7 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include "llvm/Transforms/Utils/Local.h"
@@ -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);
+ } else {
B.CreateBr(BBNE);
+ }
Phi->addIncoming(Sub, BBSubs[i]);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/160455
More information about the llvm-commits
mailing list