1 ; Test vector insertion of byte-swapped memory values.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z15 | FileCheck %s
5 declare i16 @llvm.bswap.i16(i16)
6 declare i32 @llvm.bswap.i32(i32)
7 declare i64 @llvm.bswap.i64(i64)
8 declare <8 x i16> @llvm.bswap.v8i16(<8 x i16>)
9 declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>)
10 declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)
12 ; Test v8i16 insertion into the first element.
13 define <8 x i16> @f1(<8 x i16> %val, i16 *%ptr) {
15 ; CHECK: vlebrh %v24, 0(%r2), 0
17 %element = load i16, i16 *%ptr
18 %swap = call i16 @llvm.bswap.i16(i16 %element)
19 %ret = insertelement <8 x i16> %val, i16 %swap, i32 0
23 ; Test v8i16 insertion into the last element.
24 define <8 x i16> @f2(<8 x i16> %val, i16 *%ptr) {
26 ; CHECK: vlebrh %v24, 0(%r2), 7
28 %element = load i16, i16 *%ptr
29 %swap = call i16 @llvm.bswap.i16(i16 %element)
30 %ret = insertelement <8 x i16> %val, i16 %swap, i32 7
34 ; Test v8i16 insertion with the highest in-range offset.
35 define <8 x i16> @f3(<8 x i16> %val, i16 *%base) {
37 ; CHECK: vlebrh %v24, 4094(%r2), 5
39 %ptr = getelementptr i16, i16 *%base, i32 2047
40 %element = load i16, i16 *%ptr
41 %swap = call i16 @llvm.bswap.i16(i16 %element)
42 %ret = insertelement <8 x i16> %val, i16 %swap, i32 5
46 ; Test v8i16 insertion with the first ouf-of-range offset.
47 define <8 x i16> @f4(<8 x i16> %val, i16 *%base) {
49 ; CHECK: aghi %r2, 4096
50 ; CHECK: vlebrh %v24, 0(%r2), 1
52 %ptr = getelementptr i16, i16 *%base, i32 2048
53 %element = load i16, i16 *%ptr
54 %swap = call i16 @llvm.bswap.i16(i16 %element)
55 %ret = insertelement <8 x i16> %val, i16 %swap, i32 1
59 ; Test v8i16 insertion into a variable element.
60 define <8 x i16> @f5(<8 x i16> %val, i16 *%ptr, i32 %index) {
64 %element = load i16, i16 *%ptr
65 %swap = call i16 @llvm.bswap.i16(i16 %element)
66 %ret = insertelement <8 x i16> %val, i16 %swap, i32 %index
70 ; Test v8i16 insertion using a pair of vector bswaps.
71 define <8 x i16> @f6(<8 x i16> %val, i16 *%ptr) {
73 ; CHECK: vlebrh %v24, 0(%r2), 0
75 %element = load i16, i16 *%ptr
76 %swapval = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %val)
77 %insert = insertelement <8 x i16> %swapval, i16 %element, i32 0
78 %ret = call <8 x i16> @llvm.bswap.v8i16(<8 x i16> %insert)
82 ; Test v4i32 insertion into the first element.
83 define <4 x i32> @f7(<4 x i32> %val, i32 *%ptr) {
85 ; CHECK: vlebrf %v24, 0(%r2), 0
87 %element = load i32, i32 *%ptr
88 %swap = call i32 @llvm.bswap.i32(i32 %element)
89 %ret = insertelement <4 x i32> %val, i32 %swap, i32 0
93 ; Test v4i32 insertion into the last element.
94 define <4 x i32> @f8(<4 x i32> %val, i32 *%ptr) {
96 ; CHECK: vlebrf %v24, 0(%r2), 3
98 %element = load i32, i32 *%ptr
99 %swap = call i32 @llvm.bswap.i32(i32 %element)
100 %ret = insertelement <4 x i32> %val, i32 %swap, i32 3
104 ; Test v4i32 insertion with the highest in-range offset.
105 define <4 x i32> @f9(<4 x i32> %val, i32 *%base) {
107 ; CHECK: vlebrf %v24, 4092(%r2), 2
109 %ptr = getelementptr i32, i32 *%base, i32 1023
110 %element = load i32, i32 *%ptr
111 %swap = call i32 @llvm.bswap.i32(i32 %element)
112 %ret = insertelement <4 x i32> %val, i32 %swap, i32 2
116 ; Test v4i32 insertion with the first ouf-of-range offset.
117 define <4 x i32> @f10(<4 x i32> %val, i32 *%base) {
119 ; CHECK: aghi %r2, 4096
120 ; CHECK: vlebrf %v24, 0(%r2), 1
122 %ptr = getelementptr i32, i32 *%base, i32 1024
123 %element = load i32, i32 *%ptr
124 %swap = call i32 @llvm.bswap.i32(i32 %element)
125 %ret = insertelement <4 x i32> %val, i32 %swap, i32 1
129 ; Test v4i32 insertion into a variable element.
130 define <4 x i32> @f11(<4 x i32> %val, i32 *%ptr, i32 %index) {
134 %element = load i32, i32 *%ptr
135 %swap = call i32 @llvm.bswap.i32(i32 %element)
136 %ret = insertelement <4 x i32> %val, i32 %swap, i32 %index
140 ; Test v4i32 insertion using a pair of vector bswaps.
141 define <4 x i32> @f12(<4 x i32> %val, i32 *%ptr) {
143 ; CHECK: vlebrf %v24, 0(%r2), 0
145 %element = load i32, i32 *%ptr
146 %swapval = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %val)
147 %insert = insertelement <4 x i32> %swapval, i32 %element, i32 0
148 %ret = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %insert)
152 ; Test v2i64 insertion into the first element.
153 define <2 x i64> @f13(<2 x i64> %val, i64 *%ptr) {
155 ; CHECK: vlebrg %v24, 0(%r2), 0
157 %element = load i64, i64 *%ptr
158 %swap = call i64 @llvm.bswap.i64(i64 %element)
159 %ret = insertelement <2 x i64> %val, i64 %swap, i32 0
163 ; Test v2i64 insertion into the last element.
164 define <2 x i64> @f14(<2 x i64> %val, i64 *%ptr) {
166 ; CHECK: vlebrg %v24, 0(%r2), 1
168 %element = load i64, i64 *%ptr
169 %swap = call i64 @llvm.bswap.i64(i64 %element)
170 %ret = insertelement <2 x i64> %val, i64 %swap, i32 1
174 ; Test v2i64 insertion with the highest in-range offset.
175 define <2 x i64> @f15(<2 x i64> %val, i64 *%base) {
177 ; CHECK: vlebrg %v24, 4088(%r2), 1
179 %ptr = getelementptr i64, i64 *%base, i32 511
180 %element = load i64, i64 *%ptr
181 %swap = call i64 @llvm.bswap.i64(i64 %element)
182 %ret = insertelement <2 x i64> %val, i64 %swap, i32 1
186 ; Test v2i64 insertion with the first ouf-of-range offset.
187 define <2 x i64> @f16(<2 x i64> %val, i64 *%base) {
189 ; CHECK: aghi %r2, 4096
190 ; CHECK: vlebrg %v24, 0(%r2), 0
192 %ptr = getelementptr i64, i64 *%base, i32 512
193 %element = load i64, i64 *%ptr
194 %swap = call i64 @llvm.bswap.i64(i64 %element)
195 %ret = insertelement <2 x i64> %val, i64 %swap, i32 0
199 ; Test v2i64 insertion into a variable element.
200 define <2 x i64> @f17(<2 x i64> %val, i64 *%ptr, i32 %index) {
204 %element = load i64, i64 *%ptr
205 %swap = call i64 @llvm.bswap.i64(i64 %element)
206 %ret = insertelement <2 x i64> %val, i64 %swap, i32 %index
210 ; Test v2i64 insertion using a pair of vector bswaps.
211 define <2 x i64> @f18(<2 x i64> %val, i64 *%ptr) {
213 ; CHECK: vlebrg %v24, 0(%r2), 0
215 %element = load i64, i64 *%ptr
216 %swapval = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %val)
217 %insert = insertelement <2 x i64> %swapval, i64 %element, i32 0
218 %ret = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %insert)