[llvm] 6188929 - [TTI][NFC] Introduce option to set predictable branch threshold

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 2 02:55:29 PST 2023


Author: Serguei Katkov
Date: 2023-02-02T17:54:56+07:00
New Revision: 6188929dfbda9adebdd9a1393febd6dd08842ab3

URL: https://github.com/llvm/llvm-project/commit/6188929dfbda9adebdd9a1393febd6dd08842ab3
DIFF: https://github.com/llvm/llvm-project/commit/6188929dfbda9adebdd9a1393febd6dd08842ab3.diff

LOG: [TTI][NFC] Introduce option to set predictable branch threshold

Currently TargetTransformInfo::getPredictableBranchThreshold() method
returns hardcoded value 99. This value affects the decision whether to
convert select instruction to branch or not in several passes:
SelectOptimize, CodeGenPrepare, SimplifyCFG.

It would be useful to make possible to play with that threshold in order
to test select-optimize heuristics.

Option was originally introduced in the TargetLoweringBase, but was
removed in the revision 664d0c052c315 and not restored in the TTI

Patch Author: aleksandr.popov
Reviewed By: spatel
Differential Revision: https://reviews.llvm.org/D143060

Added: 
    

Modified: 
    llvm/lib/Analysis/TargetTransformInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index ad7e5432d4c5..e8e0fcef7256 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -37,6 +37,11 @@ static cl::opt<unsigned> CacheLineSize(
     cl::desc("Use this to override the target cache line size when "
              "specified by the user."));
 
+static cl::opt<unsigned> PredictableBranchThreshold(
+    "predictable-branch-threshold", cl::init(99), cl::Hidden,
+    cl::desc(
+        "Use this to override the target's predictable branch threshold (%)."));
+
 namespace {
 /// No-op implementation of the TTI interface using the utility base
 /// classes.
@@ -232,7 +237,9 @@ TargetTransformInfo::getInstructionCost(const User *U,
 }
 
 BranchProbability TargetTransformInfo::getPredictableBranchThreshold() const {
-  return TTIImpl->getPredictableBranchThreshold();
+  return PredictableBranchThreshold.getNumOccurrences() > 0
+             ? BranchProbability(PredictableBranchThreshold, 100)
+             : TTIImpl->getPredictableBranchThreshold();
 }
 
 bool TargetTransformInfo::hasBranchDivergence() const {


        


More information about the llvm-commits mailing list