[llvm] [InstCombine] Fix ProfCheck for optimizing bitreverse (PR #227189)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 22:07:43 PDT 2026
================
@@ -2556,8 +2557,15 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
X->getType()->isIntOrIntVectorTy(1)) {
Type *Ty = II->getType();
APInt SignBit = APInt::getSignMask(Ty->getScalarSizeInBits());
- return SelectInst::Create(X, ConstantInt::get(Ty, SignBit),
- ConstantInt::getNullValue(Ty));
+ SelectInst *SI = SelectInst::Create(X, ConstantInt::get(Ty, SignBit),
+ ConstantInt::getNullValue(Ty));
+ // Mark the branch weights explicitly unknown as in the general case we
+ // cannot infer the probability of the condition without additional value
+ // profiling.
+ if (std::optional<uint64_t> EC = F.getEntryCount(); !EC || *EC == 0)
----------------
boomanaiden154 wrote:
We do, but it looks at the function attached to the instruction. Given we've used SelectInst::Create, it's not attached to a function yet, so using the default helper function causes a null pointer dereference.
https://github.com/llvm/llvm-project/pull/227189
More information about the llvm-commits
mailing list