|
1 | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2 | 2 | ; RUN: opt -S -instcombine < %s | FileCheck %s
|
3 | 3 |
|
| 4 | +declare void @use(i1) |
| 5 | + |
4 | 6 | ; Should not be converted to "and", which has different poison semantics.
|
5 | 7 | define i1 @logical_and(i1 %a, i1 %b) {
|
6 | 8 | ; CHECK-LABEL: @logical_and(
|
@@ -176,3 +178,239 @@ define i1 @logical_and_noundef_b(i1 %a, i1 noundef %b) {
|
176 | 178 | %res = select i1 %a, i1 %b, i1 false
|
177 | 179 | ret i1 %res
|
178 | 180 | }
|
| 181 | + |
| 182 | +define i1 @not_not_true(i1 %x, i1 %y) { |
| 183 | +; CHECK-LABEL: @not_not_true( |
| 184 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 185 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]] |
| 186 | +; CHECK-NEXT: ret i1 [[R]] |
| 187 | +; |
| 188 | + %notx = xor i1 %x, true |
| 189 | + %noty = xor i1 %y, true |
| 190 | + %r = select i1 %notx, i1 %noty, i1 true |
| 191 | + ret i1 %r |
| 192 | +} |
| 193 | + |
| 194 | +define i1 @not_not_false(i1 %x, i1 %y) { |
| 195 | +; CHECK-LABEL: @not_not_false( |
| 196 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 197 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 198 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false |
| 199 | +; CHECK-NEXT: ret i1 [[R]] |
| 200 | +; |
| 201 | + %notx = xor i1 %x, true |
| 202 | + %noty = xor i1 %y, true |
| 203 | + %r = select i1 %notx, i1 %noty, i1 false |
| 204 | + ret i1 %r |
| 205 | +} |
| 206 | + |
| 207 | +define i1 @not_true_not(i1 %x, i1 %y) { |
| 208 | +; CHECK-LABEL: @not_true_not( |
| 209 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 210 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 211 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]] |
| 212 | +; CHECK-NEXT: ret i1 [[R]] |
| 213 | +; |
| 214 | + %notx = xor i1 %x, true |
| 215 | + %noty = xor i1 %y, true |
| 216 | + %r = select i1 %notx, i1 true, i1 %noty |
| 217 | + ret i1 %r |
| 218 | +} |
| 219 | + |
| 220 | +define i1 @not_false_not(i1 %x, i1 %y) { |
| 221 | +; CHECK-LABEL: @not_false_not( |
| 222 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 223 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false |
| 224 | +; CHECK-NEXT: ret i1 [[R]] |
| 225 | +; |
| 226 | + %notx = xor i1 %x, true |
| 227 | + %noty = xor i1 %y, true |
| 228 | + %r = select i1 %notx, i1 false, i1 %noty |
| 229 | + ret i1 %r |
| 230 | +} |
| 231 | + |
| 232 | +define i1 @not_not_true_use1(i1 %x, i1 %y) { |
| 233 | +; CHECK-LABEL: @not_not_true_use1( |
| 234 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 235 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 236 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 237 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]] |
| 238 | +; CHECK-NEXT: ret i1 [[R]] |
| 239 | +; |
| 240 | + %notx = xor i1 %x, true |
| 241 | + call void @use(i1 %notx) |
| 242 | + %noty = xor i1 %y, true |
| 243 | + %r = select i1 %notx, i1 %noty, i1 true |
| 244 | + ret i1 %r |
| 245 | +} |
| 246 | + |
| 247 | +define i1 @not_not_false_use1(i1 %x, i1 %y) { |
| 248 | +; CHECK-LABEL: @not_not_false_use1( |
| 249 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 250 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 251 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 252 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false |
| 253 | +; CHECK-NEXT: ret i1 [[R]] |
| 254 | +; |
| 255 | + %notx = xor i1 %x, true |
| 256 | + call void @use(i1 %notx) |
| 257 | + %noty = xor i1 %y, true |
| 258 | + %r = select i1 %notx, i1 %noty, i1 false |
| 259 | + ret i1 %r |
| 260 | +} |
| 261 | + |
| 262 | +define i1 @not_true_not_use1(i1 %x, i1 %y) { |
| 263 | +; CHECK-LABEL: @not_true_not_use1( |
| 264 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 265 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 266 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 267 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]] |
| 268 | +; CHECK-NEXT: ret i1 [[R]] |
| 269 | +; |
| 270 | + %notx = xor i1 %x, true |
| 271 | + call void @use(i1 %notx) |
| 272 | + %noty = xor i1 %y, true |
| 273 | + %r = select i1 %notx, i1 true, i1 %noty |
| 274 | + ret i1 %r |
| 275 | +} |
| 276 | + |
| 277 | +define i1 @not_false_not_use1(i1 %x, i1 %y) { |
| 278 | +; CHECK-LABEL: @not_false_not_use1( |
| 279 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 280 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 281 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 282 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false |
| 283 | +; CHECK-NEXT: ret i1 [[R]] |
| 284 | +; |
| 285 | + %notx = xor i1 %x, true |
| 286 | + call void @use(i1 %notx) |
| 287 | + %noty = xor i1 %y, true |
| 288 | + %r = select i1 %notx, i1 false, i1 %noty |
| 289 | + ret i1 %r |
| 290 | +} |
| 291 | + |
| 292 | +define i1 @not_not_true_use2(i1 %x, i1 %y) { |
| 293 | +; CHECK-LABEL: @not_not_true_use2( |
| 294 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 295 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 296 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[NOTY]] |
| 297 | +; CHECK-NEXT: ret i1 [[R]] |
| 298 | +; |
| 299 | + %notx = xor i1 %x, true |
| 300 | + %noty = xor i1 %y, true |
| 301 | + call void @use(i1 %noty) |
| 302 | + %r = select i1 %notx, i1 %noty, i1 true |
| 303 | + ret i1 %r |
| 304 | +} |
| 305 | + |
| 306 | +define i1 @not_not_false_use2(i1 %x, i1 %y) { |
| 307 | +; CHECK-LABEL: @not_not_false_use2( |
| 308 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 309 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 310 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 311 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false |
| 312 | +; CHECK-NEXT: ret i1 [[R]] |
| 313 | +; |
| 314 | + %notx = xor i1 %x, true |
| 315 | + %noty = xor i1 %y, true |
| 316 | + call void @use(i1 %noty) |
| 317 | + %r = select i1 %notx, i1 %noty, i1 false |
| 318 | + ret i1 %r |
| 319 | +} |
| 320 | + |
| 321 | +define i1 @not_true_not_use2(i1 %x, i1 %y) { |
| 322 | +; CHECK-LABEL: @not_true_not_use2( |
| 323 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 324 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 325 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 326 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]] |
| 327 | +; CHECK-NEXT: ret i1 [[R]] |
| 328 | +; |
| 329 | + %notx = xor i1 %x, true |
| 330 | + %noty = xor i1 %y, true |
| 331 | + call void @use(i1 %noty) |
| 332 | + %r = select i1 %notx, i1 true, i1 %noty |
| 333 | + ret i1 %r |
| 334 | +} |
| 335 | + |
| 336 | +define i1 @not_false_not_use2(i1 %x, i1 %y) { |
| 337 | +; CHECK-LABEL: @not_false_not_use2( |
| 338 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 339 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 340 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false |
| 341 | +; CHECK-NEXT: ret i1 [[R]] |
| 342 | +; |
| 343 | + %notx = xor i1 %x, true |
| 344 | + %noty = xor i1 %y, true |
| 345 | + call void @use(i1 %noty) |
| 346 | + %r = select i1 %notx, i1 false, i1 %noty |
| 347 | + ret i1 %r |
| 348 | +} |
| 349 | + |
| 350 | +define i1 @not_not_true_use3(i1 %x, i1 %y) { |
| 351 | +; CHECK-LABEL: @not_not_true_use3( |
| 352 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 353 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 354 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 355 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 356 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 true, i1 [[NOTY]] |
| 357 | +; CHECK-NEXT: ret i1 [[R]] |
| 358 | +; |
| 359 | + %notx = xor i1 %x, true |
| 360 | + call void @use(i1 %notx) |
| 361 | + %noty = xor i1 %y, true |
| 362 | + call void @use(i1 %noty) |
| 363 | + %r = select i1 %notx, i1 %noty, i1 true |
| 364 | + ret i1 %r |
| 365 | +} |
| 366 | + |
| 367 | +define i1 @not_not_false_use3(i1 %x, i1 %y) { |
| 368 | +; CHECK-LABEL: @not_not_false_use3( |
| 369 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 370 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 371 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 372 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 373 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 [[NOTY]], i1 false |
| 374 | +; CHECK-NEXT: ret i1 [[R]] |
| 375 | +; |
| 376 | + %notx = xor i1 %x, true |
| 377 | + call void @use(i1 %notx) |
| 378 | + %noty = xor i1 %y, true |
| 379 | + call void @use(i1 %noty) |
| 380 | + %r = select i1 %notx, i1 %noty, i1 false |
| 381 | + ret i1 %r |
| 382 | +} |
| 383 | + |
| 384 | +define i1 @not_true_not_use3(i1 %x, i1 %y) { |
| 385 | +; CHECK-LABEL: @not_true_not_use3( |
| 386 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 387 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 388 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 389 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 390 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[NOTX]], i1 true, i1 [[NOTY]] |
| 391 | +; CHECK-NEXT: ret i1 [[R]] |
| 392 | +; |
| 393 | + %notx = xor i1 %x, true |
| 394 | + call void @use(i1 %notx) |
| 395 | + %noty = xor i1 %y, true |
| 396 | + call void @use(i1 %noty) |
| 397 | + %r = select i1 %notx, i1 true, i1 %noty |
| 398 | + ret i1 %r |
| 399 | +} |
| 400 | + |
| 401 | +define i1 @not_false_not_use3(i1 %x, i1 %y) { |
| 402 | +; CHECK-LABEL: @not_false_not_use3( |
| 403 | +; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true |
| 404 | +; CHECK-NEXT: call void @use(i1 [[NOTX]]) |
| 405 | +; CHECK-NEXT: [[NOTY:%.*]] = xor i1 [[Y:%.*]], true |
| 406 | +; CHECK-NEXT: call void @use(i1 [[NOTY]]) |
| 407 | +; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOTY]], i1 false |
| 408 | +; CHECK-NEXT: ret i1 [[R]] |
| 409 | +; |
| 410 | + %notx = xor i1 %x, true |
| 411 | + call void @use(i1 %notx) |
| 412 | + %noty = xor i1 %y, true |
| 413 | + call void @use(i1 %noty) |
| 414 | + %r = select i1 %notx, i1 false, i1 %noty |
| 415 | + ret i1 %r |
| 416 | +} |
0 commit comments