Skip to content

Commit 4316112

Browse files
committed
Precommit tests for sinking vector ops
1 parent cf1cdde commit 4316112

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefix=OPT %s
3+
4+
; testing insert case
5+
define amdgpu_kernel void @runningSum(ptr addrspace(1) %out0, ptr addrspace(1) %out1, i32 %inputElement0, i32 %inputElement1, i32 %inputIter) {
6+
; OPT-LABEL: define amdgpu_kernel void @runningSum(
7+
; OPT-SAME: ptr addrspace(1) [[OUT0:%.*]], ptr addrspace(1) [[OUT1:%.*]], i32 [[INPUTELEMENT0:%.*]], i32 [[INPUTELEMENT1:%.*]], i32 [[INPUTITER:%.*]]) #[[ATTR0:[0-9]+]] {
8+
; OPT-NEXT: [[PREHEADER:.*]]:
9+
; OPT-NEXT: [[VECELEMENT0:%.*]] = insertelement <2 x i32> poison, i32 [[INPUTELEMENT0]], i64 0
10+
; OPT-NEXT: [[BROADCAST0:%.*]] = shufflevector <2 x i32> [[VECELEMENT0]], <2 x i32> poison, <2 x i32> zeroinitializer
11+
; OPT-NEXT: [[VECELEMENT1:%.*]] = insertelement <2 x i32> poison, i32 [[INPUTELEMENT1]], i64 0
12+
; OPT-NEXT: [[TMP0:%.*]] = shufflevector <2 x i32> [[VECELEMENT1]], <2 x i32> poison, <2 x i32> zeroinitializer
13+
; OPT-NEXT: br label %[[LOOPBODY:.*]]
14+
; OPT: [[LOOPBODY]]:
15+
; OPT-NEXT: [[PREVIOUSSUM:%.*]] = phi <2 x i32> [ [[TMP0]], %[[PREHEADER]] ], [ [[RUNNINGSUM:%.*]], %[[LOOPBODY]] ]
16+
; OPT-NEXT: [[ITERCOUNT:%.*]] = phi i32 [ [[INPUTITER]], %[[PREHEADER]] ], [ [[ITERSLEFT:%.*]], %[[LOOPBODY]] ]
17+
; OPT-NEXT: [[RUNNINGSUM]] = add <2 x i32> [[TMP0]], [[PREVIOUSSUM]]
18+
; OPT-NEXT: [[ITERSLEFT]] = sub i32 [[ITERCOUNT]], 1
19+
; OPT-NEXT: [[COND:%.*]] = icmp eq i32 [[ITERSLEFT]], 0
20+
; OPT-NEXT: br i1 [[COND]], label %[[LOOPEXIT:.*]], label %[[LOOPBODY]]
21+
; OPT: [[LOOPEXIT]]:
22+
; OPT-NEXT: [[SUMELEMENT0:%.*]] = extractelement <2 x i32> [[RUNNINGSUM]], i64 0
23+
; OPT-NEXT: [[SUMELEMENT1:%.*]] = extractelement <2 x i32> [[RUNNINGSUM]], i64 1
24+
; OPT-NEXT: store i32 [[SUMELEMENT0]], ptr addrspace(1) [[OUT0]], align 4
25+
; OPT-NEXT: store i32 [[SUMELEMENT1]], ptr addrspace(1) [[OUT1]], align 4
26+
; OPT-NEXT: ret void
27+
;
28+
preheader:
29+
%vecElement0 = insertelement <2 x i32> poison, i32 %inputElement0, i64 0
30+
%broadcast0 = shufflevector <2 x i32> %vecElement0, <2 x i32> poison, <2 x i32> zeroinitializer
31+
%vecElement1 = insertelement <2 x i32> poison, i32 %inputElement1, i64 0
32+
%broadcast1 = shufflevector <2 x i32> %vecElement1, <2 x i32> poison, <2 x i32> zeroinitializer
33+
br label %loopBody
34+
35+
loopBody:
36+
%previousSum = phi <2 x i32> [ %broadcast1, %preheader ], [ %runningSum, %loopBody ]
37+
%iterCount = phi i32 [ %inputIter, %preheader ], [ %itersLeft, %loopBody ]
38+
%runningSum = add <2 x i32> %broadcast1, %previousSum
39+
%itersLeft = sub i32 %iterCount, 1
40+
%cond = icmp eq i32 %itersLeft, 0
41+
br i1 %cond, label %loopExit, label %loopBody
42+
43+
loopExit:
44+
%sumElement0 = extractelement <2 x i32> %runningSum, i64 0
45+
%sumElement1 = extractelement <2 x i32> %runningSum, i64 1
46+
store i32 %sumElement0, ptr addrspace(1) %out0
47+
store i32 %sumElement1, ptr addrspace(1) %out1
48+
ret void
49+
}
50+
51+
; testing extract case with single use
52+
define amdgpu_kernel void @test_sink_extract_single_use_operands(ptr addrspace(1) %out0, <2 x i32> %inputVec) {
53+
; OPT-LABEL: define amdgpu_kernel void @test_sink_extract_single_use_operands(
54+
; OPT-SAME: ptr addrspace(1) [[OUT0:%.*]], <2 x i32> [[INPUTVEC:%.*]]) #[[ATTR0]] {
55+
; OPT-NEXT: [[ENTRY:.*:]]
56+
; OPT-NEXT: [[RUNNINGSUM:%.*]] = add <2 x i32> [[INPUTVEC]], splat (i32 1)
57+
; OPT-NEXT: [[SUMELEMENT0:%.*]] = extractelement <2 x i32> [[RUNNINGSUM]], i64 0
58+
; OPT-NEXT: [[RESULT:%.*]] = add i32 [[SUMELEMENT0]], 100
59+
; OPT-NEXT: store i32 [[RESULT]], ptr addrspace(1) [[OUT0]], align 4
60+
; OPT-NEXT: ret void
61+
;
62+
entry:
63+
%runningSum = add <2 x i32> %inputVec, <i32 1, i32 1>
64+
%sumElement0 = extractelement <2 x i32> %runningSum, i64 0
65+
%result = add i32 %sumElement0, 100
66+
store i32 %result, ptr addrspace(1) %out0
67+
ret void
68+
}
69+
70+
; testing extract case with multiple uses
71+
define amdgpu_kernel void @test_sink_extract_operands(ptr addrspace(1) %ptr, <4 x i32> %input_vec) {
72+
; OPT-LABEL: define amdgpu_kernel void @test_sink_extract_operands(
73+
; OPT-SAME: ptr addrspace(1) [[PTR:%.*]], <4 x i32> [[INPUT_VEC:%.*]]) #[[ATTR0]] {
74+
; OPT-NEXT: [[ENTRY:.*:]]
75+
; OPT-NEXT: [[VEC_FULL:%.*]] = add <4 x i32> [[INPUT_VEC]], <i32 42, i32 43, i32 44, i32 45>
76+
; OPT-NEXT: [[EXTRACT0:%.*]] = extractelement <4 x i32> [[VEC_FULL]], i64 0
77+
; OPT-NEXT: [[VEC_SHIFTED:%.*]] = shl <4 x i32> [[VEC_FULL]], splat (i32 1)
78+
; OPT-NEXT: [[RESULT0:%.*]] = add i32 [[EXTRACT0]], 100
79+
; OPT-NEXT: store i32 [[RESULT0]], ptr addrspace(1) [[PTR]], align 4
80+
; OPT-NEXT: store <4 x i32> [[VEC_SHIFTED]], ptr addrspace(1) [[PTR]], align 16
81+
; OPT-NEXT: ret void
82+
;
83+
entry:
84+
%vec_full = add <4 x i32> %input_vec, <i32 42, i32 43, i32 44, i32 45>
85+
%extract0 = extractelement <4 x i32> %vec_full, i64 0
86+
%vec_shifted = shl <4 x i32> %vec_full, <i32 1, i32 1, i32 1, i32 1>
87+
%result0 = add i32 %extract0, 100
88+
store i32 %result0, ptr addrspace(1) %ptr
89+
store <4 x i32> %vec_shifted, ptr addrspace(1) %ptr
90+
ret void
91+
}
92+
93+
define amdgpu_kernel void @test_shuffle_insert_subvector(ptr addrspace(1) %ptr, <4 x i16> %vec1, <4 x i16> %vec2) {
94+
; OPT-LABEL: define amdgpu_kernel void @test_shuffle_insert_subvector(
95+
; OPT-SAME: ptr addrspace(1) [[PTR:%.*]], <4 x i16> [[VEC1:%.*]], <4 x i16> [[VEC2:%.*]]) #[[ATTR0]] {
96+
; OPT-NEXT: [[ENTRY:.*:]]
97+
; OPT-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i16> [[VEC1]], <4 x i16> [[VEC2]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
98+
; OPT-NEXT: [[OTHER_SHUFFLE:%.*]] = shufflevector <4 x i16> [[SHUFFLE]], <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
99+
; OPT-NEXT: [[RESULT_VEC:%.*]] = add <4 x i16> [[SHUFFLE]], <i16 100, i16 200, i16 300, i16 400>
100+
; OPT-NEXT: [[OTHER_RESULT:%.*]] = mul <4 x i16> [[OTHER_SHUFFLE]], splat (i16 2)
101+
; OPT-NEXT: store <4 x i16> [[RESULT_VEC]], ptr addrspace(1) [[PTR]], align 8
102+
; OPT-NEXT: store <4 x i16> [[OTHER_RESULT]], ptr addrspace(1) [[PTR]], align 8
103+
; OPT-NEXT: ret void
104+
;
105+
entry:
106+
%shuffle = shufflevector <4 x i16> %vec1, <4 x i16> %vec2, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
107+
%other_shuffle = shufflevector <4 x i16> %shuffle, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
108+
%result_vec = add <4 x i16> %shuffle, <i16 100, i16 200, i16 300, i16 400>
109+
%other_result = mul <4 x i16> %other_shuffle, <i16 2, i16 2, i16 2, i16 2>
110+
store <4 x i16> %result_vec, ptr addrspace(1) %ptr
111+
store <4 x i16> %other_result, ptr addrspace(1) %ptr
112+
ret void
113+
}
114+
115+
define amdgpu_kernel void @test_shuffle_extract_subvector(ptr addrspace(1) %ptr, <4 x i16> %input_vec) {
116+
; OPT-LABEL: define amdgpu_kernel void @test_shuffle_extract_subvector(
117+
; OPT-SAME: ptr addrspace(1) [[PTR:%.*]], <4 x i16> [[INPUT_VEC:%.*]]) #[[ATTR0]] {
118+
; OPT-NEXT: [[ENTRY:.*:]]
119+
; OPT-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i16> [[INPUT_VEC]], <4 x i16> poison, <2 x i32> <i32 2, i32 3>
120+
; OPT-NEXT: [[RESULT_VEC:%.*]] = add <2 x i16> [[SHUFFLE]], <i16 100, i16 200>
121+
; OPT-NEXT: store <2 x i16> [[RESULT_VEC]], ptr addrspace(1) [[PTR]], align 4
122+
; OPT-NEXT: ret void
123+
;
124+
entry:
125+
%shuffle = shufflevector <4 x i16> %input_vec, <4 x i16> poison, <2 x i32> <i32 2, i32 3>
126+
%result_vec = add <2 x i16> %shuffle, <i16 100, i16 200>
127+
store <2 x i16> %result_vec, ptr addrspace(1) %ptr
128+
ret void
129+
}
130+
131+
define amdgpu_kernel void @test_shuffle_sink_operands(ptr addrspace(1) %ptr, <2 x i16> %input_vec) {
132+
; OPT-LABEL: define amdgpu_kernel void @test_shuffle_sink_operands(
133+
; OPT-SAME: ptr addrspace(1) [[PTR:%.*]], <2 x i16> [[INPUT_VEC:%.*]]) #[[ATTR0]] {
134+
; OPT-NEXT: [[ENTRY:.*:]]
135+
; OPT-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i16> [[INPUT_VEC]], <2 x i16> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
136+
; OPT-NEXT: [[RESULT_VEC:%.*]] = add <4 x i16> [[SHUFFLE]], <i16 100, i16 200, i16 300, i16 400>
137+
; OPT-NEXT: store <4 x i16> [[RESULT_VEC]], ptr addrspace(1) [[PTR]], align 8
138+
; OPT-NEXT: ret void
139+
;
140+
entry:
141+
%shuffle = shufflevector <2 x i16> %input_vec, <2 x i16> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
142+
%result_vec = add <4 x i16> %shuffle, <i16 100, i16 200, i16 300, i16 400>
143+
store <4 x i16> %result_vec, ptr addrspace(1) %ptr
144+
ret void
145+
}

0 commit comments

Comments
 (0)