@@ -360,7 +360,79 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
360
360
ret <3 x i14 > %t
361
361
}
362
362
363
- ; Negative test
363
+ ; Negative tests
364
+
365
+ define i32 @mul_times_3_div_2 (i32 %x ) {
366
+ ; CHECK-LABEL: @mul_times_3_div_2(
367
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[X:%.*]], 3
368
+ ; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
369
+ ; CHECK-NEXT: ret i32 [[RES]]
370
+ ;
371
+ %mul = mul nsw nuw i32 %x , 3
372
+ %res = lshr i32 %mul , 1
373
+ ret i32 %res
374
+ }
375
+
376
+ define i32 @shl_add_lshr (i32 %x , i32 %c , i32 %y ) {
377
+ ; CHECK-LABEL: @shl_add_lshr(
378
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
379
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Y:%.*]]
380
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[ADD]], [[C]]
381
+ ; CHECK-NEXT: ret i32 [[LSHR]]
382
+ ;
383
+ %shl = shl nuw i32 %x , %c
384
+ %add = add nuw nsw i32 %shl , %y
385
+ %lshr = lshr exact i32 %add , %c
386
+ ret i32 %lshr
387
+ }
388
+
389
+ define i32 @lshr_mul_times_3_div_2_nuw (i32 %0 ) {
390
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2_nuw(
391
+ ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP0:%.*]], 1
392
+ ; CHECK-NEXT: [[LSHR:%.*]] = add nuw nsw i32 [[TMP2]], [[TMP0]]
393
+ ; CHECK-NEXT: ret i32 [[LSHR]]
394
+ ;
395
+ %mul = mul nuw i32 %0 , 3
396
+ %lshr = lshr i32 %mul , 1
397
+ ret i32 %lshr
398
+ }
399
+
400
+ define i32 @lshr_mul_times_3_div_2_nsw (i32 %0 ) {
401
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2_nsw(
402
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP0:%.*]], 3
403
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
404
+ ; CHECK-NEXT: ret i32 [[LSHR]]
405
+ ;
406
+ %mul = mul nsw i32 %0 , 3
407
+ %lshr = lshr i32 %mul , 1
408
+ ret i32 %lshr
409
+ }
410
+
411
+ ; Negative tests
412
+
413
+ define i32 @mul_times_3_div_2_no_flag (i32 %x ) {
414
+ ; CHECK-LABEL: @mul_times_3_div_2_no_flag(
415
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], 3
416
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
417
+ ; CHECK-NEXT: ret i32 [[LSHR]]
418
+ ;
419
+ %mul = mul i32 %x , 3
420
+ %lshr = lshr i32 %mul , 1
421
+ ret i32 %lshr
422
+ }
423
+
424
+ define i32 @shl_add_lshr_neg (i32 %x , i32 %y , i32 %z ) {
425
+ ; CHECK-LABEL: @shl_add_lshr_neg(
426
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
427
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
428
+ ; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
429
+ ; CHECK-NEXT: ret i32 [[RES]]
430
+ ;
431
+ %shl = shl nuw i32 %x , %y
432
+ %add = add nuw nsw i32 %shl , %z
433
+ %res = lshr exact i32 %add , %z
434
+ ret i32 %res
435
+ }
364
436
365
437
define i32 @mul_splat_fold_wrong_mul_const (i32 %x ) {
366
438
; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
@@ -373,7 +445,33 @@ define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
373
445
ret i32 %t
374
446
}
375
447
376
- ; Negative test
448
+ define i32 @shl_add_lshr_multiuse (i32 %x , i32 %y , i32 %z ) {
449
+ ; CHECK-LABEL: @shl_add_lshr_multiuse(
450
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
451
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
452
+ ; CHECK-NEXT: call void @use(i32 [[ADD]])
453
+ ; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
454
+ ; CHECK-NEXT: ret i32 [[RES]]
455
+ ;
456
+ %shl = shl nuw i32 %x , %y
457
+ %add = add nuw nsw i32 %shl , %z
458
+ call void @use (i32 %add )
459
+ %res = lshr exact i32 %add , %z
460
+ ret i32 %res
461
+ }
462
+
463
+ define i32 @mul_times_3_div_2_multiuse (i32 %x ) {
464
+ ; CHECK-LABEL: @mul_times_3_div_2_multiuse(
465
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
466
+ ; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
467
+ ; CHECK-NEXT: call void @use(i32 [[MUL]])
468
+ ; CHECK-NEXT: ret i32 [[RES]]
469
+ ;
470
+ %mul = mul nuw i32 %x , 3
471
+ %res = lshr i32 %mul , 1
472
+ call void @use (i32 %mul )
473
+ ret i32 %res
474
+ }
377
475
378
476
define i32 @mul_splat_fold_wrong_lshr_const (i32 %x ) {
379
477
; CHECK-LABEL: @mul_splat_fold_wrong_lshr_const(
@@ -386,8 +484,6 @@ define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
386
484
ret i32 %t
387
485
}
388
486
389
- ; Negative test
390
-
391
487
define i32 @mul_splat_fold_no_nuw (i32 %x ) {
392
488
; CHECK-LABEL: @mul_splat_fold_no_nuw(
393
489
; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[X:%.*]], 65537
0 commit comments