1 ; Test 16-bit byteswaps from memory to registers.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 declare i16 @llvm.bswap.i16(i16 %a)
7 ; Check LRVH with no displacement.
8 define i16 @f1(i16 *%src) {
10 ; CHECK: lrvh %r2, 0(%r2)
12 %a = load i16, i16 *%src
13 %swapped = call i16 @llvm.bswap.i16(i16 %a)
17 ; Check the high end of the aligned LRVH range.
18 define i16 @f2(i16 *%src) {
20 ; CHECK: lrvh %r2, 524286(%r2)
22 %ptr = getelementptr i16, i16 *%src, i64 262143
23 %a = load i16, i16 *%ptr
24 %swapped = call i16 @llvm.bswap.i16(i16 %a)
28 ; Check the next word up, which needs separate address logic.
29 ; Other sequences besides this one would be OK.
30 define i16 @f3(i16 *%src) {
32 ; CHECK: agfi %r2, 524288
33 ; CHECK: lrvh %r2, 0(%r2)
35 %ptr = getelementptr i16, i16 *%src, i64 262144
36 %a = load i16, i16 *%ptr
37 %swapped = call i16 @llvm.bswap.i16(i16 %a)
41 ; Check the high end of the negative aligned LRVH range.
42 define i16 @f4(i16 *%src) {
44 ; CHECK: lrvh %r2, -2(%r2)
46 %ptr = getelementptr i16, i16 *%src, i64 -1
47 %a = load i16, i16 *%ptr
48 %swapped = call i16 @llvm.bswap.i16(i16 %a)
52 ; Check the low end of the LRVH range.
53 define i16 @f5(i16 *%src) {
55 ; CHECK: lrvh %r2, -524288(%r2)
57 %ptr = getelementptr i16, i16 *%src, i64 -262144
58 %a = load i16, i16 *%ptr
59 %swapped = call i16 @llvm.bswap.i16(i16 %a)
63 ; Check the next word down, which needs separate address logic.
64 ; Other sequences besides this one would be OK.
65 define i16 @f6(i16 *%src) {
67 ; CHECK: agfi %r2, -524290
68 ; CHECK: lrvh %r2, 0(%r2)
70 %ptr = getelementptr i16, i16 *%src, i64 -262145
71 %a = load i16, i16 *%ptr
72 %swapped = call i16 @llvm.bswap.i16(i16 %a)
76 ; Check that LRVH allows an index.
77 define i16 @f7(i64 %src, i64 %index) {
79 ; CHECK: lrvh %r2, 524287({{%r3,%r2|%r2,%r3}})
81 %add1 = add i64 %src, %index
82 %add2 = add i64 %add1, 524287
83 %ptr = inttoptr i64 %add2 to i16 *
84 %a = load i16, i16 *%ptr
85 %swapped = call i16 @llvm.bswap.i16(i16 %a)