Skip to content

[Codegen][CPU] Keep roundeven native where LLVM lowers it to instructions - #25219

Merged
AGindinson merged 3 commits into
iree-org:mainfrom
dimp-pl:llvmcpu-native-roundeven
Nov 9, 2026
Merged

AGindinson merged 3 commits into
iree-org:mainfrom
dimp-pl:llvmcpu-native-roundeven

Conversation

@dimp-pl

@dimp-pl dimp-pl commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

MathTransform has expanded math.roundeven into a software sequence on every target except ROCm and WebGPU since 68439a0 on every llvm-cpu target.

Most CPU targets actually have an intruction: FRINTN on AArch64, ROUNDPS/ROUNDPD on x86 with SSE4.1, FCVT on riscv64 with D extension.

Since math.roundeven affects a lot of float-to-int quantization cases, so it makes sense to use instructions and not software sequences wherever possible.

Tests:

  • New lit cases cover each target used in the check, also native integration tests were added
  • Numerical results are identical to before the change for f32 and f64, checked on x86, AArch64 (QEMU) and riscv64 hardware (SpacemiT K3).

Related issue: #12778.

Assisted-By: Claude Code

…tructions

MathTransform has expanded `math.roundeven` into a software sequence on every
target except ROCm and WebGPU since 68439a0 on every llvm-cpu target.

Most CPU targets actually have an intruction: FRINTN on AArch64,
ROUNDPS/ROUNDPD on x86 with SSE4.1, FCVT on riscv64 with D extension.

Since `math.roundeven` affects a lot of float-to-int quantization cases,
so it makes sense to use instructions and not software sequences wherever
possible.

Tests:
- New lit cases cover each target used in the check
- Numerical results are identical to before the change for f32 and f64,
  checked on x86, AArch64 (QEMU) and riscv64 hardware (SpacemiT K3).

Assisted-By: Claude Code

Signed-off-by: Zmicier Prybysh <[email protected]>

@AGindinson AGindinson 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.

Generally looks good, I'd suggest expanding testing coverage

Check the expanded sequence in the emulated math_transform cases, and
add
an end-to-end test under LLVMCPU/test that compiles roundeven for
aarch64,
x86-64 (SSE4.1, AVX2) and riscv64 (D, V) and checks the assembly for the
native instructions.

Signed-off-by: Zmicier Prybysh <[email protected]>

@AGindinson AGindinson 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, thank you!

@AGindinson
AGindinson enabled auto-merge (squash) November 9, 2026 08:56
@AGindinson
AGindinson merged commit 42d17d4 into iree-org:main Nov 9, 2026
55 checks passed
devtbi added a commit that referenced this pull request Nov 11, 2026
…arget (#25234)

The tests
- early_data_tiling.mlir, early_data_tiling_convolution.mlir,
early_data_tiling_dynamic.mlir, added in
#24969
- roundeven_native.mlir, added in
#25219 (also riscv64), compile for
aarch64.

byo_llvm.sh builds LLVM with only the X86 target, so iree-compile stops
with "createTargetMachine(...) failed" and the tests fail
linux_x64_clang_byollvm job.

Add these tests in the same way as
#25221: CMake adds them only if
iree_compiler_targeting_iree_arch() is true for their architecture.

Theaarch64 and riscv64 RUN lines move into *_aarch64.mlir and
*_riscv64.mlir files, which copy the IR.

ci-extra: linux_x64_clang_byollvm

---------

Signed-off-by: Tobias Fuchs <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@devtbi devtbi mentioned this pull request Nov 16, 2026
8 tasks done
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.

2 participants