[all-commits] [llvm/llvm-project] a93060: [WebAssembly] Select relaxed_trunc for vector fpto...
Gauarv Chaudhary via All-commits
all-commits at lists.llvm.org
Fri Sep 11 10:38:30 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a930601b854d881876a1b953f05f8632ade87304
https://github.com/llvm/llvm-project/commit/a930601b854d881876a1b953f05f8632ade87304
Author: Gauarv Chaudhary <137998824+ANAMASGARD at users.noreply.github.com>
Date: 2026-09-11 (Fri, 11 Sep 2026)
Changed paths:
M llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
A llvm/test/CodeGen/WebAssembly/simd-relaxed-fptoint.ll
Log Message:
-----------
[WebAssembly] Select relaxed_trunc for vector fptosi/fptoui with +relaxed-simd (#214148)
Fixes #211273
When `+relaxed-simd` is enabled, plain vector `fptosi`/`fptoui` from `<4
x float>` to `<4 x i32>` is still lowered to
`i32x4.trunc_sat_f32x4_{s,u}`. The relaxed SIMD instructions already
exist in the backend, but they were only wired to the
WebAssembly-specific `llvm.wasm.relaxed.trunc.*` intrinsics—not to
generic `fptosi`/`fptoui` IR.
This matters for frontends like LDC that emit ordinary `fptosi` for SIMD
casts (e.g. `_mm_cvttps_epi32`-style code). With
`+simd128,+relaxed-simd`, we should prefer
`i32x4.relaxed_trunc_f32x4_{s,u}`, which typically lowers more
efficiently
on native SIMD hardware.
The fix adds two TableGen selection patterns in
`WebAssemblyInstrSIMD.td`, gated on `HasRelaxedSIMD` with
`AddedComplexity = 1`, so they win over the existing
`fp_to_sint`/`fp_to_uint` → `trunc_sat` patterns when relaxed SIMD is
available.
This does not require fast-math: for representable inputs, relaxed
truncation matches LLVM semantics; for NaN/out-of-range inputs,
`fptosi`/`fptoui` already produce poison, so the backend is not required
to preserve `trunc_sat`'s
saturating behavior.
Explicit saturating conversions (`llvm.fptosi.sat` / `fp_to_sint_sat`)
and `+simd128`-only targets are unchanged.
## Test plan
- [x] `llvm-lit llvm/test/CodeGen/WebAssembly/simd-relaxed-fptoint.ll`
- [x] `llvm-lit llvm/test/CodeGen/WebAssembly/simd-conversions.ll`
- [x] `llvm-lit llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll`
Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004 at gmail.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list