Skip to content

Commit 0366285

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

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

llvm/lib/CodeGen/AtomicExpandPass.cpp

Lines changed: 7 additions & 1 deletion
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"
@@ -1680,7 +1681,12 @@ Value *AtomicExpandImpl::insertRMWCmpXchgLoop(
16801681

16811682
Loaded->addIncoming(NewLoaded, LoopBB);
16821683

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

16851691
Builder.SetInsertPoint(ExitBB, ExitBB->begin());
16861692
return NewLoaded;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
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(
66
; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[PTR:%.*]], align 4
77
; CHECK-NEXT: br label [[ATOMICRMW_START:%.*]]
@@ -14,7 +14,7 @@ define float @test_atomicrmw_fadd_f32(ptr %ptr, float %value) {
1414
; CHECK-NEXT: [[SUCCESS:%.*]] = extractvalue { i32, i1 } [[TMP4]], 1
1515
; CHECK-NEXT: [[NEWLOADED:%.*]] = extractvalue { i32, i1 } [[TMP4]], 0
1616
; CHECK-NEXT: [[TMP5]] = bitcast i32 [[NEWLOADED]] to float
17-
; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]]
17+
; CHECK-NEXT: br i1 [[SUCCESS]], label [[ATOMICRMW_END:%.*]], label [[ATOMICRMW_START]], !prof [[PROF1:![0-9]+]]
1818
; CHECK: atomicrmw.end:
1919
; CHECK-NEXT: ret float [[TMP5]]
2020
;
@@ -336,3 +336,11 @@ define <2 x half> @atomicrmw_fminimum_2_x_half(ptr %ptr, <2 x half> %val) {
336336
%res = atomicrmw fminimum ptr %ptr, <2 x half> %val seq_cst
337337
ret <2 x half> %res
338338
}
339+
340+
!0 = !{!"function_entry_count", i64 1000}
341+
;.
342+
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
343+
;.
344+
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
345+
; CHECK: [[PROF1]] = !{!"unknown", !"atomic-expand"}
346+
;.

0 commit comments

Comments
 (0)