[llvm] 745f82b - [InstCombine] add tests for X == 0 ? 0 : X * Y ; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 06:08:24 PDT 2021


Author: Filipp Zhinkin
Date: 2021-09-10T09:06:48-04:00
New Revision: 745f82b8d909db1bee8282742acb97f09c68f194

URL: https://github.com/llvm/llvm-project/commit/745f82b8d909db1bee8282742acb97f09c68f194
DIFF: https://github.com/llvm/llvm-project/commit/745f82b8d909db1bee8282742acb97f09c68f194.diff

LOG: [InstCombine] add tests for X == 0 ? 0 : X * Y ; NFC

These are the tests for D108408 with current baseline results.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/select.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 76246e01d89a5..fc288d565a7d1 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -2844,6 +2844,156 @@ define <2 x i1> @partial_false_undef_condval(<2 x i1> %x) {
   ret <2 x i1> %r
 }
 
+define i32 @mul_select_eq_zero(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_eq_zero(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 0, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp eq i32 %x, 0
+  %m = mul i32 %x, %y
+  %r = select i1 %c, i32 0, i32 %m
+  ret i32 %r
+}
+
+define i32 @mul_select_eq_zero_commute(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_eq_zero_commute(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[Y:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X:%.*]], [[Y]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 0, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp eq i32 %y, 0
+  %m = mul i32 %x, %y
+  %r = select i1 %c, i32 0, i32 %m
+  ret i32 %r
+}
+
+define i32 @mul_select_eq_zero_copy_flags(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_eq_zero_copy_flags(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul nuw nsw i32 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 0, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp eq i32 %x, 0
+  %m = mul nuw nsw i32 %x, %y
+  %r = select i1 %c, i32 0, i32 %m
+  ret i32 %r
+}
+
+define i32 @mul_select_ne_zero(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_ne_zero(
+; CHECK-NEXT:    [[C_NOT:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C_NOT]], i32 0, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp ne i32 %x, 0
+  %m = mul i32 %x, %y
+  %r = select i1 %c, i32 %m, i32 0
+  ret i32 %r
+}
+
+define i32 @mul_select_eq_zero_sel_undef(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_eq_zero_sel_undef(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 undef, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp eq i32 %x, 0
+  %m = mul i32 %x, %y
+  %r = select i1 %c, i32 undef, i32 %m
+  ret i32 %r
+}
+
+define i32 @mul_select_eq_zero_multiple_users(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_select_eq_zero_multiple_users(
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    call void @use_i32(i32 [[M]])
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 0, i32 [[M]]
+; CHECK-NEXT:    call void @use_i32(i32 [[M]])
+; CHECK-NEXT:    call void @use_i32(i32 [[R]])
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %m = mul i32 %x, %y
+  call void @use_i32(i32 %m)
+  %c = icmp eq i32 %x, 0
+  %r = select i1 %c, i32 0, i32 %m
+  call void @use_i32(i32 %m)
+  call void @use_i32(i32 %r)
+  ret i32 %r
+}
+
+define i32 @mul_select_eq_zero_unrelated_condition(i32 %x, i32 %y, i32 %z) {
+; CHECK-LABEL: @mul_select_eq_zero_unrelated_condition(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[Z:%.*]], 0
+; CHECK-NEXT:    [[M:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 0, i32 [[M]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %c = icmp eq i32 %z, 0
+  %m = mul i32 %x, %y
+  %r = select i1 %c, i32 0, i32 %m
+  ret i32 %r
+}
+
+define <4 x i32> @mul_select_eq_zero_vector(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: @mul_select_eq_zero_vector(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq <4 x i32> [[X:%.*]], zeroinitializer
+; CHECK-NEXT:    [[M:%.*]] = mul <4 x i32> [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select <4 x i1> [[C]], <4 x i32> zeroinitializer, <4 x i32> [[M]]
+; CHECK-NEXT:    ret <4 x i32> [[R]]
+;
+  %c = icmp eq <4 x i32> %x, zeroinitializer
+  %m = mul <4 x i32> %x, %y
+  %r = select <4 x i1> %c, <4 x i32> zeroinitializer, <4 x i32> %m
+  ret <4 x i32> %r
+}
+
+define <2 x i32> @mul_select_eq_undef_vector(<2 x i32> %x, <2 x i32> %y) {
+; CHECK-LABEL: @mul_select_eq_undef_vector(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 0, i32 undef>
+; CHECK-NEXT:    [[M:%.*]] = mul <2 x i32> [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> <i32 0, i32 42>, <2 x i32> [[M]]
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %c = icmp eq <2 x i32> %x, <i32 0, i32 undef>
+  %m = mul <2 x i32> %x, %y
+  %r = select <2 x i1> %c, <2 x i32> <i32 0, i32 42>, <2 x i32> %m
+  ret <2 x i32> %r
+}
+
+define <2 x i32> @mul_select_eq_zero_sel_undef_vector(<2 x i32> %x, <2 x i32> %y) {
+; CHECK-LABEL: @mul_select_eq_zero_sel_undef_vector(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer
+; CHECK-NEXT:    [[M:%.*]] = mul <2 x i32> [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> <i32 0, i32 undef>, <2 x i32> [[M]]
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %c = icmp eq <2 x i32> %x, zeroinitializer
+  %m = mul <2 x i32> %x, %y
+  %r = select <2 x i1> %c, <2 x i32> <i32 0, i32 undef>, <2 x i32> %m
+  ret <2 x i32> %r
+}
+
+define <2 x i32> @mul_select_eq_undef_vector_not_merging_to_zero(<2 x i32> %x, <2 x i32> %y) {
+; CHECK-LABEL: @mul_select_eq_undef_vector_not_merging_to_zero(
+; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i32> [[X:%.*]], <i32 0, i32 undef>
+; CHECK-NEXT:    [[M:%.*]] = mul <2 x i32> [[X]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> <i32 1, i32 0>, <2 x i32> [[M]]
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %c = icmp eq <2 x i32> %x, <i32 0, i32 undef>
+  %m = mul <2 x i32> %x, %y
+  %r = select <2 x i1> %c, <2 x i32> <i32 1, i32 0>, <2 x i32> %m
+  ret <2 x i32> %r
+}
+
 declare void @use(i1)
 declare void @use_i8(i8)
+declare void @use_i32(i32)
 declare i32 @llvm.cttz.i32(i32, i1 immarg)


        


More information about the llvm-commits mailing list