[llvm] [profcheck] Add unknown branch weights to expanded cmpxchg loop. (PR #165841)

Tim Gymnich via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 09:48:16 PST 2025


================
@@ -1686,7 +1681,12 @@ Value *AtomicExpandImpl::insertRMWCmpXchgLoop(
 
   Loaded->addIncoming(NewLoaded, LoopBB);
 
-  Builder.CreateCondBr(Success, ExitBB, LoopBB);
+  Instruction *CondBr = Builder.CreateCondBr(Success, ExitBB, LoopBB);
+
+  // Atomic RMW expands to a cmpxchg loop, Since precise branch weights
+  // cannot be easily determined here, we mark the branch as "unknown" (50/50)
+  // to prevent misleading optimizations.
+  setExplicitlyUnknownBranchWeightsIfProfiled(*CondBr, *F, DEBUG_TYPE);
----------------
tgymnich wrote:

```suggestion
  setExplicitlyUnknownBranchWeightsIfProfiled(*CondBr, DEBUG_TYPE, *F);
```
The argument order seems wrong...

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


More information about the llvm-commits mailing list