@@ -332,3 +332,185 @@ define i64 @lshr_mul_negative_nsw(i64 %0) {
332
332
%3 = lshr i64 %2 , 2
333
333
ret i64 %3
334
334
}
335
+
336
+ define i8 @shl_add (i8 %x , i8 %y ) {
337
+ ; CHECK-LABEL: @shl_add(
338
+ ; CHECK-NEXT: [[SH0:%.*]] = shl i8 [[X:%.*]], 3
339
+ ; CHECK-NEXT: [[R:%.*]] = add i8 [[SH0]], [[Y:%.*]]
340
+ ; CHECK-NEXT: [[SH1:%.*]] = shl i8 [[R]], 2
341
+ ; CHECK-NEXT: ret i8 [[SH1]]
342
+ ;
343
+ %sh0 = shl i8 %x , 3
344
+ %r = add i8 %sh0 , %y
345
+ %sh1 = shl i8 %r , 2
346
+ ret i8 %sh1
347
+ }
348
+
349
+ define <2 x i8 > @shl_add_nonuniform (<2 x i8 > %x , <2 x i8 > %y ) {
350
+ ; CHECK-LABEL: @shl_add_nonuniform(
351
+ ; CHECK-NEXT: [[SH0:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 4>
352
+ ; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[SH0]], [[Y:%.*]]
353
+ ; CHECK-NEXT: [[SH1:%.*]] = shl <2 x i8> [[R]], <i8 2, i8 0>
354
+ ; CHECK-NEXT: ret <2 x i8> [[SH1]]
355
+ ;
356
+ %sh0 = shl <2 x i8 > %x , <i8 3 , i8 4 >
357
+ %r = add <2 x i8 > %sh0 , %y
358
+ %sh1 = shl <2 x i8 > %r , <i8 2 , i8 0 >
359
+ ret <2 x i8 > %sh1
360
+ }
361
+
362
+
363
+ define <2 x i64 > @shl_add_undef (<2 x i64 > %x , <2 x i64 > %py ) {
364
+ ; CHECK-LABEL: @shl_add_undef(
365
+ ; CHECK-NEXT: [[Y:%.*]] = srem <2 x i64> [[PY:%.*]], <i64 42, i64 42>
366
+ ; CHECK-NEXT: [[SH0:%.*]] = shl <2 x i64> [[X:%.*]], <i64 5, i64 undef>
367
+ ; CHECK-NEXT: [[R:%.*]] = add <2 x i64> [[Y]], [[SH0]]
368
+ ; CHECK-NEXT: [[SH1:%.*]] = shl <2 x i64> [[R]], <i64 7, i64 undef>
369
+ ; CHECK-NEXT: ret <2 x i64> [[SH1]]
370
+ ;
371
+ %y = srem <2 x i64 > %py , <i64 42 , i64 42 > ; thwart complexity-based canonicalization
372
+ %sh0 = shl <2 x i64 > %x , <i64 5 , i64 undef >
373
+ %r = add <2 x i64 > %y , %sh0
374
+ %sh1 = shl <2 x i64 > %r , <i64 7 , i64 undef >
375
+ ret <2 x i64 > %sh1
376
+ }
377
+
378
+
379
+ define i8 @lshr_add (i8 %x , i8 %y ) {
380
+ ; CHECK-LABEL: @lshr_add(
381
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr i8 [[X:%.*]], 3
382
+ ; CHECK-NEXT: [[R:%.*]] = add i8 [[SH0]], [[Y:%.*]]
383
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr i8 [[R]], 2
384
+ ; CHECK-NEXT: ret i8 [[SH1]]
385
+ ;
386
+ %sh0 = lshr i8 %x , 3
387
+ %r = add i8 %sh0 , %y
388
+ %sh1 = lshr i8 %r , 2
389
+ ret i8 %sh1
390
+ }
391
+
392
+ define <2 x i8 > @lshr_add_nonuniform (<2 x i8 > %x , <2 x i8 > %y ) {
393
+ ; CHECK-LABEL: @lshr_add_nonuniform(
394
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 3, i8 4>
395
+ ; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[SH0]], [[Y:%.*]]
396
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr <2 x i8> [[R]], <i8 2, i8 0>
397
+ ; CHECK-NEXT: ret <2 x i8> [[SH1]]
398
+ ;
399
+ %sh0 = lshr <2 x i8 > %x , <i8 3 , i8 4 >
400
+ %r = add <2 x i8 > %sh0 , %y
401
+ %sh1 = lshr <2 x i8 > %r , <i8 2 , i8 0 >
402
+ ret <2 x i8 > %sh1
403
+ }
404
+
405
+ define <2 x i64 > @lshr_add_undef (<2 x i64 > %x , <2 x i64 > %py ) {
406
+ ; CHECK-LABEL: @lshr_add_undef(
407
+ ; CHECK-NEXT: [[Y:%.*]] = srem <2 x i64> [[PY:%.*]], <i64 42, i64 42>
408
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr <2 x i64> [[X:%.*]], <i64 5, i64 undef>
409
+ ; CHECK-NEXT: [[R:%.*]] = add <2 x i64> [[Y]], [[SH0]]
410
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr <2 x i64> [[R]], <i64 7, i64 undef>
411
+ ; CHECK-NEXT: ret <2 x i64> [[SH1]]
412
+ ;
413
+ %y = srem <2 x i64 > %py , <i64 42 , i64 42 > ; thwart complexity-based canonicalization
414
+ %sh0 = lshr <2 x i64 > %x , <i64 5 , i64 undef >
415
+ %r = add <2 x i64 > %y , %sh0
416
+ %sh1 = lshr <2 x i64 > %r , <i64 7 , i64 undef >
417
+ ret <2 x i64 > %sh1
418
+ }
419
+
420
+ define i8 @shl_sub (i8 %x , i8 %y ) {
421
+ ; CHECK-LABEL: @shl_sub(
422
+ ; CHECK-NEXT: [[SH0:%.*]] = shl i8 [[X:%.*]], 3
423
+ ; CHECK-NEXT: [[R:%.*]] = sub i8 [[SH0]], [[Y:%.*]]
424
+ ; CHECK-NEXT: [[SH1:%.*]] = shl i8 [[R]], 2
425
+ ; CHECK-NEXT: ret i8 [[SH1]]
426
+ ;
427
+ %sh0 = shl i8 %x , 3
428
+ %r = sub i8 %sh0 , %y
429
+ %sh1 = shl i8 %r , 2
430
+ ret i8 %sh1
431
+ }
432
+
433
+ ; Make sure we don't commute operands for sub
434
+ define i8 @shl_sub_no_commute (i8 %x , i8 %y ) {
435
+ ; CHECK-LABEL: @shl_sub_no_commute(
436
+ ; CHECK-NEXT: [[SH0:%.*]] = shl i8 [[Y:%.*]], 3
437
+ ; CHECK-NEXT: [[R:%.*]] = sub i8 [[X:%.*]], [[SH0]]
438
+ ; CHECK-NEXT: [[SH1:%.*]] = shl i8 [[R]], 2
439
+ ; CHECK-NEXT: ret i8 [[SH1]]
440
+ ;
441
+ %sh0 = shl i8 %y , 3
442
+ %r = sub i8 %x , %sh0
443
+ %sh1 = shl i8 %r , 2
444
+ ret i8 %sh1
445
+ }
446
+
447
+ define <2 x i8 > @shl_sub_nonuniform (<2 x i8 > %x , <2 x i8 > %y ) {
448
+ ; CHECK-LABEL: @shl_sub_nonuniform(
449
+ ; CHECK-NEXT: [[SH0:%.*]] = shl <2 x i8> [[X:%.*]], <i8 3, i8 4>
450
+ ; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[SH0]], [[Y:%.*]]
451
+ ; CHECK-NEXT: [[SH1:%.*]] = shl <2 x i8> [[R]], <i8 2, i8 0>
452
+ ; CHECK-NEXT: ret <2 x i8> [[SH1]]
453
+ ;
454
+ %sh0 = shl <2 x i8 > %x , <i8 3 , i8 4 >
455
+ %r = sub <2 x i8 > %sh0 , %y
456
+ %sh1 = shl <2 x i8 > %r , <i8 2 , i8 0 >
457
+ ret <2 x i8 > %sh1
458
+ }
459
+
460
+
461
+ define <2 x i64 > @shl_sub_undef (<2 x i64 > %x , <2 x i64 > %py ) {
462
+ ; CHECK-LABEL: @shl_sub_undef(
463
+ ; CHECK-NEXT: [[Y:%.*]] = srem <2 x i64> [[PY:%.*]], <i64 42, i64 42>
464
+ ; CHECK-NEXT: [[SH0:%.*]] = shl <2 x i64> [[X:%.*]], <i64 5, i64 undef>
465
+ ; CHECK-NEXT: [[R:%.*]] = sub <2 x i64> [[Y]], [[SH0]]
466
+ ; CHECK-NEXT: [[SH1:%.*]] = shl <2 x i64> [[R]], <i64 7, i64 undef>
467
+ ; CHECK-NEXT: ret <2 x i64> [[SH1]]
468
+ ;
469
+ %y = srem <2 x i64 > %py , <i64 42 , i64 42 > ; thwart complexity-based canonicalization
470
+ %sh0 = shl <2 x i64 > %x , <i64 5 , i64 undef >
471
+ %r = sub <2 x i64 > %y , %sh0
472
+ %sh1 = shl <2 x i64 > %r , <i64 7 , i64 undef >
473
+ ret <2 x i64 > %sh1
474
+ }
475
+
476
+
477
+ define i8 @lshr_sub (i8 %x , i8 %y ) {
478
+ ; CHECK-LABEL: @lshr_sub(
479
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr i8 [[X:%.*]], 3
480
+ ; CHECK-NEXT: [[R:%.*]] = sub i8 [[SH0]], [[Y:%.*]]
481
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr i8 [[R]], 2
482
+ ; CHECK-NEXT: ret i8 [[SH1]]
483
+ ;
484
+ %sh0 = lshr i8 %x , 3
485
+ %r = sub i8 %sh0 , %y
486
+ %sh1 = lshr i8 %r , 2
487
+ ret i8 %sh1
488
+ }
489
+
490
+ define <2 x i8 > @lshr_sub_nonuniform (<2 x i8 > %x , <2 x i8 > %y ) {
491
+ ; CHECK-LABEL: @lshr_sub_nonuniform(
492
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 3, i8 4>
493
+ ; CHECK-NEXT: [[R:%.*]] = sub <2 x i8> [[SH0]], [[Y:%.*]]
494
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr <2 x i8> [[R]], <i8 2, i8 0>
495
+ ; CHECK-NEXT: ret <2 x i8> [[SH1]]
496
+ ;
497
+ %sh0 = lshr <2 x i8 > %x , <i8 3 , i8 4 >
498
+ %r = sub <2 x i8 > %sh0 , %y
499
+ %sh1 = lshr <2 x i8 > %r , <i8 2 , i8 0 >
500
+ ret <2 x i8 > %sh1
501
+ }
502
+
503
+ define <2 x i64 > @lshr_sub_undef (<2 x i64 > %x , <2 x i64 > %py ) {
504
+ ; CHECK-LABEL: @lshr_sub_undef(
505
+ ; CHECK-NEXT: [[Y:%.*]] = srem <2 x i64> [[PY:%.*]], <i64 42, i64 42>
506
+ ; CHECK-NEXT: [[SH0:%.*]] = lshr <2 x i64> [[X:%.*]], <i64 5, i64 undef>
507
+ ; CHECK-NEXT: [[R:%.*]] = sub <2 x i64> [[Y]], [[SH0]]
508
+ ; CHECK-NEXT: [[SH1:%.*]] = lshr <2 x i64> [[R]], <i64 7, i64 undef>
509
+ ; CHECK-NEXT: ret <2 x i64> [[SH1]]
510
+ ;
511
+ %y = srem <2 x i64 > %py , <i64 42 , i64 42 > ; thwart complexity-based canonicalization
512
+ %sh0 = lshr <2 x i64 > %x , <i64 5 , i64 undef >
513
+ %r = sub <2 x i64 > %y , %sh0
514
+ %sh1 = lshr <2 x i64 > %r , <i64 7 , i64 undef >
515
+ ret <2 x i64 > %sh1
516
+ }
0 commit comments