Skip to content

[LLVMCPU] strip per-function target attributes to allow inlining ukernels - #24833

Merged
AGindinson merged 1 commit into
iree-org:mainfrom
egebeysel:egb.strip_ukernel_features
Aug 22, 2026
Merged

AGindinson merged 1 commit into
iree-org:mainfrom
egebeysel:egb.strip_ukernel_features

Conversation

@egebeysel

@egebeysel egebeysel commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

The ukernel bitcode carries per-function target-cpu/tune-cpu/target-features attributes that conflict with the attribute-less dispatch (which inherits the module-level TargetMachine) and stop LLVM from inlining the ukernel. Strip them (and vscale_range, so RVV bitcode inlines) at link time.

Fixes #24755.

Assisted-by: Claude Code

…ning

The ukernel bitcode carries per-function target-cpu/tune-cpu/target-features
attributes that conflict with the attribute-less dispatch (which inherits the
module-level TargetMachine)and stop LLVM from inlining the ukernel. Strip
them (and vscale_range, so RVV bitcode inlines) at link time.

Co-Authored-By: Stefan Schuermans <[email protected]>
Co-Authored-By: Federico Bruzzone <[email protected]>
Signed-off-by: Ege Beysel <[email protected]>
@egebeysel egebeysel changed the title [LLVMCPU]Strip per-function target attributes to allow inlining ukernels [LLVMCPU] strip per-function target attributes to allow inlining ukernels Aug 21, 2026
for (auto &func : module.get()->functions()) {
func.addFnAttr(llvm::Attribute::AlwaysInline);
stripFunctionTargetAttrs(func);
func.removeFnAttr(llvm::Attribute::VScaleRange);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is known from RISC-V target properties too, right? Or unneeded whatsoever?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's known, but it's unneeded on the ukernel here. the target properties will have a user-specified value in a future PR of mine, but they currently get the same default (unless the specific llvm flags are passed).

@phemashekar phemashekar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@FedericoBruzzone FedericoBruzzone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super clean, LGTM @egebeysel!

P.S. Thanks for co-authoring it with me too 🙏

@AGindinson
AGindinson merged commit ee89ff3 into iree-org:main Aug 22, 2026
83 of 85 checks passed
devtbi added a commit to devtbi/iree that referenced this pull request Nov 9, 2026
ukernel_inlining.mlir, added in iree-org#24833, compiles for aarch64 and
riscv64, but byo_llvm.sh builds LLVM with only the X86 target. The test
has failed the scheduled linux_x64_clang_byollvm job since iree-org#24833
landed. Since 2026-10-26 that job fails earlier, while configuring LLVM.

Move the aarch64 and riscv64 RUN lines into their own tests, tag them
with the LLVM target they need, and exclude those tags in
build_and_test_byo_llvm.sh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Tobias Fuchs <[email protected]>
devtbi added a commit that referenced this pull request Nov 9, 2026
…25221)

ukernel_inlining.mlir, added in
#24833, compiles for aarch64 and
riscv64, but byo_llvm.sh builds LLVM with only the X86 target. The test
has failed the scheduled linux_x64_clang_byollvm job since
#24833
landed.

Move the aarch64 and riscv64 RUN lines into their own tests. CMake adds
these tests only if iree_compiler_targeting_iree_arch() is true for
their
architecture. The same check decides whether CMake builds the ukernel
bitcode for the architecture. Without the LLVM target, CMake writes an
empty bitcode file instead, so the tests cannot pass in such a build.
The Bazel build always has these targets.

The aarch64 RUN lines also crashed iree-compile:
populateDefaultsFromTargetMachine only asserted that LLVM could create
the target machine, so builds without assertions dereferenced a null
pointer. It now reports a fatal usage error.

---------

Signed-off-by: Tobias Fuchs <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LLVMCPU] C microkernels do not get inlined after 7bdca287 (target-feature mismatch)

4 participants