From: Jenhao Chen <jenhaochen@google.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
Rong Xu <xur@google.com>, Han Shen <shenhan@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nicolas Schier" <nsc@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Maurer" <mmaurer@google.com>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Qais Yousef" <qyousef@google.com>, "Ben Wei" <benwei@google.com>,
rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org,
"Jenhao Chen" <jenhaochen@google.com>
Subject: Re: [PATCH] kbuild: rust: pass AutoFDO flags to Clang with inline helpers
Date: Fri, 13 Nov 2026 08:28:37 +0000 [thread overview]
Message-ID: <20261113082837.4011638-1-jenhaochen@google.com> (raw)
In-Reply-To: <CANiq72=zg8WeupV5TPTr2tUxAt7imSZXacw=CBf75MdfcAv-rA@mail.gmail.com>
On Wed, Nov 11, 2026 at 7:48 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> This sounds reasonable, but my LLM spotted that Clang will run
> `AddDiscriminatorsPass` again, i.e. on the optimized bitcode that
> `rustc` produced. So the profile ends up indexed by Clang's renumbered
> discriminators, and then the build that uses the profile will not find
> a match for some code (depending on inlining decisions), i.e. that
> part of the profile is silently dropped.
>
> It proposes `-mllvm -no-discriminators` in
> `CC_FLAGS_RUST_INLINE_HELPERS` so that Clang doesn't add them, i.e.
> using the `rustc` ones.
>
> Rong, Han: is that expected?
Hi Miguel,
Nice catch -- I tested this on drivers/android/binder/rust_binder_main.o
(arm64, Clang 22 + rustc 1.91) and confirmed that the duplicate
AddDiscriminatorsPass run is real and that passing
`-mllvm -no-discriminators` to the post-llvm-link $(CC) step improves
profile matching in both stages:
1. Why the second AddDiscriminatorsPass renumbers discriminators:
In Stage 1, rustc runs AddDiscriminatorsPass on pre-inlining IR and
then runs its optimization/inlining pipeline before emitting .bc.
When post-llvm-link $(CC) runs AddDiscriminatorsPass again on the
already-inlined .m.bc, llvm/lib/Transforms/Utils/AddDiscriminators.cpp
keys blocks by (filename, line) without checking inlinedAt and
overwrites existing base discriminators via
cloneWithBaseDiscriminator(). On rust_binder_main.o, that second pass
increases non-zero DWARF .debug_line discriminator rows from 6,245 to
9,313 (+3,068 rows, +49%).
In the profile-use build, rustc's SampleProfileLoaderPass runs before
rustc's inliner (against pre-inlining discriminators), while Stage 3
sees a different post-inlining CFG once Stage 1 has applied the
profile.
2. Measured round-trip impact (42 sampled functions in
rust_binder_main.o):
- Stage 1 (rustc -Zprofile-sample-use): annotated branch_weights
increase from 454 to 490 (+7.9%) when the profile is generated and
used with `-mllvm -no-discriminators` in Stage 3.
- Stage 3 ($(CC) -fprofile-sample-use): SampleProfileLoader record
coverage increases from 39.3% (2,832 / 7,205) to 54.0%
(3,707 / 6,860, +14.7 percentage points), and sample coverage
increases from 42.9% (757.8K / 1,767.6K) to 56.4%
(989.6K / 1,753.4K, +13.6 percentage points; 969 -> 1,035
branch_weights). Against a hardware ETM profile, Stage 3 matched
function entry counts also increase by +33.9%.
3. Side-effect checks:
- C helpers: rust/helpers/helpers*.bc is compiled separately via
cmd_rust_helper (without CC_FLAGS_RUST_INLINE_HELPERS), so C
helpers still get their pre-inlining base discriminators before
llvm-link.
- Flow-sensitive discriminators: MIRAddFSDiscriminators in
llvm/lib/CodeGen/MIRFSDiscriminator.cpp checks
EnableFSDiscriminator and shouldEmitDebugInfoForProfiling() rather
than NoDiscriminators, so post-link FS discriminators remain
enabled.
Rong, Han, Miguel, Nathan: would you prefer adding
`-mllvm -no-discriminators` directly to `CC_FLAGS_RUST_INLINE_HELPERS`
in the top-level Makefile, or appending it in scripts/Makefile.autofdo
under `ifdef CONFIG_RUST_INLINE_HELPERS`? Happy to send v2 once we align
on the preferred spot.
Thanks,
Jenhao
prev parent reply other threads:[~2026-11-13 8:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 3:08 Jenhao Chen
2026-11-06 2:42 ` Nathan Chancellor
2026-11-11 18:48 ` Miguel Ojeda
2026-11-13 8:28 ` Jenhao Chen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113082837.4011638-1-jenhaochen@google.com \
--to=jenhaochen@google.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=benwei@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=jpoimboe@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=lossin@kernel.org \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=mmaurer@google.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=qyousef@google.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=shenhan@google.com \
--cc=tmgross@umich.edu \
--cc=xur@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®