[llvm] [UniformityAnalysis] Skip CycleAnalysis on targets without branch divergence (PR #189948)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 05:32:26 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Pankaj Dwivedi (PankajDwivedi-25)
<details>
<summary>Changes</summary>
UniformityAnalysis unconditionally computes CycleAnalysis even on targets that don't care about divergence, causing measurable compile-time overhead (see [#<!-- -->99878 (comment)](https://github.com/llvm/llvm-project/pull/175167#issuecomment-4156230947)).
---
Full diff: https://github.com/llvm/llvm-project/pull/189948.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/GenericUniformityImpl.h (+14)
- (modified) llvm/lib/Analysis/UniformityAnalysis.cpp (+12-11)
``````````diff
diff --git a/llvm/include/llvm/ADT/GenericUniformityImpl.h b/llvm/include/llvm/ADT/GenericUniformityImpl.h
index b6c714b704a57..6af4a0e15430f 100644
--- a/llvm/include/llvm/ADT/GenericUniformityImpl.h
+++ b/llvm/include/llvm/ADT/GenericUniformityImpl.h
@@ -1289,29 +1289,43 @@ GenericUniformityInfo<ContextT>::getFunction() const {
}
/// Whether \p V is divergent at its definition.
+/// A default-constructed instance (no analysis computed) reports everything
+/// as uniform, which is conservatively correct for non-divergent targets.
template <typename ContextT>
bool GenericUniformityInfo<ContextT>::isDivergent(ConstValueRefT V) const {
+ if (!DA)
+ return false;
return DA->isDivergent(V);
}
template <typename ContextT>
bool GenericUniformityInfo<ContextT>::isDivergent(const InstructionT *I) const {
+ if (!DA)
+ return false;
return DA->isDivergent(*I);
}
template <typename ContextT>
bool GenericUniformityInfo<ContextT>::isDivergentUse(const UseT &U) const {
+ if (!DA)
+ return false;
return DA->isDivergentUse(U);
}
template <typename ContextT>
bool GenericUniformityInfo<ContextT>::hasDivergentTerminator(const BlockT &B) {
+ if (!DA)
+ return false;
return DA->hasDivergentTerminator(B);
}
/// \brief T helper function for printing.
template <typename ContextT>
void GenericUniformityInfo<ContextT>::print(raw_ostream &out) const {
+ if (!DA) {
+ out << " Uniformity analysis not computed (no branch divergence).\n";
+ return;
+ }
DA->print(out);
}
diff --git a/llvm/lib/Analysis/UniformityAnalysis.cpp b/llvm/lib/Analysis/UniformityAnalysis.cpp
index f40ea1a556f9f..f3195ca9efc86 100644
--- a/llvm/lib/Analysis/UniformityAnalysis.cpp
+++ b/llvm/lib/Analysis/UniformityAnalysis.cpp
@@ -168,14 +168,13 @@ template struct llvm::GenericUniformityAnalysisImplDeleter<
llvm::UniformityInfo UniformityInfoAnalysis::run(Function &F,
FunctionAnalysisManager &FAM) {
- auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
auto &TTI = FAM.getResult<TargetIRAnalysis>(F);
+ if (!TTI.hasBranchDivergence(&F))
+ return UniformityInfo{};
+ auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
auto &CI = FAM.getResult<CycleAnalysis>(F);
UniformityInfo UI{DT, CI, &TTI};
- // Skip computation if we can assume everything is uniform.
- if (TTI.hasBranchDivergence(&F))
- UI.compute();
-
+ UI.compute();
return UI;
}
@@ -216,18 +215,20 @@ void UniformityInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
}
bool UniformityInfoWrapperPass::runOnFunction(Function &F) {
- auto &cycleInfo = getAnalysis<CycleInfoWrapperPass>().getResult();
- auto &domTree = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto &targetTransformInfo =
getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
m_function = &F;
- m_uniformityInfo = UniformityInfo{domTree, cycleInfo, &targetTransformInfo};
- // Skip computation if we can assume everything is uniform.
- if (targetTransformInfo.hasBranchDivergence(m_function))
- m_uniformityInfo.compute();
+ if (!targetTransformInfo.hasBranchDivergence(m_function)) {
+ m_uniformityInfo = UniformityInfo{};
+ return false;
+ }
+ auto &cycleInfo = getAnalysis<CycleInfoWrapperPass>().getResult();
+ auto &domTree = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ m_uniformityInfo = UniformityInfo{domTree, cycleInfo, &targetTransformInfo};
+ m_uniformityInfo.compute();
return false;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/189948
More information about the llvm-commits
mailing list