@@ -360,8 +360,56 @@ 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 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 %y , i32 %z ) {
377
+ ; CHECK-LABEL: @shl_add_lshr(
378
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
379
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
380
+ ; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
381
+ ; CHECK-NEXT: ret i32 [[RES]]
382
+ ;
383
+ %shl = shl nuw i32 %x , %y
384
+ %add = add nuw nsw i32 %shl , %z
385
+ %res = lshr exact i32 %add , %z
386
+ ret i32 %res
387
+ }
388
+
389
+ define i32 @lshr_mul_times_3_div_2 (i32 %0 ) {
390
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2(
391
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[TMP0:%.*]], 3
392
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
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
+
363
400
; Negative test
364
401
402
+ define i32 @mul_times_3_div_2_no_nsw (i32 %x ) {
403
+ ; CHECK-LABEL: @mul_times_3_div_2_no_nsw(
404
+ ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], 3
405
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
406
+ ; CHECK-NEXT: ret i32 [[LSHR]]
407
+ ;
408
+ %mul = mul i32 %x , 3
409
+ %lshr = lshr i32 %mul , 1
410
+ ret i32 %lshr
411
+ }
412
+
365
413
define i32 @mul_splat_fold_wrong_mul_const (i32 %x ) {
366
414
; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
367
415
; CHECK-NEXT: [[M:%.*]] = mul nuw i32 [[X:%.*]], 65538
@@ -373,7 +421,44 @@ define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
373
421
ret i32 %t
374
422
}
375
423
376
- ; Negative test
424
+ define i32 @shl_add_lshr_multiuse (i32 %x , i32 %y , i32 %z ) {
425
+ ; CHECK-LABEL: @shl_add_lshr_multiuse(
426
+ ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
427
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
428
+ ; CHECK-NEXT: call void @use(i32 [[ADD]])
429
+ ; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
430
+ ; CHECK-NEXT: ret i32 [[RES]]
431
+ ;
432
+ %shl = shl nuw i32 %x , %y
433
+ %add = add nuw nsw i32 %shl , %z
434
+ call void @use (i32 %add )
435
+ %res = lshr exact i32 %add , %z
436
+ ret i32 %res
437
+ }
438
+
439
+ define i32 @mul_times_3_div_2_multiuse (i32 %x ) {
440
+ ; CHECK-LABEL: @mul_times_3_div_2_multiuse(
441
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
442
+ ; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
443
+ ; CHECK-NEXT: call void @use(i32 [[MUL]])
444
+ ; CHECK-NEXT: ret i32 [[RES]]
445
+ ;
446
+ %mul = mul nuw i32 %x , 3
447
+ %res = lshr i32 %mul , 1
448
+ call void @use (i32 %mul )
449
+ ret i32 %res
450
+ }
451
+
452
+ define i32 @lshr_mul_times_3_div_2_nsw (i32 %0 ) {
453
+ ; CHECK-LABEL: @lshr_mul_times_3_div_2_nsw(
454
+ ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP0:%.*]], 3
455
+ ; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
456
+ ; CHECK-NEXT: ret i32 [[LSHR]]
457
+ ;
458
+ %mul = mul nsw i32 %0 , 3
459
+ %lshr = lshr i32 %mul , 1
460
+ ret i32 %lshr
461
+ }
377
462
378
463
define i32 @mul_splat_fold_wrong_lshr_const (i32 %x ) {
379
464
; CHECK-LABEL: @mul_splat_fold_wrong_lshr_const(
@@ -386,8 +471,6 @@ define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
386
471
ret i32 %t
387
472
}
388
473
389
- ; Negative test
390
-
391
474
define i32 @mul_splat_fold_no_nuw (i32 %x ) {
392
475
; CHECK-LABEL: @mul_splat_fold_no_nuw(
393
476
; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[X:%.*]], 65537
0 commit comments