[llvm] [WebAssembly] Fix v8i16-to-v8f32 uitofp cost (PR #212501)
Anutosh Bhat via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 07:01:55 PDT 2026
https://github.com/anutosh491 created https://github.com/llvm/llvm-project/pull/212501
I think there was a wrong duplication here. The WebAssembly SIMD conversion cost table accidentally duplicated the
`UINT_TO_FP` entry for `v8i8` to `v8f32`. As a result, the unsigned `v8i16` to `v8f32` conversion missed the target-specific table entry and fell back to the generic cost of 5 instead of the intended cost of 10.
I've added `llvm-lit llvm/test/Analysis/CostModel/WebAssembly/cast.ll` which I think is good here as it would help test other casting errors in the future too.
>From 3c17f271f611cb551fbecf67f81506dc8b3572c0 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Tue, 28 Jul 2026 19:29:07 +0530
Subject: [PATCH] [WebAssembly] Fix v8i16-to-v8f32 uitofp cost
---
.../WebAssemblyTargetTransformInfo.cpp | 2 +-
llvm/test/Analysis/CostModel/WebAssembly/cast.ll | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Analysis/CostModel/WebAssembly/cast.ll
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
index 7249d54cc7a9f..7d1136bb9beba 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
@@ -204,7 +204,7 @@ InstructionCost WebAssemblyTTIImpl::getCastInstrCost(
{ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i8, 10},
{ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 10},
{ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 10},
- {ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i8, 10},
+ {ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 10},
/// trunc_sat, const, and, 3x narrow
{ISD::FP_TO_SINT, MVT::v2i8, MVT::v2f32, 6},
{ISD::FP_TO_UINT, MVT::v2i8, MVT::v2f32, 6},
diff --git a/llvm/test/Analysis/CostModel/WebAssembly/cast.ll b/llvm/test/Analysis/CostModel/WebAssembly/cast.ll
new file mode 100644
index 0000000000000..6cedc370add06
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/WebAssembly/cast.ll
@@ -0,0 +1,16 @@
+; RUN: opt -mtriple=wasm32-unknown-unknown -mattr=+simd128 \
+; RUN: -passes='print<cost-model>' -disable-output < %s 2>&1 | FileCheck %s
+
+define <8 x float> @sitofp_v8i16(<8 x i16> %x) {
+; CHECK-LABEL: function 'sitofp_v8i16'
+; CHECK: estimated cost of 10 for instruction:
+ %result = sitofp <8 x i16> %x to <8 x float>
+ ret <8 x float> %result
+}
+
+define <8 x float> @uitofp_v8i16(<8 x i16> %x) {
+; CHECK-LABEL: function 'uitofp_v8i16'
+; CHECK: estimated cost of 10 for instruction:
+ %result = uitofp <8 x i16> %x to <8 x float>
+ ret <8 x float> %result
+}
\ No newline at end of file
More information about the llvm-commits
mailing list