[llvm] [JumpThreading] Add a hook to override the duplication threshold (PR #111826)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 05:18:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Pengcheng Wang (wangpc-pp)
<details>
<summary>Changes</summary>
We can override the default duplication threshold via the constructor
of `JumpThreadingPass` but it is unused in current pass pipeline.
So we remove the constructor and add a target hook so that targets
can override the default value.
---
Full diff: https://github.com/llvm/llvm-project/pull/111826.diff
5 Files Affected:
- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (+9)
- (modified) llvm/include/llvm/Analysis/TargetTransformInfoImpl.h (+4)
- (modified) llvm/include/llvm/Transforms/Scalar/JumpThreading.h (-3)
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+5)
- (modified) llvm/lib/Transforms/Scalar/JumpThreading.cpp (+2-7)
``````````diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 5c5da5e06c1bff..bd41433da1059d 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -1810,6 +1810,10 @@ class TargetTransformInfo {
/// \return The maximum number of function arguments the target supports.
unsigned getMaxNumArgs() const;
+ /// \return The maximum number of duplicate threshold when doing
+ /// JumpThreading.
+ unsigned getJumpThreadingDupThreshold(bool OptForSize) const;
+
/// @}
private:
@@ -2211,6 +2215,7 @@ class TargetTransformInfo::Concept {
getVPLegalizationStrategy(const VPIntrinsic &PI) const = 0;
virtual bool hasArmWideBranch(bool Thumb) const = 0;
virtual unsigned getMaxNumArgs() const = 0;
+ virtual unsigned getJumpThreadingDupThreshold(bool OptForSize) const = 0;
};
template <typename T>
@@ -3004,6 +3009,10 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
unsigned getMaxNumArgs() const override {
return Impl.getMaxNumArgs();
}
+
+ unsigned getJumpThreadingDupThreshold(bool OptForSize) const override {
+ return Impl.getJumpThreadingDupThreshold(OptForSize);
+ }
};
template <typename T>
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 6d3ce93acbe451..ba3187c89faf91 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -995,6 +995,10 @@ class TargetTransformInfoImplBase {
unsigned getMaxNumArgs() const { return UINT_MAX; }
+ unsigned getJumpThreadingDupThreshold(bool OptForSize) const {
+ return OptForSize ? 3 : 6;
+ }
+
protected:
// Obtain the minimum required size to hold the value (without the sign)
// In case of a vector it returns the min required size for one element.
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 7d11fc0ad69384..8e242a2c256062 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
@@ -95,11 +95,8 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
#endif
unsigned BBDupThreshold;
- unsigned DefaultBBDupThreshold;
public:
- JumpThreadingPass(int T = -1);
-
// Glue for old PM.
bool runImpl(Function &F, FunctionAnalysisManager *FAM,
TargetLibraryInfo *TLI, TargetTransformInfo *TTI,
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 3dc29fc7cd77b1..2aca9e4b2917c4 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -1328,6 +1328,11 @@ unsigned TargetTransformInfo::getMaxNumArgs() const {
return TTIImpl->getMaxNumArgs();
}
+unsigned
+TargetTransformInfo::getJumpThreadingDupThreshold(bool OptForSize) const {
+ return TTIImpl->getJumpThreadingDupThreshold(OptForSize);
+}
+
bool TargetTransformInfo::shouldExpandReduction(const IntrinsicInst *II) const {
return TTIImpl->shouldExpandReduction(II);
}
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 7a0b661a07799a..ea6c1ee1bea6b7 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -107,10 +107,6 @@ static cl::opt<bool> ThreadAcrossLoopHeaders(
cl::desc("Allow JumpThreading to thread across loop headers, for testing"),
cl::init(false), cl::Hidden);
-JumpThreadingPass::JumpThreadingPass(int T) {
- DefaultBBDupThreshold = (T == -1) ? BBDuplicateThreshold : unsigned(T);
-}
-
// Update branch probability information according to conditional
// branch probability. This is usually made possible for cloned branches
// in inline instances by the context specific profile in the caller.
@@ -304,10 +300,9 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
// size.
if (BBDuplicateThreshold.getNumOccurrences())
BBDupThreshold = BBDuplicateThreshold;
- else if (F->hasFnAttribute(Attribute::MinSize))
- BBDupThreshold = 3;
else
- BBDupThreshold = DefaultBBDupThreshold;
+ BBDupThreshold = TTI->getJumpThreadingDupThreshold(
+ F->hasFnAttribute(Attribute::MinSize));
// JumpThreading must not processes blocks unreachable from entry. It's a
// waste of compute time and can potentially lead to hangs.
``````````
</details>
https://github.com/llvm/llvm-project/pull/111826
More information about the llvm-commits
mailing list