Debian Codegraph @

llvm/test/CodeGen/SPIRV/llvm-intrinsics/matrix-transpose.ll

raw
1 ; RUN: llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3 %s -o - | FileCheck %s
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3 %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3
4 @private_v4f32 = internal addrspace(10) global [4 x float] poison
5 @private_v6f32 = internal addrspace(10) global [6 x float] poison
6 @private_v1f32 = internal addrspace(10) global [1 x float] poison
7
8 ; CHECK-DAG: %[[Float_ID:[0-9]+]] = OpTypeFloat 32
9 ; CHECK-DAG: %[[V4F32_ID:[0-9]+]] = OpTypeVector %[[Float_ID]] 4
10
11 ; Test Transpose 2x2 float
12 ; CHECK-LABEL: ; -- Begin function test_transpose_f32_2x2
13 ; CHECK: %[[Shuffle:[0-9]+]] = OpVectorShuffle %[[V4F32_ID]] {{.*}} 0 2 1 3
14 define internal void @test_transpose_f32_2x2() {
15 %1 = load <4 x float>, ptr addrspace(10) @private_v4f32
16 %2 = call <4 x float> @llvm.matrix.transpose.v4f32.i32(<4 x float> %1, i32 2, i32 2)
17 store <4 x float> %2, ptr addrspace(10) @private_v4f32
18 ret void
19 }
20
21 ; Test Transpose 2x3 float (Result is 3x2 float)
22 ; Note: We should add more code to the prelegalizer combiner to be able to remove the insert and extracts.
23 ; This test should reduce to a series of access chains, loads, and stores.
24 ; CHECK-LABEL: ; -- Begin function test_transpose_f32_2x3
25 define internal void @test_transpose_f32_2x3() {
26 ; -- Load input 2x3 matrix elements
27 ; CHECK: %[[AccessChain1:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID:[0-9]+]] %[[private_v6f32:[0-9]+]] %[[int_0:[0-9]+]]
28 ; CHECK: %[[Load1:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain1]]
29 ; CHECK: %[[AccessChain2:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_1:[0-9]+]]
30 ; CHECK: %[[Load2:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain2]]
31 ; CHECK: %[[AccessChain3:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_2:[0-9]+]]
32 ; CHECK: %[[Load3:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain3]]
33 ; CHECK: %[[AccessChain4:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_3:[0-9]+]]
34 ; CHECK: %[[Load4:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain4]]
35 ; CHECK: %[[AccessChain5:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_4:[0-9]+]]
36 ; CHECK: %[[Load5:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain5]]
37 ; CHECK: %[[AccessChain6:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_5:[0-9]+]]
38 ; CHECK: %[[Load6:[0-9]+]] = OpLoad %[[Float_ID]] %[[AccessChain6]]
39 ;
40 ; -- Construct intermediate vectors
41 ; CHECK: %[[Construct1:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load1]] %[[Load2]] %[[Load3]] %[[Load4]]
42 ; CHECK: %[[Construct2:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load1]] %[[Load2]] %[[Load3]] %[[Load4]]
43 ; CHECK: %[[Construct3:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load5]] %[[Load6]] {{.*}} {{.*}}
44 ; CHECK: %[[Construct4:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load1]] %[[Load2]] %[[Load3]] %[[Load4]]
45 ; CHECK: %[[Construct5:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load1]] %[[Load2]] %[[Load3]] %[[Load4]]
46 ; CHECK: %[[Construct6:[0-9]+]] = OpCompositeConstruct %[[V4F32_ID]] %[[Load5]] %[[Load6]] {{.*}} {{.*}}
47 %1 = load <6 x float>, ptr addrspace(10) @private_v6f32
48
49 ; -- Extract elements for transposition
50 ; CHECK: %[[Extract1:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct1]] 0
51 ; CHECK: %[[Extract2:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct2]] 2
52 ; CHECK: %[[Extract3:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct3]] 0
53 ; CHECK: %[[Extract4:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct4]] 1
54 ; CHECK: %[[Extract5:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct5]] 3
55 ; CHECK: %[[Extract6:[0-9]+]] = OpCompositeExtract %[[Float_ID]] %[[Construct6]] 1
56 %2 = call <6 x float> @llvm.matrix.transpose.v6f32.i32(<6 x float> %1, i32 2, i32 3)
57
58 ; -- Store output 3x2 matrix elements
59 ; CHECK: %[[AccessChain7:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_0]]
60 ; CHECK: OpStore %[[AccessChain7]] %[[Extract1]]
61 ; CHECK: %[[AccessChain8:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_1]]
62 ; CHECK: OpStore %[[AccessChain8]] %[[Extract2]]
63 ; CHECK: %[[AccessChain9:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_2]]
64 ; CHECK: OpStore %[[AccessChain9]] %[[Extract3]]
65 ; CHECK: %[[AccessChain10:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_3]]
66 ; CHECK: OpStore %[[AccessChain10]] %[[Extract4]]
67 ; CHECK: %[[AccessChain11:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_4]]
68 ; CHECK: OpStore %[[AccessChain11]] %[[Extract5]]
69 ; CHECK: %[[AccessChain12:[0-9]+]] = OpAccessChain %[[_ptr_Float_ID]] %[[private_v6f32]] %[[int_5]]
70 ; CHECK: OpStore %[[AccessChain12]] %[[Extract6]]
71 store <6 x float> %2, ptr addrspace(10) @private_v6f32
72 ret void
73 }
74
75 ; Test Transpose 1x4 float (Result is 4x1 float), should be a copy (vector of 4 floats)
76 ; CHECK-LABEL: ; -- Begin function test_transpose_f32_1x4_to_4x1
77 ; CHECK: %[[Shuffle:[0-9]+]] = OpVectorShuffle %[[V4F32_ID]] {{.*}} 0 1 2 3
78 define internal void @test_transpose_f32_1x4_to_4x1() {
79 %1 = load <4 x float>, ptr addrspace(10) @private_v4f32
80 %2 = call <4 x float> @llvm.matrix.transpose.v4f32.i32(<4 x float> %1, i32 1, i32 4)
81 store <4 x float> %2, ptr addrspace(10) @private_v4f32
82 ret void
83 }
84
85 ; Test Transpose 4x1 float (Result is 1x4 float), should be a copy (vector of 4 floats)
86 ; CHECK-LABEL: ; -- Begin function test_transpose_f32_4x1_to_1x4
87 ; CHECK: %[[Shuffle:[0-9]+]] = OpVectorShuffle %[[V4F32_ID]] {{.*}} 0 1 2 3
88 define internal void @test_transpose_f32_4x1_to_1x4() {
89 %1 = load <4 x float>, ptr addrspace(10) @private_v4f32
90 %2 = call <4 x float> @llvm.matrix.transpose.v4f32.i32(<4 x float> %1, i32 4, i32 1)
91 store <4 x float> %2, ptr addrspace(10) @private_v4f32
92 ret void
93 }
94
95 ; Test Transpose 1x1 float (Result is 1x1 float), should be a copy (scalar float)
96 ; TODO(171175): The SPIR-V backend does not seem to be legalizing single element vectors.
97 ; define internal void @test_transpose_f32_1x1() {
98 ; %1 = load <1 x float>, ptr addrspace(10) @private_v1f32
99 ; %2 = call <1 x float> @llvm.matrix.transpose.v1f32.i32(<1 x float> %1, i32 1, i32 1)
100 ; store <1 x float> %2, ptr addrspace(10) @private_v1f32
101 ; ret void
102 ; }
103
104 define void @main() #0 {
105 ret void
106 }
107
108 declare <4 x float> @llvm.matrix.transpose.v4f32.i32(<4 x float>, i32, i32)
109 declare <6 x float> @llvm.matrix.transpose.v6f32.i32(<6 x float>, i32, i32)
110 ; declare <1 x float> @llvm.matrix.transpose.v1f32.i32(<1 x float>, i32, i32)
111
112 attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }