Skip to content

Commit edf9bfe

Browse files
author
Jin Huang
committed
[profcheck] Add unknown branch weights to expanded cmpxchg loop.
1 parent 4d6bff4 commit edf9bfe

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

llvm/lib/CodeGen/AtomicExpandPass.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/MDBuilder.h"
3939
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
4040
#include "llvm/IR/Module.h"
41+
#include "llvm/IR/ProfDataUtils.h"
4142
#include "llvm/IR/Type.h"
4243
#include "llvm/IR/User.h"
4344
#include "llvm/IR/Value.h"
@@ -1259,8 +1260,7 @@ Value *AtomicExpandImpl::insertRMWLLSCLoop(
12591260
BasicBlock *BB = Builder.GetInsertBlock();
12601261
Function *F = BB->getParent();
12611262

1262-
assert(AddrAlign >=
1263-
F->getDataLayout().getTypeStoreSize(ResultTy) &&
1263+
assert(AddrAlign >= F->getDataLayout().getTypeStoreSize(ResultTy) &&
12641264
"Expected at least natural alignment at this point.");
12651265

12661266
// Given: atomicrmw some_op iN* %addr, iN %incr ordering
@@ -1680,7 +1680,12 @@ Value *AtomicExpandImpl::insertRMWCmpXchgLoop(
16801680

16811681
Loaded->addIncoming(NewLoaded, LoopBB);
16821682

1683-
Builder.CreateCondBr(Success, ExitBB, LoopBB);
1683+
Instruction *CondBr = Builder.CreateCondBr(Success, ExitBB, LoopBB);
1684+
1685+
// Atomic RMW expands to a cmpxchg loop, Since precise branch weights
1686+
// cannot be easily determined here, we mark the branch as "unknown" (50/50)
1687+
// to prevent misleading optimizations.
1688+
setExplicitlyUnknownBranchWeightsIfProfiled(*CondBr, *F, DEBUG_TYPE);
16841689

16851690
Builder.SetInsertPoint(ExitBB, ExitBB->begin());
16861691
return NewLoaded;

llvm/test/Transforms/AtomicExpand/AArch64/atomicrmw-fp.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt -S -mtriple=aarch64-linux-gnu -passes=atomic-expand %s | FileCheck %s
33

4-
define float @test_atomicrmw_fadd_f32(ptr %ptr, float %value) {
4+
define float @test_atomicrmw_fadd_f32(ptr %ptr, float %value) !prof !0 {
55
; CHECK-LABEL: @test_atomicrmw_fadd_f32(
6+
; CHECK: !prof [[PROF_0:![0-9]+]]
67
; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4
78
; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]]
89
; CHECK: atomicrmw.start:
@@ -336,3 +337,7 @@ define <2 x half> @atomicrmw_fminimum_2_x_half(ptr %ptr, <2 x half> %val) {
336337
%res = atomicrmw fminimum ptr %ptr, <2 x half> %val seq_cst
337338
ret <2 x half> %res
338339
}
340+
341+
!0 = !{!"function_entry_count", i64 1000}
342+
; CHECK: [[PROF_0]] = !{!"function_entry_count", i64 1000}
343+
; CHECK: [[PROF_1]] = !{!"unknown", !"atomic-expand"}

0 commit comments

Comments
 (0)