Files
clang-p2996/llvm/test/Transforms/PGOProfile/instrprof_simple_sampling.ll
xur-llvm b1ca2a9546 [PGO] Sampled instrumentation in PGO to speed up instrumentation binary (#69535)
In comparison to non-instrumented binaries, PGO instrumentation binaries
can be significantly slower. For highly threaded programs, this slowdown
can
reach 10x due to data races or false sharing within counters.

This patch incorporates sampling into the PGO instrumentation process to
enhance the speed of instrumentation binaries. The fundamental concept
is similar to the one proposed in https://reviews.llvm.org/D63949.

Three sampling modes are introduced:
1. Simple Sampling: When '-sampled-instr-bust-duration' is set to 1.
2. Fast Burst Sampling: When not using simple sampling, and 
'-sampled-instr-period' is set to 65535. This is the default mode of
sampling.
3. Full Burst Sampling: When neither simple nor fast burst sampling is
used.

Utilizing this sampled instrumentation significantly improves the
binary's
execution speed. Measurements show up to 5x speedup with default
settings. Fast burst sampling now results in only around 20% to 30%
slowdown (compared to 8 to 10x slowdown without sampling).

Out tests show that profile quality remains good with sampling,
with edge counts typically showing more than 90% overlap.
For applications whose behavior changes due to binary speed,
sampling instrumentation can enhance performance.
Observations have shown some apps experiencing up to
a ~2% improvement in PGO.

A potential drawback of this patch is the increased binary size
and compilation time. The Sampling method in this patch does
not improve single threaded program instrumentation binary
speed.
2024-07-22 09:19:17 -07:00

61 lines
2.9 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s --passes=instrprof --sampled-instrumentation --sampled-instr-burst-duration=1 --sampled-instr-period=1009 -S | FileCheck %s --check-prefix=PERIOD1009
; RUN: opt < %s --passes=instrprof --sampled-instrumentation --sampled-instr-burst-duration=1 -S | FileCheck %s --check-prefix=DEFAULTPERIOD
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
$__llvm_profile_raw_version = comdat any
@__llvm_profile_raw_version = constant i64 72057594037927940, comdat
@__profn_f = private constant [1 x i8] c"f"
define void @f() {
; PERIOD1009-LABEL: define void @f() {
; PERIOD1009-NEXT: [[ENTRY:.*:]]
; PERIOD1009-NEXT: [[TMP0:%.*]] = load i16, ptr @__llvm_profile_sampling, align 2
; PERIOD1009-NEXT: [[TMP1:%.*]] = add i16 [[TMP0]], 1
; PERIOD1009-NEXT: [[TMP2:%.*]] = icmp uge i16 [[TMP1]], 1009
; PERIOD1009-NEXT: br i1 [[TMP2]], label %[[BB3:.*]], label %[[BB5:.*]], !prof [[PROF0:![0-9]+]]
; PERIOD1009: [[BB3]]:
; PERIOD1009-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_f, align 8
; PERIOD1009-NEXT: [[TMP4:%.*]] = add i64 [[PGOCOUNT]], 1
; PERIOD1009-NEXT: store i64 [[TMP4]], ptr @__profc_f, align 8
; PERIOD1009-NEXT: store i16 0, ptr @__llvm_profile_sampling, align 2
; PERIOD1009-NEXT: br label %[[BB6:.*]]
; PERIOD1009: [[BB5]]:
; PERIOD1009-NEXT: store i16 [[TMP1]], ptr @__llvm_profile_sampling, align 2
; PERIOD1009-NEXT: br label %[[BB6]]
; PERIOD1009: [[BB6]]:
; PERIOD1009-NEXT: ret void
;
; DEFAULTPERIOD-LABEL: define void @f() {
; DEFAULTPERIOD-NEXT: [[ENTRY:.*:]]
; DEFAULTPERIOD-NEXT: [[TMP0:%.*]] = load i16, ptr @__llvm_profile_sampling, align 2
; DEFAULTPERIOD-NEXT: [[TMP1:%.*]] = add i16 [[TMP0]], 1
; DEFAULTPERIOD-NEXT: [[TMP2:%.*]] = icmp uge i16 [[TMP1]], -1
; DEFAULTPERIOD-NEXT: br i1 [[TMP2]], label %[[BB3:.*]], label %[[BB5:.*]], !prof [[PROF0:![0-9]+]]
; DEFAULTPERIOD: [[BB3]]:
; DEFAULTPERIOD-NEXT: [[PGOCOUNT:%.*]] = load i64, ptr @__profc_f, align 8
; DEFAULTPERIOD-NEXT: [[TMP4:%.*]] = add i64 [[PGOCOUNT]], 1
; DEFAULTPERIOD-NEXT: store i64 [[TMP4]], ptr @__profc_f, align 8
; DEFAULTPERIOD-NEXT: store i16 0, ptr @__llvm_profile_sampling, align 2
; DEFAULTPERIOD-NEXT: br label %[[BB6:.*]]
; DEFAULTPERIOD: [[BB5]]:
; DEFAULTPERIOD-NEXT: store i16 [[TMP1]], ptr @__llvm_profile_sampling, align 2
; DEFAULTPERIOD-NEXT: br label %[[BB6]]
; DEFAULTPERIOD: [[BB6]]:
; DEFAULTPERIOD-NEXT: ret void
;
entry:
call void @llvm.instrprof.increment(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__profn_f, i32 0, i32 0), i64 12884901887, i32 1, i32 0)
ret void
}
declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
;.
; PERIOD1009: [[PROF0]] = !{!"branch_weights", i32 1, i32 1009}
;.
; DEFAULTPERIOD: [[PROF0]] = !{!"branch_weights", i32 1, i32 65535}
;.