Nicola Zaghen | 436c012 | 2018-09-27 10:08:38 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 3 | |
| 4 | ; Tests for slt/ult |
| 5 | |
| 6 | define i1 @slt_positive_multip_rem_zero(i8 %x) { |
| 7 | ; CHECK-LABEL: @slt_positive_multip_rem_zero( |
| 8 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7 |
| 9 | ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21 |
| 10 | ; CHECK-NEXT: ret i1 [[B]] |
| 11 | ; |
| 12 | %a = mul nsw i8 %x, 7 |
| 13 | %b = icmp slt i8 %a, 21 |
| 14 | ret i1 %b |
| 15 | } |
| 16 | |
| 17 | define i1 @slt_negative_multip_rem_zero(i8 %x) { |
| 18 | ; CHECK-LABEL: @slt_negative_multip_rem_zero( |
| 19 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7 |
| 20 | ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21 |
| 21 | ; CHECK-NEXT: ret i1 [[B]] |
| 22 | ; |
| 23 | %a = mul nsw i8 %x, -7 |
| 24 | %b = icmp slt i8 %a, 21 |
| 25 | ret i1 %b |
| 26 | } |
| 27 | |
| 28 | define i1 @slt_positive_multip_rem_nz(i8 %x) { |
| 29 | ; CHECK-LABEL: @slt_positive_multip_rem_nz( |
| 30 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5 |
| 31 | ; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21 |
| 32 | ; CHECK-NEXT: ret i1 [[B]] |
| 33 | ; |
| 34 | %a = mul nsw i8 %x, 5 |
| 35 | %b = icmp slt i8 %a, 21 |
| 36 | ret i1 %b |
| 37 | } |
| 38 | |
| 39 | define i1 @ult_rem_zero(i8 %x) { |
| 40 | ; CHECK-LABEL: @ult_rem_zero( |
| 41 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7 |
| 42 | ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21 |
| 43 | ; CHECK-NEXT: ret i1 [[B]] |
| 44 | ; |
| 45 | %a = mul nuw i8 %x, 7 |
| 46 | %b = icmp ult i8 %a, 21 |
| 47 | ret i1 %b |
| 48 | } |
| 49 | |
| 50 | define i1 @ult_rem_nz(i8 %x) { |
| 51 | ; CHECK-LABEL: @ult_rem_nz( |
| 52 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 53 | ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21 |
| 54 | ; CHECK-NEXT: ret i1 [[B]] |
| 55 | ; |
| 56 | %a = mul nuw i8 %x, 5 |
| 57 | %b = icmp ult i8 %a, 21 |
| 58 | ret i1 %b |
| 59 | } |
| 60 | |
| 61 | ; Tests for sgt/ugt |
| 62 | |
| 63 | define i1 @sgt_positive_multip_rem_zero(i8 %x) { |
| 64 | ; CHECK-LABEL: @sgt_positive_multip_rem_zero( |
| 65 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7 |
| 66 | ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21 |
| 67 | ; CHECK-NEXT: ret i1 [[B]] |
| 68 | ; |
| 69 | %a = mul nsw i8 %x, 7 |
| 70 | %b = icmp sgt i8 %a, 21 |
| 71 | ret i1 %b |
| 72 | } |
| 73 | |
| 74 | define i1 @sgt_negative_multip_rem_zero(i8 %x) { |
| 75 | ; CHECK-LABEL: @sgt_negative_multip_rem_zero( |
| 76 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7 |
| 77 | ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21 |
| 78 | ; CHECK-NEXT: ret i1 [[B]] |
| 79 | ; |
| 80 | %a = mul nsw i8 %x, -7 |
| 81 | %b = icmp sgt i8 %a, 21 |
| 82 | ret i1 %b |
| 83 | } |
| 84 | |
| 85 | define i1 @sgt_positive_multip_rem_nz(i8 %x) { |
| 86 | ; CHECK-LABEL: @sgt_positive_multip_rem_nz( |
| 87 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5 |
| 88 | ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21 |
| 89 | ; CHECK-NEXT: ret i1 [[B]] |
| 90 | ; |
| 91 | %a = mul nsw i8 %x, 5 |
| 92 | %b = icmp sgt i8 %a, 21 |
| 93 | ret i1 %b |
| 94 | } |
| 95 | |
| 96 | define i1 @ugt_rem_zero(i8 %x) { |
| 97 | ; CHECK-LABEL: @ugt_rem_zero( |
| 98 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7 |
| 99 | ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21 |
| 100 | ; CHECK-NEXT: ret i1 [[B]] |
| 101 | ; |
| 102 | %a = mul nuw i8 %x, 7 |
| 103 | %b = icmp ugt i8 %a, 21 |
| 104 | ret i1 %b |
| 105 | } |
| 106 | |
| 107 | define i1 @ugt_rem_nz(i8 %x) { |
| 108 | ; CHECK-LABEL: @ugt_rem_nz( |
| 109 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 110 | ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21 |
| 111 | ; CHECK-NEXT: ret i1 [[B]] |
| 112 | ; |
| 113 | %a = mul nuw i8 %x, 5 |
| 114 | %b = icmp ugt i8 %a, 21 |
| 115 | ret i1 %b |
| 116 | } |
| 117 | |
| 118 | ; Tests for eq/ne |
| 119 | |
| 120 | define i1 @eq_rem_zero(i8 %x) { |
| 121 | ; CHECK-LABEL: @eq_rem_zero( |
| 122 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 123 | ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20 |
| 124 | ; CHECK-NEXT: ret i1 [[B]] |
| 125 | ; |
| 126 | %a = mul nuw i8 %x, 5 |
| 127 | %b = icmp eq i8 %a, 20 |
| 128 | ret i1 %b |
| 129 | } |
| 130 | |
| 131 | define i1 @ne_rem_zero(i8 %x) { |
| 132 | ; CHECK-LABEL: @ne_rem_zero( |
| 133 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 134 | ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30 |
| 135 | ; CHECK-NEXT: ret i1 [[B]] |
| 136 | ; |
| 137 | %a = mul nuw i8 %x, 5 |
| 138 | %b = icmp ne i8 %a, 30 |
| 139 | ret i1 %b |
| 140 | } |
| 141 | |
| 142 | define i1 @eq_rem_nz(i8 %x) { |
| 143 | ; CHECK-LABEL: @eq_rem_nz( |
| 144 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 145 | ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 31 |
| 146 | ; CHECK-NEXT: ret i1 [[B]] |
| 147 | ; |
| 148 | %a = mul nuw i8 %x, 5 |
| 149 | %b = icmp eq i8 %a, 31 |
| 150 | ret i1 %b |
| 151 | } |
| 152 | |
| 153 | define i1 @ne_rem_nz(i8 %x) { |
| 154 | ; CHECK-LABEL: @ne_rem_nz( |
| 155 | ; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5 |
| 156 | ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 31 |
| 157 | ; CHECK-NEXT: ret i1 [[B]] |
| 158 | ; |
| 159 | %a = mul nuw i8 %x, 5 |
| 160 | %b = icmp ne i8 %a, 31 |
| 161 | ret i1 %b |
| 162 | } |
| 163 | |
| 164 | ; Negative tests for the icmp mul folds |
| 165 | |
| 166 | define i1 @sgt_positive_multip_rem_zero_nonsw(i8 %x) { |
| 167 | ; CHECK-LABEL: @sgt_positive_multip_rem_zero_nonsw( |
| 168 | ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7 |
| 169 | ; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21 |
| 170 | ; CHECK-NEXT: ret i1 [[B]] |
| 171 | ; |
| 172 | %a = mul i8 %x, 7 |
| 173 | %b = icmp sgt i8 %a, 21 |
| 174 | ret i1 %b |
| 175 | } |
| 176 | |
| 177 | define i1 @ult_multip_rem_zero_nonsw(i8 %x) { |
| 178 | ; CHECK-LABEL: @ult_multip_rem_zero_nonsw( |
| 179 | ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7 |
| 180 | ; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21 |
| 181 | ; CHECK-NEXT: ret i1 [[B]] |
| 182 | ; |
| 183 | %a = mul i8 %x, 7 |
| 184 | %b = icmp ult i8 %a, 21 |
| 185 | ret i1 %b |
| 186 | } |
| 187 | |
| 188 | define i1 @ugt_rem_zero_nonuw(i8 %x) { |
| 189 | ; CHECK-LABEL: @ugt_rem_zero_nonuw( |
| 190 | ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7 |
| 191 | ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21 |
| 192 | ; CHECK-NEXT: ret i1 [[B]] |
| 193 | ; |
| 194 | %a = mul i8 %x, 7 |
| 195 | %b = icmp ugt i8 %a, 21 |
| 196 | ret i1 %b |
| 197 | } |
| 198 | |
| 199 | define i1 @sgt_minnum(i8 %x) { |
| 200 | ; CHECK-LABEL: @sgt_minnum( |
| 201 | ; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7 |
| 202 | ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], -128 |
| 203 | ; CHECK-NEXT: ret i1 [[B]] |
| 204 | ; |
| 205 | %a = mul nsw i8 %x, 7 |
| 206 | %b = icmp sgt i8 %a, -128 |
| 207 | ret i1 %b |
| 208 | } |
| 209 | |
| 210 | define i1 @ule_bignum(i8 %x) { |
| 211 | ; CHECK-LABEL: @ule_bignum( |
| 212 | ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[X:%.*]], 0 |
| 213 | ; CHECK-NEXT: ret i1 [[B]] |
| 214 | ; |
| 215 | %a = mul i8 %x, 2147483647 |
| 216 | %b = icmp ule i8 %a, 0 |
| 217 | ret i1 %b |
| 218 | } |
| 219 | |
| 220 | define i1 @sgt_mulzero(i8 %x) { |
| 221 | ; CHECK-LABEL: @sgt_mulzero( |
| 222 | ; CHECK-NEXT: ret i1 false |
| 223 | ; |
| 224 | %a = mul nsw i8 %x, 0 |
| 225 | %b = icmp sgt i8 %a, 21 |
| 226 | ret i1 %b |
| 227 | } |
| 228 | |
| 229 | define i1 @eq_rem_zero_nonuw(i8 %x) { |
| 230 | ; CHECK-LABEL: @eq_rem_zero_nonuw( |
| 231 | ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5 |
| 232 | ; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20 |
| 233 | ; CHECK-NEXT: ret i1 [[B]] |
| 234 | ; |
| 235 | %a = mul i8 %x, 5 |
| 236 | %b = icmp eq i8 %a, 20 |
| 237 | ret i1 %b |
| 238 | } |
| 239 | |
| 240 | define i1 @ne_rem_zero_nonuw(i8 %x) { |
| 241 | ; CHECK-LABEL: @ne_rem_zero_nonuw( |
| 242 | ; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5 |
| 243 | ; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30 |
| 244 | ; CHECK-NEXT: ret i1 [[B]] |
| 245 | ; |
| 246 | %a = mul i8 %x, 5 |
| 247 | %b = icmp ne i8 %a, 30 |
| 248 | ret i1 %b |
| 249 | } |