Index: llvm/include/llvm/ADT/GenericUniformityImpl.h =================================================================== --- llvm/include/llvm/ADT/GenericUniformityImpl.h +++ llvm/include/llvm/ADT/GenericUniformityImpl.h @@ -43,6 +43,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SparseBitVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Support/raw_ostream.h" #include @@ -1139,8 +1140,6 @@ const TargetTransformInfo *TTI) : F(&Func) { DA.reset(new ImplT{Func, DT, CI, TTI}); - DA->initialize(); - DA->compute(); } template Index: llvm/include/llvm/ADT/GenericUniformityInfo.h =================================================================== --- llvm/include/llvm/ADT/GenericUniformityInfo.h +++ llvm/include/llvm/ADT/GenericUniformityInfo.h @@ -47,6 +47,11 @@ GenericUniformityInfo(GenericUniformityInfo &&) = default; GenericUniformityInfo &operator=(GenericUniformityInfo &&) = default; + void compute() { + DA->initialize(); + DA->compute(); + } + /// Whether any divergence was detected. bool hasDivergence() const; Index: llvm/include/llvm/CodeGen/MachineUniformityAnalysis.h =================================================================== --- llvm/include/llvm/CodeGen/MachineUniformityAnalysis.h +++ llvm/include/llvm/CodeGen/MachineUniformityAnalysis.h @@ -25,10 +25,12 @@ using MachineUniformityInfo = GenericUniformityInfo; /// \brief Compute uniformity information for a Machine IR function. -MachineUniformityInfo -computeMachineUniformityInfo(MachineFunction &F, - const MachineCycleInfo &cycleInfo, - const MachineDomTree &domTree); +/// +/// If \p HasBranchDivergence is false, produces a dummy result which assumes +/// everything is uniform. +MachineUniformityInfo computeMachineUniformityInfo( + MachineFunction &F, const MachineCycleInfo &cycleInfo, + const MachineDomTree &domTree, bool HasBranchDivergence); } // namespace llvm Index: llvm/lib/Analysis/UniformityAnalysis.cpp =================================================================== --- llvm/lib/Analysis/UniformityAnalysis.cpp +++ llvm/lib/Analysis/UniformityAnalysis.cpp @@ -118,7 +118,12 @@ auto &DT = FAM.getResult(F); auto &TTI = FAM.getResult(F); auto &CI = FAM.getResult(F); - return UniformityInfo{F, DT, CI, &TTI}; + UniformityInfo UI{F, DT, CI, &TTI}; + // Skip computation if we can assume everything is uniform. + if (TTI.hasBranchDivergence()) + UI.compute(); + + return UI; } AnalysisKey UniformityInfoAnalysis::Key; @@ -168,6 +173,11 @@ m_function = &F; m_uniformityInfo = UniformityInfo{F, domTree, cycleInfo, &targetTransformInfo}; + + // Skip computation if we can assume everything is uniform. + if (targetTransformInfo.hasBranchDivergence()) + m_uniformityInfo.compute(); + return false; } Index: llvm/lib/CodeGen/MachineUniformityAnalysis.cpp =================================================================== --- llvm/lib/CodeGen/MachineUniformityAnalysis.cpp +++ llvm/lib/CodeGen/MachineUniformityAnalysis.cpp @@ -153,12 +153,14 @@ template struct llvm::GenericUniformityAnalysisImplDeleter< llvm::GenericUniformityAnalysisImpl>; -MachineUniformityInfo -llvm::computeMachineUniformityInfo(MachineFunction &F, - const MachineCycleInfo &cycleInfo, - const MachineDomTree &domTree) { +MachineUniformityInfo llvm::computeMachineUniformityInfo( + MachineFunction &F, const MachineCycleInfo &cycleInfo, + const MachineDomTree &domTree, bool HasBranchDivergence) { assert(F.getRegInfo().isSSA() && "Expected to be run on SSA form!"); - return MachineUniformityInfo(F, domTree, cycleInfo); + MachineUniformityInfo UI(F, domTree, cycleInfo); + if (HasBranchDivergence) + UI.compute(); + return UI; } namespace { @@ -218,7 +220,9 @@ bool MachineUniformityAnalysisPass::runOnMachineFunction(MachineFunction &MF) { auto &DomTree = getAnalysis().getBase(); auto &CI = getAnalysis().getCycleInfo(); - UI = computeMachineUniformityInfo(MF, CI, DomTree); + // FIXME: Query TTI::hasBranchDivergence. -run-pass seems to end up with a + // default NoTTI + UI = computeMachineUniformityInfo(MF, CI, DomTree, true); return false; } Index: llvm/lib/Target/AMDGPU/AMDGPURegBankSelect.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPURegBankSelect.cpp +++ llvm/lib/Target/AMDGPU/AMDGPURegBankSelect.cpp @@ -63,8 +63,9 @@ getAnalysis().getCycleInfo(); MachineDominatorTree &DomTree = getAnalysis(); + // TODO: Check for single lane execution. MachineUniformityInfo Uniformity = - computeMachineUniformityInfo(MF, CycleInfo, DomTree.getBase()); + computeMachineUniformityInfo(MF, CycleInfo, DomTree.getBase(), true); (void)Uniformity; // TODO: Use this assignRegisterBanks(MF);