[llvm] 3552f0a - [InstCombine] Add tests for udiv with shl-mul; NFC

Chenbing Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 19:20:20 PST 2022


Author: Chenbing Zheng
Date: 2022-12-09T11:18:31+08:00
New Revision: 3552f0a931dcbdd53ad0f80697fc75f672c04f49

URL: https://github.com/llvm/llvm-project/commit/3552f0a931dcbdd53ad0f80697fc75f672c04f49
DIFF: https://github.com/llvm/llvm-project/commit/3552f0a931dcbdd53ad0f80697fc75f672c04f49.diff

LOG: [InstCombine] Add tests for udiv with shl-mul; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/div-shift.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/div-shift.ll b/llvm/test/Transforms/InstCombine/div-shift.ll
index 2831a808918e..33da4be2cbc8 100644
--- a/llvm/test/Transforms/InstCombine/div-shift.ll
+++ b/llvm/test/Transforms/InstCombine/div-shift.ll
@@ -556,6 +556,51 @@ define i5 @udiv_shl_mul_nuw_swap(i5 %x, i5 %y, i5 %z) {
   ret i5 %d
 }
 
+define i5 @udiv_shl_mul_nuw_exact(i5 %x, i5 %y, i5 %z) {
+; CHECK-LABEL: @udiv_shl_mul_nuw_exact(
+; CHECK-NEXT:    [[M1:%.*]] = shl nuw i5 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[M2:%.*]] = mul nuw i5 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[D:%.*]] = udiv exact i5 [[M1]], [[M2]]
+; CHECK-NEXT:    ret i5 [[D]]
+;
+  %m1 = shl nuw i5 %x, %z
+  %m2 = mul nuw i5 %x, %y
+  %d = udiv exact i5 %m1, %m2
+  ret i5 %d
+}
+
+define <2 x i4> @udiv_shl_mul_nuw_vec(<2 x i4> %x, <2 x i4> %y, <2 x i4> %z) {
+; CHECK-LABEL: @udiv_shl_mul_nuw_vec(
+; CHECK-NEXT:    [[M1:%.*]] = shl nuw <2 x i4> [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    [[M2:%.*]] = mul nuw <2 x i4> [[Y:%.*]], [[X]]
+; CHECK-NEXT:    [[D:%.*]] = udiv <2 x i4> [[M1]], [[M2]]
+; CHECK-NEXT:    ret <2 x i4> [[D]]
+;
+  %m1 = shl nuw <2 x i4> %x, %z
+  %m2 = mul nuw <2 x i4> %y, %x
+  %d = udiv <2 x i4> %m1, %m2
+  ret <2 x i4> %d
+}
+
+; negative test - extra use
+
+define i8 @udiv_shl_mul_nuw_extra_use(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @udiv_shl_mul_nuw_extra_use(
+; CHECK-NEXT:    [[M1:%.*]] = shl nuw i8 [[X:%.*]], [[Z:%.*]]
+; CHECK-NEXT:    call void @use(i8 [[M1]])
+; CHECK-NEXT:    [[M2:%.*]] = mul nuw i8 [[Y:%.*]], [[X]]
+; CHECK-NEXT:    call void @use(i8 [[M2]])
+; CHECK-NEXT:    [[D:%.*]] = udiv i8 [[M1]], [[M2]]
+; CHECK-NEXT:    ret i8 [[D]]
+;
+  %m1 = shl nuw i8 %x, %z
+  call void @use(i8 %m1)
+  %m2 = mul nuw i8 %y, %x
+  call void @use(i8 %m2)
+  %d = udiv i8 %m1, %m2
+  ret i8 %d
+}
+
 ; negative test - sdiv
 
 define i5 @sdiv_shl_mul_nuw(i5 %x, i5 %y, i5 %z) {


        


More information about the llvm-commits mailing list