[InstCombine] Add tests for folding `(icmp eq/ne (zext i1) (sext i1))`; NFC
authorNoah Goldstein <goldstein.w.n@gmail.com>
Thu, 6 Jul 2023 07:23:32 +0000 (02:23 -0500)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 12 Jul 2023 22:17:52 +0000 (17:17 -0500)
Differential Revision: https://reviews.llvm.org/D154573

llvm/test/Transforms/InstCombine/icmp-ext-ext.ll

index 42472bb..c350358 100644 (file)
@@ -380,3 +380,43 @@ define i1 @sext_zext_uge_known_nonneg_op0_wide(i16 %x, i8 %y) {
   %c = icmp uge i32 %a, %b
   ret i1 %c
 }
+
+
+define i1 @zext_eq_sext(i1 %a, i1 %b) {
+; CHECK-LABEL: @zext_eq_sext(
+; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[A:%.*]] to i32
+; CHECK-NEXT:    [[CONV3_NEG:%.*]] = sext i1 [[B:%.*]] to i32
+; CHECK-NEXT:    [[TOBOOL4:%.*]] = icmp eq i32 [[CONV]], [[CONV3_NEG]]
+; CHECK-NEXT:    ret i1 [[TOBOOL4]]
+;
+  %conv = zext i1 %a to i32
+  %conv3.neg = sext i1 %b to i32
+  %tobool4 = icmp eq i32 %conv, %conv3.neg
+  ret i1 %tobool4
+}
+
+define i1 @zext_eq_sext_fail_not_i1(i1 %a, i8 %b) {
+; CHECK-LABEL: @zext_eq_sext_fail_not_i1(
+; CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[A:%.*]] to i32
+; CHECK-NEXT:    [[CONV3_NEG:%.*]] = sext i8 [[B:%.*]] to i32
+; CHECK-NEXT:    [[TOBOOL4:%.*]] = icmp eq i32 [[CONV]], [[CONV3_NEG]]
+; CHECK-NEXT:    ret i1 [[TOBOOL4]]
+;
+  %conv = zext i1 %a to i32
+  %conv3.neg = sext i8 %b to i32
+  %tobool4 = icmp eq i32 %conv, %conv3.neg
+  ret i1 %tobool4
+}
+
+define <2 x i1> @zext_ne_sext(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @zext_ne_sext(
+; CHECK-NEXT:    [[CONV:%.*]] = zext <2 x i1> [[A:%.*]] to <2 x i8>
+; CHECK-NEXT:    [[CONV3_NEG:%.*]] = sext <2 x i1> [[B:%.*]] to <2 x i8>
+; CHECK-NEXT:    [[TOBOOL4:%.*]] = icmp ne <2 x i8> [[CONV3_NEG]], [[CONV]]
+; CHECK-NEXT:    ret <2 x i1> [[TOBOOL4]]
+;
+  %conv = zext <2 x i1> %a to <2 x i8>
+  %conv3.neg = sext <2 x i1> %b to <2 x i8>
+  %tobool4 = icmp ne <2 x i8> %conv3.neg, %conv
+  ret <2 x i1> %tobool4
+}