[clang] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi for SamplePGO (PR #145957)

2025-06-26 Thread Nilanjana Basu via cfe-commits

https://github.com/nilanjana87 edited 
https://github.com/llvm/llvm-project/pull/145957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi for SamplePGO (PR #145957)

2025-06-26 Thread Nilanjana Basu via cfe-commits

https://github.com/nilanjana87 ready_for_review 
https://github.com/llvm/llvm-project/pull/145957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi for SamplePGO (PR #145957)

2025-06-26 Thread Nilanjana Basu via cfe-commits

https://github.com/nilanjana87 created 
https://github.com/llvm/llvm-project/pull/145957

- Enable -fsample-profile-use-profi flag by default for SamplePGO
- Add -fno_sample_profile_use_profi flag for opting out

>From f0893f3b64661fc5a6ab39e7bdcc86a9142221a1 Mon Sep 17 00:00:00 2001
From: Nilanjana Basu 
Date: Thu, 26 Jun 2025 11:54:14 -0700
Subject: [PATCH] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi
 for SamplePGO in clang

---
 clang/include/clang/Driver/Options.td|  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp|  3 ++-
 clang/test/Driver/pgo-sample-use-profi.c | 19 +--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0822df2640d23..ef6bcfe296a80 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1698,6 +1698,8 @@ def fsample_profile_use_profi : Flag<["-"], 
"fsample-profile-use-profi">,
basic block counts to branch probabilities to fix them by 
extended
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, 
Group;
+def fno_sample_profile_use_profi : Flag<["-"], "fno-sample-profile-use-profi">,
+   Group;
 def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group,
 Alias;
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8a18865b899d2..7898c0a6a899c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6283,7 +6283,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
   if (getLastProfileSampleUseArg(Args) &&
-  Args.hasArg(options::OPT_fsample_profile_use_profi)) {
+  Args.hasFlag(options::OPT_fsample_profile_use_profi,
+   options::OPT_fno_sample_profile_use_profi, true)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-sample-profile-use-profi");
   }
diff --git a/clang/test/Driver/pgo-sample-use-profi.c 
b/clang/test/Driver/pgo-sample-use-profi.c
index 0370d947ce590..9d7c7af983508 100644
--- a/clang/test/Driver/pgo-sample-use-profi.c
+++ b/clang/test/Driver/pgo-sample-use-profi.c
@@ -1,4 +1,19 @@
-/// Test if profi flat is enabled in frontend as user-facing feature.
-// RUN: %clang --target=x86_64 -c -fsample-profile-use-profi 
-fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
+/// Ensure that profi flag is enabled by default in frontend for SamplePGO
+
+// Target specific checks:
+// RUN: %clang --target=x86_64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 
| FileCheck %s
+// RUN: %clang --target=AArch64 -c -fprofile-sample-use=/dev/null -### %s 2>&1 
| FileCheck %s
+
+// Target agnostic checks:
+// RUN: %clang -c -fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
+// RUN: %clang -c -fsample-profile-use-profi -fprofile-sample-use=/dev/null 
-### %s 2>&1 | FileCheck %s
+// RUN: %clang -c -fno-sample-profile-use-profi -fsample-profile-use-profi 
-fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s
+
+// Cases where profi flag is disabled:
+// RUN: %clang -c -### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
+// RUN: %clang -c -fno-sample-profile-use-profi -fprofile-sample-use=/dev/null 
-### %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO-PROFI
+// RUN: %clang -c -fsample-profile-use-profi -fno-sample-profile-use-profi 
-fprofile-sample-use=/dev/null -### %s 2>&1 | FileCheck %s 
--check-prefixes=CHECK-NO-PROFI
+
 
 // CHECK: "-mllvm" "-sample-profile-use-profi"
+// CHECK-NO-PROFI-NOT: "-sample-profile-use-profi"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver][SamplePGO] Enable -fsample-profile-use-profi for SamplePGO (PR #145957)

2025-06-27 Thread Nilanjana Basu via cfe-commits

nilanjana87 wrote:

> We evaluated profi internally (at Google) last year. Our configuration uses 
> AutoFDO with [flow-sensitive discriminators 
> ](https://lists.llvm.org/pipermail/llvm-dev/2020-November/146694.html) 
> (FS-AFDO). We found slight regressions with this configuration and didn't 
> enable it for our workloads. With FS-AFDO we see performance improvements of 
> ~1%. Can you share your configuration and performance numbers?

Our configuration uses SamplePGO with non-FS discriminators. We experimented 
with some benchmarks & 2 real-world workloads. Our experiments show better perf 
gains for 9/13 cases with this flag enabled, with 3 of them showing > 1% extra 
gain. On the downside of using this flag, we have seen >1% net loss in perf. 
gain for 3 benchmarks. For the real-world use-cases, we typically see 7-11% 
perf gain with SamplePGO & ~1% improvement on top of that with this flag 
enabled.

My argument in favor of enabling this flag by default is that increasing 
coverage of samples is ideally a good thing. If increased coverage shows 
reduced performance, then that can be addressed separately by disabling this 
flag for those particular cases. Empirically too, we see more cases with wins 
than losses on enabling this by default.

https://github.com/llvm/llvm-project/pull/145957
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits