[Mlir-commits] [mlir] [mlir][spirv][vector] Use adaptor.getElements() in FromElements lowering. (PR #156972)
Han-Chung Wang
llvmlistbot at llvm.org
Thu Sep 4 14:56:14 PDT 2025
https://github.com/hanhanW created https://github.com/llvm/llvm-project/pull/156972
None
>From 23f1aa4fd3d2cd9449da4258b46dd3dfcdfa94a6 Mon Sep 17 00:00:00 2001
From: hanhanW <hanhan0912 at gmail.com>
Date: Thu, 4 Sep 2025 14:54:54 -0700
Subject: [PATCH] [mlir][spirv][vector] Use adaptor.getElements() in
FromElements lowering.
Signed-off-by: hanhanW <hanhan0912 at gmail.com>
---
.../VectorToSPIRV/VectorToSPIRV.cpp | 2 +-
.../VectorToSPIRV/vector-to-spirv.mlir | 25 ++++++++++++++-----
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 036cbad0bcfe8..c861935b4bc18 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -278,7 +278,7 @@ struct VectorFromElementsOpConvert final
Type resultType = getTypeConverter()->convertType(op.getType());
if (!resultType)
return failure();
- OperandRange elements = op.getElements();
+ ValueRange elements = adaptor.getElements();
if (isa<spirv::ScalarType>(resultType)) {
// In the case with a single scalar operand / single-element result,
// pass through the scalar.
diff --git a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
index 4b56897821dbb..c3688e0657d4b 100644
--- a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
+++ b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
@@ -281,33 +281,46 @@ func.func @to_elements_dead_elements(%a: vector<4xf32>) -> (f32, f32) {
// -----
-// CHECK-LABEL: @from_elements_0d
+// CHECK-LABEL: @from_elements_0d_f32
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK: %[[RETVAL:.+]] = builtin.unrealized_conversion_cast %[[ARG0]]
// CHECK: return %[[RETVAL]]
-func.func @from_elements_0d(%arg0 : f32) -> vector<f32> {
+func.func @from_elements_0d_f32(%arg0 : f32) -> vector<f32> {
%0 = vector.from_elements %arg0 : vector<f32>
return %0: vector<f32>
}
-// CHECK-LABEL: @from_elements_1x
+// CHECK-LABEL: @from_elements_1xf32
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK: %[[RETVAL:.+]] = builtin.unrealized_conversion_cast %[[ARG0]]
// CHECK: return %[[RETVAL]]
-func.func @from_elements_1x(%arg0 : f32) -> vector<1xf32> {
+func.func @from_elements_1xf32(%arg0 : f32) -> vector<1xf32> {
%0 = vector.from_elements %arg0 : vector<1xf32>
return %0: vector<1xf32>
}
-// CHECK-LABEL: @from_elements_3x
+// CHECK-LABEL: @from_elements_3xf32
// CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32, %[[ARG2:.+]]: f32
// CHECK: %[[RETVAL:.+]] = spirv.CompositeConstruct %[[ARG0]], %[[ARG1]], %[[ARG2]] : (f32, f32, f32) -> vector<3xf32>
// CHECK: return %[[RETVAL]]
-func.func @from_elements_3x(%arg0 : f32, %arg1 : f32, %arg2 : f32) -> vector<3xf32> {
+func.func @from_elements_3xf32(%arg0 : f32, %arg1 : f32, %arg2 : f32) -> vector<3xf32> {
%0 = vector.from_elements %arg0, %arg1, %arg2 : vector<3xf32>
return %0: vector<3xf32>
}
+func.func @from_elements_3xi8(%arg0 : i8, %arg1 : i8, %arg2 : i8) -> vector<3xi8> {
+ %0 = vector.from_elements %arg0, %arg1, %arg2 : vector<3xi8>
+ return %0: vector<3xi8>
+}
+// CHECK-LABEL: @from_elements_3xi8
+// CHECK-SAME: %[[ARG0:.+]]: i8, %[[ARG1:.+]]: i8, %[[ARG2:.+]]: i8
+// CHECK-DAG: %[[CAST0:.*]] = builtin.unrealized_conversion_cast %[[ARG0]] : i8 to i32
+// CHECK-DAG: %[[CAST1:.*]] = builtin.unrealized_conversion_cast %[[ARG1]] : i8 to i32
+// CHECK-DAG: %[[CAST2:.*]] = builtin.unrealized_conversion_cast %[[ARG2]] : i8 to i32
+// CHECK: %[[VAL:.+]] = spirv.CompositeConstruct %[[CAST0]], %[[CAST1]], %[[CAST2]] : (i32, i32, i32) -> vector<3xi32>
+// CHECK: %[[RETVAL:.*]] = builtin.unrealized_conversion_cast %[[VAL]] : vector<3xi32> to vector<3xi8>
+// CHECK: return %[[RETVAL]]
+
// -----
// CHECK-LABEL: @insert
More information about the Mlir-commits
mailing list