1 ; Test ANDs of a constant into a byte of memory.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
5 ; Check the lowest useful constant, expressed as a signed integer.
6 define void @f1(i8 *%ptr) {
10 %val = load i8, i8 *%ptr
11 %and = and i8 %val, -255
12 store i8 %and, i8 *%ptr
16 ; Check the highest useful constant, expressed as a signed integer.
17 define void @f2(i8 *%ptr) {
19 ; CHECK: ni 0(%r2), 254
21 %val = load i8, i8 *%ptr
22 %and = and i8 %val, -2
23 store i8 %and, i8 *%ptr
27 ; Check the lowest useful constant, expressed as an unsigned integer.
28 define void @f3(i8 *%ptr) {
32 %val = load i8, i8 *%ptr
34 store i8 %and, i8 *%ptr
38 ; Check the highest useful constant, expressed as a unsigned integer.
39 define void @f4(i8 *%ptr) {
41 ; CHECK: ni 0(%r2), 254
43 %val = load i8, i8 *%ptr
44 %and = and i8 %val, 254
45 store i8 %and, i8 *%ptr
49 ; Check the high end of the NI range.
50 define void @f5(i8 *%src) {
52 ; CHECK: ni 4095(%r2), 127
54 %ptr = getelementptr i8, i8 *%src, i64 4095
55 %val = load i8, i8 *%ptr
56 %and = and i8 %val, 127
57 store i8 %and, i8 *%ptr
61 ; Check the next byte up, which should use NIY instead of NI.
62 define void @f6(i8 *%src) {
64 ; CHECK: niy 4096(%r2), 127
66 %ptr = getelementptr i8, i8 *%src, i64 4096
67 %val = load i8, i8 *%ptr
68 %and = and i8 %val, 127
69 store i8 %and, i8 *%ptr
73 ; Check the high end of the NIY range.
74 define void @f7(i8 *%src) {
76 ; CHECK: niy 524287(%r2), 127
78 %ptr = getelementptr i8, i8 *%src, i64 524287
79 %val = load i8, i8 *%ptr
80 %and = and i8 %val, 127
81 store i8 %and, i8 *%ptr
85 ; Check the next byte up, which needs separate address logic.
86 ; Other sequences besides this one would be OK.
87 define void @f8(i8 *%src) {
89 ; CHECK: agfi %r2, 524288
90 ; CHECK: ni 0(%r2), 127
92 %ptr = getelementptr i8, i8 *%src, i64 524288
93 %val = load i8, i8 *%ptr
94 %and = and i8 %val, 127
95 store i8 %and, i8 *%ptr
99 ; Check the high end of the negative NIY range.
100 define void @f9(i8 *%src) {
102 ; CHECK: niy -1(%r2), 127
104 %ptr = getelementptr i8, i8 *%src, i64 -1
105 %val = load i8, i8 *%ptr
106 %and = and i8 %val, 127
107 store i8 %and, i8 *%ptr
111 ; Check the low end of the NIY range.
112 define void @f10(i8 *%src) {
114 ; CHECK: niy -524288(%r2), 127
116 %ptr = getelementptr i8, i8 *%src, i64 -524288
117 %val = load i8, i8 *%ptr
118 %and = and i8 %val, 127
119 store i8 %and, i8 *%ptr
123 ; Check the next byte down, which needs separate address logic.
124 ; Other sequences besides this one would be OK.
125 define void @f11(i8 *%src) {
127 ; CHECK: agfi %r2, -524289
128 ; CHECK: ni 0(%r2), 127
130 %ptr = getelementptr i8, i8 *%src, i64 -524289
131 %val = load i8, i8 *%ptr
132 %and = and i8 %val, 127
133 store i8 %and, i8 *%ptr
137 ; Check that NI does not allow an index
138 define void @f12(i64 %src, i64 %index) {
140 ; CHECK: agr %r2, %r3
141 ; CHECK: ni 4095(%r2), 127
143 %add1 = add i64 %src, %index
144 %add2 = add i64 %add1, 4095
145 %ptr = inttoptr i64 %add2 to i8 *
146 %val = load i8, i8 *%ptr
147 %and = and i8 %val, 127
148 store i8 %and, i8 *%ptr
152 ; Check that NIY does not allow an index
153 define void @f13(i64 %src, i64 %index) {
155 ; CHECK: agr %r2, %r3
156 ; CHECK: niy 4096(%r2), 127
158 %add1 = add i64 %src, %index
159 %add2 = add i64 %add1, 4096
160 %ptr = inttoptr i64 %add2 to i8 *
161 %val = load i8, i8 *%ptr
162 %and = and i8 %val, 127
163 store i8 %and, i8 *%ptr