[InstSimplify] fold implied cmp with zero (PR35790)

This doesn't handle the more complicated case in the bug report yet:
https://bugs.llvm.org/show_bug.cgi?id=35790

For that, we have to match / look through a cast.

llvm-svn: 322327
diff --git a/llvm/test/Transforms/InstSimplify/and-or-icmp-zero.ll b/llvm/test/Transforms/InstSimplify/and-or-icmp-zero.ll
index 91a2983..af384fa 100644
--- a/llvm/test/Transforms/InstSimplify/and-or-icmp-zero.ll
+++ b/llvm/test/Transforms/InstSimplify/and-or-icmp-zero.ll
@@ -8,11 +8,9 @@
 
 define i1 @or_cmps_eq_zero_with_mask_commute1(i64 %x, i64 %y) {
 ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute1(
-; CHECK-NEXT:    [[ISNULL:%.*]] = icmp eq i64 %x, 0
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and i64 %x, %y
 ; CHECK-NEXT:    [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i64 [[SOMEBITS]], 0
-; CHECK-NEXT:    [[R:%.*]] = or i1 [[SOMEBITS_ARE_ZERO]], [[ISNULL]]
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 [[SOMEBITS_ARE_ZERO]]
 ;
   %isnull = icmp eq i64 %x, 0
   %somebits = and i64 %x, %y
@@ -25,11 +23,9 @@
 
 define <2 x i1> @or_cmps_eq_zero_with_mask_commute2(<2 x i64> %x, <2 x i64> %y) {
 ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute2(
-; CHECK-NEXT:    [[ISNULL:%.*]] = icmp eq <2 x i64> %x, zeroinitializer
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and <2 x i64> %x, %y
 ; CHECK-NEXT:    [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i64> [[SOMEBITS]], zeroinitializer
-; CHECK-NEXT:    [[R:%.*]] = or <2 x i1> [[ISNULL]], [[SOMEBITS_ARE_ZERO]]
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> [[SOMEBITS_ARE_ZERO]]
 ;
   %isnull = icmp eq <2 x i64> %x, zeroinitializer
   %somebits = and <2 x i64> %x, %y
@@ -42,11 +38,9 @@
 
 define i1 @or_cmps_eq_zero_with_mask_commute3(i4 %x, i4 %y) {
 ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute3(
-; CHECK-NEXT:    [[ISNULL:%.*]] = icmp eq i4 %x, 0
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and i4 %y, %x
 ; CHECK-NEXT:    [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i4 [[SOMEBITS]], 0
-; CHECK-NEXT:    [[R:%.*]] = or i1 [[SOMEBITS_ARE_ZERO]], [[ISNULL]]
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 [[SOMEBITS_ARE_ZERO]]
 ;
   %isnull = icmp eq i4 %x, 0
   %somebits = and i4 %y, %x
@@ -59,11 +53,9 @@
 
 define <2 x i1> @or_cmps_eq_zero_with_mask_commute4(<2 x i4> %x, <2 x i4> %y) {
 ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute4(
-; CHECK-NEXT:    [[ISNULL:%.*]] = icmp eq <2 x i4> %x, zeroinitializer
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and <2 x i4> %y, %x
 ; CHECK-NEXT:    [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[SOMEBITS]], zeroinitializer
-; CHECK-NEXT:    [[R:%.*]] = or <2 x i1> [[ISNULL]], [[SOMEBITS_ARE_ZERO]]
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> [[SOMEBITS_ARE_ZERO]]
 ;
   %isnull = icmp eq <2 x i4> %x, zeroinitializer
   %somebits = and <2 x i4> %y, %x
@@ -76,11 +68,9 @@
 
 define <3 x i1> @and_cmps_eq_zero_with_mask_commute1(<3 x i4> %x, <3 x i4> %y) {
 ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute1(
-; CHECK-NEXT:    [[ISNOTNULL:%.*]] = icmp ne <3 x i4> %x, zeroinitializer
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and <3 x i4> %x, %y
 ; CHECK-NEXT:    [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i4> [[SOMEBITS]], zeroinitializer
-; CHECK-NEXT:    [[R:%.*]] = and <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]], [[ISNOTNULL]]
-; CHECK-NEXT:    ret <3 x i1> [[R]]
+; CHECK-NEXT:    ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]]
 ;
   %isnotnull = icmp ne <3 x i4> %x, zeroinitializer
   %somebits = and <3 x i4> %x, %y
@@ -93,11 +83,9 @@
 
 define i1 @and_cmps_eq_zero_with_mask_commute2(i4 %x, i4 %y) {
 ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute2(
-; CHECK-NEXT:    [[ISNOTNULL:%.*]] = icmp ne i4 %x, 0
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and i4 %x, %y
 ; CHECK-NEXT:    [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i4 [[SOMEBITS]], 0
-; CHECK-NEXT:    [[R:%.*]] = and i1 [[ISNOTNULL]], [[SOMEBITS_ARE_NOT_ZERO]]
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 [[SOMEBITS_ARE_NOT_ZERO]]
 ;
   %isnotnull = icmp ne i4 %x, 0
   %somebits = and i4 %x, %y
@@ -110,11 +98,9 @@
 
 define <3 x i1> @and_cmps_eq_zero_with_mask_commute3(<3 x i64> %x, <3 x i64> %y) {
 ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute3(
-; CHECK-NEXT:    [[ISNOTNULL:%.*]] = icmp ne <3 x i64> %x, zeroinitializer
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and <3 x i64> %y, %x
 ; CHECK-NEXT:    [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i64> [[SOMEBITS]], zeroinitializer
-; CHECK-NEXT:    [[R:%.*]] = and <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]], [[ISNOTNULL]]
-; CHECK-NEXT:    ret <3 x i1> [[R]]
+; CHECK-NEXT:    ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]]
 ;
   %isnotnull = icmp ne <3 x i64> %x, zeroinitializer
   %somebits = and <3 x i64> %y, %x
@@ -127,11 +113,9 @@
 
 define i1 @and_cmps_eq_zero_with_mask_commute4(i64 %x, i64 %y) {
 ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute4(
-; CHECK-NEXT:    [[ISNOTNULL:%.*]] = icmp ne i64 %x, 0
 ; CHECK-NEXT:    [[SOMEBITS:%.*]] = and i64 %y, %x
 ; CHECK-NEXT:    [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i64 [[SOMEBITS]], 0
-; CHECK-NEXT:    [[R:%.*]] = and i1 [[ISNOTNULL]], [[SOMEBITS_ARE_NOT_ZERO]]
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 [[SOMEBITS_ARE_NOT_ZERO]]
 ;
   %isnotnull = icmp ne i64 %x, 0
   %somebits = and i64 %y, %x