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

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 03:35:38 PST 2023


aleksandr.popov created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently TargetTransformInfo::getPredictableBranchThreshold() method
returns hardcoded value 99. This value affects on 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.


https://reviews.llvm.org/D143060

Files:
  llvm/lib/Analysis/TargetTransformInfo.cpp


Index: llvm/lib/Analysis/TargetTransformInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetTransformInfo.cpp
+++ llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -37,6 +37,11 @@
     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 @@
 }
 
 BranchProbability TargetTransformInfo::getPredictableBranchThreshold() const {
-  return TTIImpl->getPredictableBranchThreshold();
+  return PredictableBranchThreshold.getNumOccurrences() > 0
+             ? BranchProbability(PredictableBranchThreshold, 100)
+             : TTIImpl->getPredictableBranchThreshold();
 }
 
 bool TargetTransformInfo::hasBranchDivergence() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143060.493890.patch
Type: text/x-patch
Size: 1060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230201/81bfef9e/attachment.bin>


More information about the llvm-commits mailing list