[llvm] [SimplifyCFG][PGO] Reuse existing `setBranchWeights` (PR #160629)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 10:33:07 PDT 2025


================
@@ -209,10 +209,10 @@ loop_exit:
 
 ; IR-LABEL: define void @func5_zero_branch_weight
 ; IR: entry:
-; IR:   br i1 %cmp1, label %loop_exit, label %loop_body.lr.ph, !prof [[PROF_FUNC5_0:![0-9]+]]
+; IR:   br i1 %cmp1, label %loop_exit, label %loop_body.lr.ph
----------------
mtrofin wrote:

It comes from the code that I'm moving from SimplifyCFG. @david-xl believes there is some difference when leaving things as 0 vs removing, but we couldn't observe it in practice. I added the flag to allow us to experiment more. My take is that "0" really means "it's in a cold subgraph and happens to have been set" (by, e.g., iFDO), so leaving as 0 or removing should be equivalent.

I could flip the flag the other way, add an extra parameter to `setBranchWeights` on whether to propagate or not 0s, and have SimplifyCFG use that parameter. I'd still flip the flag so we can see if we ever hit an issue, and if not, we can remove the flag, remove the parameter, and propagate things as given.

wdyt?

https://github.com/llvm/llvm-project/pull/160629


More information about the llvm-commits mailing list