blob: 32719a4db5841007d0ced51aa1a0aaa000027810 [file] [log] [blame]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00001; Test ANDs of a constant into a byte of memory.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
5; Check the lowest useful constant, expressed as a signed integer.
6define void @f1(i8 *%ptr) {
Stephen Lind24ab202013-07-14 06:24:09 +00007; CHECK-LABEL: f1:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00008; CHECK: ni 0(%r2), 1
9; CHECK: br %r14
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000010 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000011 %and = and i8 %val, -255
12 store i8 %and, i8 *%ptr
13 ret void
14}
15
16; Check the highest useful constant, expressed as a signed integer.
17define void @f2(i8 *%ptr) {
Stephen Lind24ab202013-07-14 06:24:09 +000018; CHECK-LABEL: f2:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000019; CHECK: ni 0(%r2), 254
20; CHECK: br %r14
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000021 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000022 %and = and i8 %val, -2
23 store i8 %and, i8 *%ptr
24 ret void
25}
26
27; Check the lowest useful constant, expressed as an unsigned integer.
28define void @f3(i8 *%ptr) {
Stephen Lind24ab202013-07-14 06:24:09 +000029; CHECK-LABEL: f3:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000030; CHECK: ni 0(%r2), 1
31; CHECK: br %r14
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000032 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000033 %and = and i8 %val, 1
34 store i8 %and, i8 *%ptr
35 ret void
36}
37
38; Check the highest useful constant, expressed as a unsigned integer.
39define void @f4(i8 *%ptr) {
Stephen Lind24ab202013-07-14 06:24:09 +000040; CHECK-LABEL: f4:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000041; CHECK: ni 0(%r2), 254
42; CHECK: br %r14
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000043 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000044 %and = and i8 %val, 254
45 store i8 %and, i8 *%ptr
46 ret void
47}
48
49; Check the high end of the NI range.
50define void @f5(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +000051; CHECK-LABEL: f5:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000052; CHECK: ni 4095(%r2), 127
53; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000054 %ptr = getelementptr i8, i8 *%src, i64 4095
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000055 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000056 %and = and i8 %val, 127
57 store i8 %and, i8 *%ptr
58 ret void
59}
60
61; Check the next byte up, which should use NIY instead of NI.
62define void @f6(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +000063; CHECK-LABEL: f6:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000064; CHECK: niy 4096(%r2), 127
65; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000066 %ptr = getelementptr i8, i8 *%src, i64 4096
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000067 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000068 %and = and i8 %val, 127
69 store i8 %and, i8 *%ptr
70 ret void
71}
72
73; Check the high end of the NIY range.
74define void @f7(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +000075; CHECK-LABEL: f7:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000076; CHECK: niy 524287(%r2), 127
77; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000078 %ptr = getelementptr i8, i8 *%src, i64 524287
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000079 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000080 %and = and i8 %val, 127
81 store i8 %and, i8 *%ptr
82 ret void
83}
84
85; Check the next byte up, which needs separate address logic.
86; Other sequences besides this one would be OK.
87define void @f8(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +000088; CHECK-LABEL: f8:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000089; CHECK: agfi %r2, 524288
90; CHECK: ni 0(%r2), 127
91; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +000092 %ptr = getelementptr i8, i8 *%src, i64 524288
Ulrich Weigand9dd23b82018-07-20 12:12:10 +000093 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000094 %and = and i8 %val, 127
95 store i8 %and, i8 *%ptr
96 ret void
97}
98
99; Check the high end of the negative NIY range.
100define void @f9(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +0000101; CHECK-LABEL: f9:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000102; CHECK: niy -1(%r2), 127
103; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +0000104 %ptr = getelementptr i8, i8 *%src, i64 -1
Ulrich Weigand9dd23b82018-07-20 12:12:10 +0000105 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000106 %and = and i8 %val, 127
107 store i8 %and, i8 *%ptr
108 ret void
109}
110
111; Check the low end of the NIY range.
112define void @f10(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +0000113; CHECK-LABEL: f10:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000114; CHECK: niy -524288(%r2), 127
115; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +0000116 %ptr = getelementptr i8, i8 *%src, i64 -524288
Ulrich Weigand9dd23b82018-07-20 12:12:10 +0000117 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000118 %and = and i8 %val, 127
119 store i8 %and, i8 *%ptr
120 ret void
121}
122
123; Check the next byte down, which needs separate address logic.
124; Other sequences besides this one would be OK.
125define void @f11(i8 *%src) {
Stephen Lind24ab202013-07-14 06:24:09 +0000126; CHECK-LABEL: f11:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000127; CHECK: agfi %r2, -524289
128; CHECK: ni 0(%r2), 127
129; CHECK: br %r14
David Blaikie79e6c742015-02-27 19:29:02 +0000130 %ptr = getelementptr i8, i8 *%src, i64 -524289
Ulrich Weigand9dd23b82018-07-20 12:12:10 +0000131 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000132 %and = and i8 %val, 127
133 store i8 %and, i8 *%ptr
134 ret void
135}
136
137; Check that NI does not allow an index
138define void @f12(i64 %src, i64 %index) {
Stephen Lind24ab202013-07-14 06:24:09 +0000139; CHECK-LABEL: f12:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000140; CHECK: agr %r2, %r3
141; CHECK: ni 4095(%r2), 127
142; CHECK: br %r14
143 %add1 = add i64 %src, %index
144 %add2 = add i64 %add1, 4095
145 %ptr = inttoptr i64 %add2 to i8 *
Ulrich Weigand9dd23b82018-07-20 12:12:10 +0000146 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000147 %and = and i8 %val, 127
148 store i8 %and, i8 *%ptr
149 ret void
150}
151
152; Check that NIY does not allow an index
153define void @f13(i64 %src, i64 %index) {
Stephen Lind24ab202013-07-14 06:24:09 +0000154; CHECK-LABEL: f13:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000155; CHECK: agr %r2, %r3
156; CHECK: niy 4096(%r2), 127
157; CHECK: br %r14
158 %add1 = add i64 %src, %index
159 %add2 = add i64 %add1, 4096
160 %ptr = inttoptr i64 %add2 to i8 *
Ulrich Weigand9dd23b82018-07-20 12:12:10 +0000161 %val = load i8, i8 *%ptr
Ulrich Weigand9e3577f2013-05-06 16:17:29 +0000162 %and = and i8 %val, 127
163 store i8 %and, i8 *%ptr
164 ret void
165}