[llvm] [SamplePGO] Support -salvage-stale-profile without probes too (PR #86116)

Lei Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 20:12:07 PDT 2024


================
@@ -0,0 +1,231 @@
+; REQUIRES: x86_64-linux
+; REQUIRES: asserts
+; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/non-probe-stale-profile-matching.prof --salvage-stale-profile -S --debug-only=sample-profile,sample-profile-impl 2>&1 | FileCheck %s
+
+
+; CHECK: Run stale profile matching for main
+
+; CHECK: Callsite with callee:foo is matched from 3.12 to 6
+; CHECK: Callsite with callee:bar is matched from 4.13 to 7
+; CHECK: Callsite with callee:foo is matched from 7.14 to 8
+; CHECK: Callsite with callee:bar is matched from 8.15 to 9
+
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at x = internal global i32 1, align 4, !dbg !0
+
+; Function Attrs: nounwind uwtable
+define dso_local i32 @main() local_unnamed_addr #0 !dbg !49 !prof !55 {
+  call void @llvm.dbg.value(metadata i32 0, metadata !53, metadata !DIExpression()), !dbg !57
+  br label %1, !dbg !61
+
+1:                                                ; preds = %17, %0
+  %2 = phi i32 [ 0, %0 ], [ %28, %17 ]
+  call void @llvm.dbg.value(metadata i32 %2, metadata !53, metadata !DIExpression()), !dbg !57
+  %3 = load volatile i32, ptr @x, align 4, !dbg !65, !tbaa !66
+  call void @llvm.dbg.value(metadata i32 %2, metadata !70, metadata !DIExpression()), !dbg !76
+  call void @llvm.dbg.value(metadata i32 %3, metadata !75, metadata !DIExpression()), !dbg !76
+  %4 = urem i32 %2, 10, !dbg !81
+  %5 = icmp eq i32 %4, 0, !dbg !81
+  %6 = zext i1 %5 to i32, !dbg !82
+  %7 = add nsw i32 %3, %6, !dbg !82
+  %8 = call i32 @bar(i32 noundef %7) #4, !dbg !83, !prof !84
+  %9 = load volatile i32, ptr @x, align 4, !dbg !86, !tbaa !66
+  %10 = add nsw i32 %9, %8, !dbg !86
+  store volatile i32 %10, ptr @x, align 4, !dbg !86, !tbaa !66
+  %11 = load volatile i32, ptr @x, align 4, !dbg !87, !tbaa !66
+  %12 = call i32 @bar(i32 noundef %11) #4, !dbg !88, !prof !90
+  %13 = load volatile i32, ptr @x, align 4, !dbg !91, !tbaa !66
+  %14 = add nsw i32 %13, %12, !dbg !91
+  store volatile i32 %14, ptr @x, align 4, !dbg !91, !tbaa !66
+  %15 = load volatile i32, ptr @x, align 4, !dbg !92, !tbaa !66
+  %16 = icmp slt i32 %15, 0, !dbg !94
+  br i1 %16, label %30, label %17, !dbg !95, !prof !96
+
+17:                                               ; preds = %1
+  %18 = load volatile i32, ptr @x, align 4, !dbg !98, !tbaa !66
+  call void @llvm.dbg.value(metadata i32 %2, metadata !70, metadata !DIExpression()), !dbg !99
+  call void @llvm.dbg.value(metadata i32 %18, metadata !75, metadata !DIExpression()), !dbg !99
+  %19 = zext i1 %5 to i32, !dbg !103
+  %20 = add nsw i32 %18, %19, !dbg !103
+  %21 = call i32 @bar(i32 noundef %20) #4, !dbg !104, !prof !84
+  %22 = load volatile i32, ptr @x, align 4, !dbg !106, !tbaa !66
+  %23 = add nsw i32 %22, %21, !dbg !106
+  store volatile i32 %23, ptr @x, align 4, !dbg !106, !tbaa !66
+  %24 = load volatile i32, ptr @x, align 4, !dbg !107, !tbaa !66
+  %25 = call i32 @bar(i32 noundef %24) #4, !dbg !108, !prof !90
+  %26 = load volatile i32, ptr @x, align 4, !dbg !110, !tbaa !66
+  %27 = add nsw i32 %26, %25, !dbg !110
+  store volatile i32 %27, ptr @x, align 4, !dbg !110, !tbaa !66
+  %28 = add nuw nsw i32 %2, 1, !dbg !112
+  call void @llvm.dbg.value(metadata i32 %28, metadata !53, metadata !DIExpression()), !dbg !57
+  %29 = icmp eq i32 %28, 1000000, !dbg !114
+  br i1 %29, label %30, label %1, !dbg !61, !prof !116, !llvm.loop !117
+
+30:                                               ; preds = %17, %1
+  %31 = phi i32 [ 1, %1 ], [ 0, %17 ]
+  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !121
+  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 10, i32 0, i64 -1), !dbg !122
+  ret i32 %31, !dbg !122
+}
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
+declare void @llvm.pseudoprobe(i64, i64, i32, i64) #1
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
+define available_externally dso_local i32 @bar(i32 noundef %0) local_unnamed_addr #3 !dbg !123 !prof !128 {
+  call void @llvm.dbg.value(metadata i32 %0, metadata !127, metadata !DIExpression()), !dbg !129
+  call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !130
+  %2 = add nsw i32 %0, 1, !dbg !131
+  ret i32 %2, !dbg !132
+}
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
+attributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
+attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+attributes #3 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
+attributes #4 = { nounwind }
+
+!llvm.dbg.cu = !{!2, !7}
+!llvm.module.flags = !{!9, !10, !11, !12, !13, !14, !15, !16, !17}
+!llvm.ident = !{!46, !46}
+!llvm.pseudo_probe_desc = !{!47, !48}
----------------
wlei-llvm wrote:

Looks the IR is still built with pseudo-probe, but the profile is non-probe, which is a mismatch. Though it can work, but would it be better to use a non-probe IR? It might be confusing in the future if someone changes pseudo-probe features but it would break a non-probe-xxx.ll test. 

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


More information about the llvm-commits mailing list