@@ -295,11 +295,12 @@ define <2 x i32> @t16(<2 x i32> %x, <2 x i32> %y) {
295
295
ret <2 x i32 > %r
296
296
}
297
297
298
+ ; (X * Y) s/ (X << Z) --> Y s/ (1 << Z)
299
+
298
300
define i5 @sdiv_mul_shl_nsw (i5 %x , i5 %y , i5 %z ) {
299
301
; CHECK-LABEL: @sdiv_mul_shl_nsw(
300
- ; CHECK-NEXT: [[M1:%.*]] = mul nsw i5 [[X:%.*]], [[Y:%.*]]
301
- ; CHECK-NEXT: [[M2:%.*]] = shl nsw i5 [[X]], [[Z:%.*]]
302
- ; CHECK-NEXT: [[D:%.*]] = sdiv i5 [[M1]], [[M2]]
302
+ ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i5 1, [[Z:%.*]]
303
+ ; CHECK-NEXT: [[D:%.*]] = sdiv i5 [[Y:%.*]], [[TMP1]]
303
304
; CHECK-NEXT: ret i5 [[D]]
304
305
;
305
306
%m1 = mul nsw i5 %x , %y
@@ -308,11 +309,12 @@ define i5 @sdiv_mul_shl_nsw(i5 %x, i5 %y, i5 %z) {
308
309
ret i5 %d
309
310
}
310
311
312
+ ; (Y * Z) s/ (X << Z) --> Y s/ (1 << Z)
313
+
311
314
define i5 @sdiv_mul_shl_nsw_commute1 (i5 %x , i5 %y , i5 %z ) {
312
315
; CHECK-LABEL: @sdiv_mul_shl_nsw_commute1(
313
- ; CHECK-NEXT: [[M1:%.*]] = mul nsw i5 [[Y:%.*]], [[X:%.*]]
314
- ; CHECK-NEXT: [[M2:%.*]] = shl nsw i5 [[X]], [[Z:%.*]]
315
- ; CHECK-NEXT: [[D:%.*]] = sdiv i5 [[M1]], [[M2]]
316
+ ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i5 1, [[Z:%.*]]
317
+ ; CHECK-NEXT: [[D:%.*]] = sdiv i5 [[Y:%.*]], [[TMP1]]
316
318
; CHECK-NEXT: ret i5 [[D]]
317
319
;
318
320
%m1 = mul nsw i5 %y , %x
@@ -321,6 +323,8 @@ define i5 @sdiv_mul_shl_nsw_commute1(i5 %x, i5 %y, i5 %z) {
321
323
ret i5 %d
322
324
}
323
325
326
+ ; negative test - shl is not commutative
327
+
324
328
define i5 @sdiv_mul_shl_nsw_commute2 (i5 %x , i5 %y , i5 %z ) {
325
329
; CHECK-LABEL: @sdiv_mul_shl_nsw_commute2(
326
330
; CHECK-NEXT: [[M1:%.*]] = mul nsw i5 [[Y:%.*]], [[X:%.*]]
@@ -334,12 +338,14 @@ define i5 @sdiv_mul_shl_nsw_commute2(i5 %x, i5 %y, i5 %z) {
334
338
ret i5 %d
335
339
}
336
340
341
+ ; extra use is ok
342
+
337
343
define i8 @sdiv_mul_shl_nsw_use1 (i8 %x , i8 %y , i8 %z ) {
338
344
; CHECK-LABEL: @sdiv_mul_shl_nsw_use1(
339
345
; CHECK-NEXT: [[M1:%.*]] = mul nsw i8 [[X:%.*]], [[Y:%.*]]
340
346
; CHECK-NEXT: call void @use(i8 [[M1]])
341
- ; CHECK-NEXT: [[M2 :%.*]] = shl nsw i8 [[X]] , [[Z:%.*]]
342
- ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[M1 ]], [[M2 ]]
347
+ ; CHECK-NEXT: [[TMP1 :%.*]] = shl nuw i8 1 , [[Z:%.*]]
348
+ ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[Y ]], [[TMP1 ]]
343
349
; CHECK-NEXT: ret i8 [[D]]
344
350
;
345
351
%m1 = mul nsw i8 %x , %y
@@ -349,12 +355,14 @@ define i8 @sdiv_mul_shl_nsw_use1(i8 %x, i8 %y, i8 %z) {
349
355
ret i8 %d
350
356
}
351
357
358
+ ; extra use is ok
359
+
352
360
define i8 @sdiv_mul_shl_nsw_use2 (i8 %x , i8 %y , i8 %z ) {
353
361
; CHECK-LABEL: @sdiv_mul_shl_nsw_use2(
354
- ; CHECK-NEXT: [[M1:%.*]] = mul nsw i8 [[X:%.*]], [[Y:%.*]]
355
- ; CHECK-NEXT: [[M2:%.*]] = shl nsw i8 [[X]], [[Z:%.*]]
362
+ ; CHECK-NEXT: [[M2:%.*]] = shl nsw i8 [[X:%.*]], [[Z:%.*]]
356
363
; CHECK-NEXT: call void @use(i8 [[M2]])
357
- ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[M1]], [[M2]]
364
+ ; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i8 1, [[Z]]
365
+ ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[Y:%.*]], [[TMP1]]
358
366
; CHECK-NEXT: ret i8 [[D]]
359
367
;
360
368
%m1 = mul nsw i8 %x , %y
@@ -364,6 +372,8 @@ define i8 @sdiv_mul_shl_nsw_use2(i8 %x, i8 %y, i8 %z) {
364
372
ret i8 %d
365
373
}
366
374
375
+ ; negative test - both operands can't have extra uses
376
+
367
377
define i8 @sdiv_mul_shl_nsw_use3 (i8 %x , i8 %y , i8 %z ) {
368
378
; CHECK-LABEL: @sdiv_mul_shl_nsw_use3(
369
379
; CHECK-NEXT: [[M1:%.*]] = mul nsw i8 [[X:%.*]], [[Y:%.*]]
@@ -381,6 +391,8 @@ define i8 @sdiv_mul_shl_nsw_use3(i8 %x, i8 %y, i8 %z) {
381
391
ret i8 %d
382
392
}
383
393
394
+ ; negative test - shl must be divisor
395
+
384
396
define i5 @sdiv_shl_mul_nsw (i5 %x , i5 %y , i5 %z ) {
385
397
; CHECK-LABEL: @sdiv_shl_mul_nsw(
386
398
; CHECK-NEXT: [[M1:%.*]] = shl nsw i5 [[Z:%.*]], [[X:%.*]]
@@ -394,6 +406,8 @@ define i5 @sdiv_shl_mul_nsw(i5 %x, i5 %y, i5 %z) {
394
406
ret i5 %d
395
407
}
396
408
409
+ ; negative test - wrong no-wrap
410
+
397
411
define i5 @sdiv_mul_shl_missing_nsw1 (i5 %x , i5 %y , i5 %z ) {
398
412
; CHECK-LABEL: @sdiv_mul_shl_missing_nsw1(
399
413
; CHECK-NEXT: [[M1:%.*]] = mul nsw i5 [[X:%.*]], [[Y:%.*]]
@@ -407,6 +421,8 @@ define i5 @sdiv_mul_shl_missing_nsw1(i5 %x, i5 %y, i5 %z) {
407
421
ret i5 %d
408
422
}
409
423
424
+ ; negative test - wrong no-wrap
425
+
410
426
define i5 @sdiv_mul_shl_missing_nsw2 (i5 %x , i5 %y , i5 %z ) {
411
427
; CHECK-LABEL: @sdiv_mul_shl_missing_nsw2(
412
428
; CHECK-NEXT: [[M1:%.*]] = mul nuw i5 [[X:%.*]], [[Y:%.*]]
0 commit comments