[llvm] [SLU][profcheck] Use the original branch weigths in `buildPartialInvariantUnswitchConditionalBranch` (PR #164270)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 30 10:55:59 PDT 2025


================
@@ -377,8 +377,17 @@ static void buildPartialInvariantUnswitchConditionalBranch(
   IRBuilder<> IRB(&BB);
   IRB.SetCurrentDebugLocation(DebugLoc::getCompilerGenerated());
   Value *Cond = VMap[ToDuplicate[0]];
-  IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc,
-                   Direction ? &NormalSucc : &UnswitchedSucc);
+  auto *ProfData =
+      !ProfcheckDisableMetadataFixes &&
+              ToDuplicate[0] == skipTrivialSelect(OriginalBranch.getCondition())
+          ? OriginalBranch.getMetadata(LLVMContext::MD_prof)
+          : nullptr;
+  auto *BR =
+      IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc,
+                       Direction ? &NormalSucc : &UnswitchedSucc, ProfData);
+  if (!ProfData)
+    setExplicitlyUnknownBranchWeightsIfProfiled(
+        *BR, *BR->getParent()->getParent(), DEBUG_TYPE);
----------------
fhahn wrote:

```suggestion
        *BR, *BR->getFunction(), DEBUG_TYPE);
```

I think there's a getFunction helper

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


More information about the llvm-commits mailing list