[llvm] [IRBuilder] Introduce CreateSelectFMFWithUnknownProfile (PR #174162)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 1 14:35:03 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
This came up in review feedback in
c163e7a72249cbc8105fbc5cc6a772e5dc90c94d. This function makes it easier to create select instructions that propagate fast math flags with unknown profile info, which is a common case. This mirrors the already existing CreateSelectWithUknownProfile helper.
---
Full diff: https://github.com/llvm/llvm-project/pull/174162.diff
3 Files Affected:
- (modified) llvm/include/llvm/IR/IRBuilder.h (+6)
- (modified) llvm/lib/IR/IRBuilder.cpp (+12)
- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (+2-4)
``````````diff
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 972a253344ddf..bc35caabeb849 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2553,6 +2553,12 @@ class IRBuilderBase {
StringRef PassName,
const Twine &Name = "");
+ LLVM_ABI Value *CreateSelectFMFWithUnknownProfile(Value *C, Value *True,
+ Value *False,
+ FMFSource FMFSource,
+ StringRef PassName,
+ const Twine &Name = "");
+
LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
const Twine &Name = "",
Instruction *MDFrom = nullptr);
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index a397f6973ee05..6f7ffe9cbe635 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -1014,6 +1014,18 @@ Value *IRBuilderBase::CreateSelectWithUnknownProfile(Value *C, Value *True,
return Ret;
}
+Value *IRBuilderBase::CreateSelectFMFWithUnknownProfile(Value *C, Value *True,
+ Value *False,
+ FMFSource FMFSource,
+ StringRef PassName,
+ const Twine &Name) {
+ Value *Ret = CreateSelectFMF(C, True, False, FMFSource, Name);
+ if (auto *SI = dyn_cast<SelectInst>(Ret)) {
+ setExplicitlyUnknownBranchWeightsIfProfiled(*SI, PassName);
+ }
+ return Ret;
+}
+
Value *IRBuilderBase::CreateSelect(Value *C, Value *True, Value *False,
const Twine &Name, Instruction *MDFrom) {
return CreateSelectFMF(C, True, False, {}, Name, MDFrom);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 47b66a4e0f37d..3ad1caa6baa63 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2202,12 +2202,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V,
Value *X = CI->getArgOperand(0);
Value *IsPosInfOrNan = Builder.CreateFCmpFMF(
FCmpInst::FCMP_UEQ, X, ConstantFP::getInfinity(VTy), FMF);
- Value *ZeroOrInf = Builder.CreateSelectFMF(
- IsPosInfOrNan, X, ConstantFP::getZero(VTy), FMF);
// We do not know whether an infinity or a NaN is more likely here,
// so mark the branch weights as unkown.
- if (auto *SI = dyn_cast<SelectInst>(ZeroOrInf))
- setExplicitlyUnknownBranchWeightsIfProfiled(*SI, DEBUG_TYPE);
+ Value *ZeroOrInf = Builder.CreateSelectFMFWithUnknownProfile(
+ IsPosInfOrNan, X, ConstantFP::getZero(VTy), FMF, DEBUG_TYPE);
return ZeroOrInf;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/174162
More information about the llvm-commits
mailing list