[llvm] [SPIR-V] Legalize vector arithmetic and intrinsics for large vectors (PR #170668)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 11:56:57 PST 2025
================
@@ -0,0 +1,149 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-DAG: OpName %[[#main:]] "main"
+; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
+; CHECK-DAG: %[[#v4f32:]] = OpTypeVector %[[#float]] 4
+; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0
+; CHECK-DAG: %[[#c16:]] = OpConstant %[[#int]] 16
+; CHECK-DAG: %[[#v16f32:]] = OpTypeArray %[[#float]] %[[#c16]]
+; CHECK-DAG: %[[#v16i32:]] = OpTypeArray %[[#int]] %[[#c16]]
+; CHECK-DAG: %[[#ptr_ssbo_v16i32:]] = OpTypePointer Private %[[#v16i32]]
+; CHECK-DAG: %[[#v4i32:]] = OpTypeVector %[[#int]] 4
+
+ at f1 = internal addrspace(10) global [4 x [16 x float] ] zeroinitializer
+ at f2 = internal addrspace(10) global [4 x [16 x float] ] zeroinitializer
+ at i1 = internal addrspace(10) global [4 x [16 x i32] ] zeroinitializer
+ at i2 = internal addrspace(10) global [4 x [16 x i32] ] zeroinitializer
+
+define void @main() local_unnamed_addr #0 {
+; CHECK: %[[#main]] = OpFunction
+entry:
+ %2 = getelementptr [4 x [16 x float] ], ptr addrspace(10) @f1, i32 0, i32 0
+ %3 = load <16 x float>, ptr addrspace(10) %2, align 4
+ %4 = getelementptr [4 x [16 x float] ], ptr addrspace(10) @f1, i32 0, i32 1
+ %5 = load <16 x float>, ptr addrspace(10) %4, align 4
+ %6 = getelementptr [4 x [16 x float] ], ptr addrspace(10) @f1, i32 0, i32 2
+ %7 = load <16 x float>, ptr addrspace(10) %6, align 4
+ %8 = getelementptr [4 x [16 x float] ], ptr addrspace(10) @f1, i32 0, i32 3
+ %9 = load <16 x float>, ptr addrspace(10) %8, align 4
+
+ ; We expect the large vectors to be split into size 4, and the operations performed on them.
+ ; CHECK: OpFMul %[[#v4f32]]
+ ; CHECK: OpFMul %[[#v4f32]]
+ ; CHECK: OpFMul %[[#v4f32]]
+ ; CHECK: OpFMul %[[#v4f32]]
+ %10 = fmul reassoc nnan ninf nsz arcp afn <16 x float> %3, splat (float 3.000000e+00)
----------------
farzonl wrote:
I think it might be good to add some tests for arithmetic operations where the vector chunks don't fit neatly into the same size vector. What about a Vector of size 6. Does that get split into two OpFmul of size 3 or one size 4 and one size 2?
https://github.com/llvm/llvm-project/pull/170668
More information about the llvm-commits
mailing list