[llvm] [SimplifyCFG][profcheck] Profile propagation for `indirectbr` (PR #161747)

Alan Zhao via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 6 10:48:43 PDT 2025


================
@@ -7877,19 +7882,30 @@ bool SimplifyCFGOpt::simplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) {
 bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
   BasicBlock *BB = IBI->getParent();
   bool Changed = false;
+  SmallVector<uint32_t> BranchWeights;
+  const bool HasBranchWeights = !ProfcheckDisableMetadataFixes &&
+                                extractBranchWeights(*IBI, BranchWeights);
 
+  DenseMap<const BasicBlock *, uint64_t> TargetWeight;
+  if (HasBranchWeights)
+    for (size_t I = 0, E = IBI->getNumDestinations(); I < E; ++I) {
+      auto [It, Inserted] =
----------------
alanzhao1 wrote:

I believe `operator[]` default constructs a value if the key isn't present, so these four lines could be simplified to

```cpp
TargetWeight[IBI->getDestination(I)] += BranchWeights[I];
```

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


More information about the llvm-commits mailing list