[llvm] [PGO] Add uniformity profile metadata and gate CHR (PR #221517)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 6 05:50:44 PDT 2026
================
@@ -1329,6 +1336,36 @@ static bool hasAtLeastTwoBiasedBranches(CHRScope *Scope) {
void CHR::filterScopes(SmallVectorImpl<CHRScope *> &Input,
SmallVectorImpl<CHRScope *> &Output) {
for (CHRScope *Scope : Input) {
+ // Branch weights count individual lanes. A divergent branch can therefore
+ // look strongly biased even when every wave executes both paths. Avoid
+ // applying CHR to such a scope because duplicating its control flow may
+ // increase live ranges and register pressure without eliminating control
+ // flow for the wave. Select-only scopes are unaffected because branch
+ // uniformity profile describes only conditional branches.
+ if (HasBlockUniformityProfile) {
+ Instruction *DivergentBranch = nullptr;
+ auto FindDivergentBranch = [&](const DenseSet<Region *> &Regions) {
+ for (Region *R : Regions) {
+ Instruction *Branch = R->getEntry()->getTerminator();
+ if (!Branch->getMetadata(LLVMContext::MD_branch_uniformity_profile)) {
+ DivergentBranch = Branch;
+ return;
+ }
+ }
+ };
+ FindDivergentBranch(Scope->TrueBiasedRegions);
+ if (!DivergentBranch)
+ FindDivergentBranch(Scope->FalseBiasedRegions);
+ if (DivergentBranch) {
+ ORE.emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "DivergentBranch",
+ DivergentBranch)
+ << "Drop scope containing a divergent branch";
----------------
arsenm wrote:
```suggestion
<< "drop scope containing a divergent branch";
```
https://github.com/llvm/llvm-project/pull/221517
More information about the llvm-commits
mailing list