1 ; 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. 6 define void @f1(i8 *%ptr) { 7 ; CHECK-LABEL: f1: 8 ; CHECK: ni 0(%r2), 1 9 ; CHECK: br %r14 10 %val = load i8 *%ptr 11 %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. 17 define void @f2(i8 *%ptr) { 18 ; CHECK-LABEL: f2: 19 ; CHECK: ni 0(%r2), 254 20 ; CHECK: br %r14 21 %val = load i8 *%ptr 22 %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. 28 define void @f3(i8 *%ptr) { 29 ; CHECK-LABEL: f3: 30 ; CHECK: ni 0(%r2), 1 31 ; CHECK: br %r14 32 %val = load i8 *%ptr 33 %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. 39 define void @f4(i8 *%ptr) { 40 ; CHECK-LABEL: f4: 41 ; CHECK: ni 0(%r2), 254 42 ; CHECK: br %r14 43 %val = load i8 *%ptr 44 %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. 50 define void @f5(i8 *%src) { 51 ; CHECK-LABEL: f5: 52 ; CHECK: ni 4095(%r2), 127 53 ; CHECK: br %r14 54 %ptr = getelementptr i8 *%src, i64 4095 55 %val = load i8 *%ptr 56 %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. 62 define void @f6(i8 *%src) { 63 ; CHECK-LABEL: f6: 64 ; CHECK: niy 4096(%r2), 127 65 ; CHECK: br %r14 66 %ptr = getelementptr i8 *%src, i64 4096 67 %val = load i8 *%ptr 68 %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. 74 define void @f7(i8 *%src) { 75 ; CHECK-LABEL: f7: 76 ; CHECK: niy 524287(%r2), 127 77 ; CHECK: br %r14 78 %ptr = getelementptr i8 *%src, i64 524287 79 %val = load i8 *%ptr 80 %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. 87 define void @f8(i8 *%src) { 88 ; CHECK-LABEL: f8: 89 ; CHECK: agfi %r2, 524288 90 ; CHECK: ni 0(%r2), 127 91 ; CHECK: br %r14 92 %ptr = getelementptr i8 *%src, i64 524288 93 %val = load i8 *%ptr 94 %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. 100 define void @f9(i8 *%src) { 101 ; CHECK-LABEL: f9: 102 ; CHECK: niy -1(%r2), 127 103 ; CHECK: br %r14 104 %ptr = getelementptr i8 *%src, i64 -1 105 %val = load i8 *%ptr 106 %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. 112 define void @f10(i8 *%src) { 113 ; CHECK-LABEL: f10: 114 ; CHECK: niy -524288(%r2), 127 115 ; CHECK: br %r14 116 %ptr = getelementptr i8 *%src, i64 -524288 117 %val = load i8 *%ptr 118 %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. 125 define void @f11(i8 *%src) { 126 ; CHECK-LABEL: f11: 127 ; CHECK: agfi %r2, -524289 128 ; CHECK: ni 0(%r2), 127 129 ; CHECK: br %r14 130 %ptr = getelementptr i8 *%src, i64 -524289 131 %val = load i8 *%ptr 132 %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 138 define void @f12(i64 %src, i64 %index) { 139 ; CHECK-LABEL: f12: 140 ; 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 * 146 %val = load i8 *%ptr 147 %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 153 define void @f13(i64 %src, i64 %index) { 154 ; CHECK-LABEL: f13: 155 ; 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 * 161 %val = load i8 *%ptr 162 %and = and i8 %val, 127 163 store i8 %and, i8 *%ptr 164 ret void 165 } 166