-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[IRBuilder] Introduce CreateSelectFMFWithUnknownProfile #174162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IRBuilder] Introduce CreateSelectFMFWithUnknownProfile #174162
Conversation
This came up in review feedback in c163e7a. 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.
|
@llvm/pr-subscribers-llvm-transforms Author: Aiden Grossman (boomanaiden154) ChangesThis came up in review feedback in Full diff: https://github.com/llvm/llvm-project/pull/174162.diff 3 Files Affected:
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;
}
|
|
@llvm/pr-subscribers-llvm-ir Author: Aiden Grossman (boomanaiden154) ChangesThis came up in review feedback in Full diff: https://github.com/llvm/llvm-project/pull/174162.diff 3 Files Affected:
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;
}
|
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This came up in review feedback in c163e7a. 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.
This came up in review feedback in
c163e7a. 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.