1 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
3 ; Test PC-relative memory accesses of globals with packed struct types.
4 ; PC-relative memory accesses cannot be used when the address is not
5 ; aligned. This can happen with programs like the following (which are not
20 %packed.i16i32 = type <{ i16, i32 }>
21 %packed.i16i32i16i32 = type <{ i16, i32, i16, i32 }>
22 %packed.i16i64 = type <{ i16, i64 }>
23 %packed.i8i16 = type <{ i8, i16 }>
25 @A_align2 = dso_local global %packed.i16i32 zeroinitializer, align 2
26 @B_align2 = dso_local global %packed.i16i32i16i32 zeroinitializer, align 2
27 @C_align2 = dso_local global %packed.i16i64 zeroinitializer, align 2
28 @D_align4 = dso_local global %packed.i16i32 zeroinitializer, align 4
29 @E_align4 = dso_local global %packed.i16i32i16i32 zeroinitializer, align 4
30 @F_align2 = dso_local global %packed.i8i16 zeroinitializer, align 2
34 ; unaligned packed struct + 2 -> unaligned address
35 define dso_local void @f1() {
37 ; CHECK: larl %r1, A_align2
38 ; CHECK: mvhi 2(%r1), 0
40 store i32 0, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @A_align2, i64 0, i32 1), align 4
44 ; unaligned packed struct + 8 -> unaligned address
45 define dso_local void @f2() {
47 ; CHECK: larl %r1, B_align2
48 ; CHECK: mvhi 8(%r1), 0
50 store i32 0, i32* getelementptr inbounds (%packed.i16i32i16i32, %packed.i16i32i16i32* @B_align2, i64 0, i32 3), align 4
54 ; aligned packed struct + 2 -> unaligned address
55 define dso_local void @f3() {
57 ; CHECK: larl %r1, D_align4
58 ; CHECK: mvhi 2(%r1), 0
60 store i32 0, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @D_align4, i64 0, i32 1), align 4
64 ; aligned packed struct + 8 -> aligned address
65 define dso_local void @f4() {
68 ; CHECK: strl %r0, E_align4+8
70 store i32 0, i32* getelementptr inbounds (%packed.i16i32i16i32, %packed.i16i32i16i32* @E_align4, i64 0, i32 3), align 4
74 define dso_local void @f5() {
76 ; CHECK: larl %r1, C_align2
77 ; CHECK: mvghi 2(%r1), 0
79 store i64 0, i64* getelementptr inbounds (%packed.i16i64, %packed.i16i64* @C_align2, i64 0, i32 1), align 8
83 define dso_local void @f6() {
86 store i16 0, i16* getelementptr inbounds (%packed.i8i16, %packed.i8i16* @F_align2, i64 0, i32 1), align 2
90 define dso_local void @f7(i64* %Src) {
92 ; CHECK: lg %r0, 0(%r2)
93 ; CHECK: larl %r1, D_align4
94 ; CHECK: st %r0, 2(%r1)
96 %L = load i64, i64* %Src
97 %T = trunc i64 %L to i32
98 store i32 %T, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @D_align4, i64 0, i32 1), align 4
102 define dso_local void @f8(i64* %Src) {
105 %L = load i64, i64* %Src
106 %T = trunc i64 %L to i16
107 store i16 %T, i16* getelementptr inbounds (%packed.i8i16, %packed.i8i16* @F_align2, i64 0, i32 1), align 2
113 ; unaligned packed struct + 2 -> unaligned address
114 define dso_local i32 @f9() {
116 ; CHECK: larl %r1, A_align2
117 ; CHECK: l %r2, 2(%r1)
119 %L = load i32, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @A_align2, i64 0, i32 1), align 4
123 ; unaligned packed struct + 8 -> unaligned address
124 define dso_local i32 @f10() {
126 ; CHECK: larl %r1, B_align2
127 ; CHECK: l %r2, 8(%r1)
129 %L = load i32, i32* getelementptr inbounds (%packed.i16i32i16i32, %packed.i16i32i16i32* @B_align2, i64 0, i32 3), align 4
133 ; aligned packed struct + 2 -> unaligned address
134 define dso_local i32 @f11() {
136 ; CHECK: larl %r1, D_align4
137 ; CHECK: l %r2, 2(%r1)
139 %L = load i32, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @D_align4, i64 0, i32 1), align 4
143 ; aligned packed struct + 8 -> aligned address
144 define dso_local i32 @f12() {
146 ; CHECK: lrl %r2, E_align4+8
148 %L = load i32, i32* getelementptr inbounds (%packed.i16i32i16i32, %packed.i16i32i16i32* @E_align4, i64 0, i32 3), align 4
152 define dso_local i64 @f13() {
154 ; CHECK: larl %r1, C_align2
155 ; CHECK: lg %r2, 2(%r1)
157 %L = load i64, i64* getelementptr inbounds (%packed.i16i64, %packed.i16i64* @C_align2, i64 0, i32 1), align 8
161 define dso_local i32 @f14() {
164 %L = load i16, i16* getelementptr inbounds (%packed.i8i16, %packed.i8i16* @F_align2, i64 0, i32 1), align 2
165 %ext = sext i16 %L to i32
169 define dso_local i64 @f15() {
172 %L = load i16, i16* getelementptr inbounds (%packed.i8i16, %packed.i8i16* @F_align2, i64 0, i32 1), align 2
173 %ext = zext i16 %L to i64
177 ;;; Loads folded into compare instructions
179 define dso_local i32 @f16(i32 %src1) {
181 ; CHECK: larl %r1, A_align2
182 ; CHECK: c %r2, 2(%r1)
184 %src2 = load i32, i32* getelementptr inbounds (%packed.i16i32, %packed.i16i32* @A_align2, i64 0, i32 1), align 4
185 %cond = icmp slt i32 %src1, %src2
186 br i1 %cond, label %exit, label %mulb
188 %mul = mul i32 %src1, %src1
191 %res = phi i32 [ %src1, %entry ], [ %mul, %mulb ]
195 define dso_local i64 @f17(i64 %src1) {
197 ; CHECK: larl %r1, C_align2
198 ; CHECK: clg %r2, 2(%r1)
200 %src2 = load i64, i64* getelementptr inbounds (%packed.i16i64, %packed.i16i64* @C_align2, i64 0, i32 1), align 8
201 %cond = icmp ult i64 %src1, %src2
202 br i1 %cond, label %exit, label %mulb
204 %mul = mul i64 %src1, %src1
207 %res = phi i64 [ %src1, %entry ], [ %mul, %mulb ]