[llvm] 687af8c - [InstCombine] Add tests for and of two ranges differing by mask (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 02:39:25 PDT 2022


Author: Nikita Popov
Date: 2022-04-29T11:39:15+02:00
New Revision: 687af8c9352d240b05150b6b3003abb33abe8ca2

URL: https://github.com/llvm/llvm-project/commit/687af8c9352d240b05150b6b3003abb33abe8ca2
DIFF: https://github.com/llvm/llvm-project/commit/687af8c9352d240b05150b6b3003abb33abe8ca2.diff

LOG: [InstCombine] Add tests for and of two ranges differing by mask (NFC)

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/and-or-icmps.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/and-or-icmps.ll b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
index 16008ff2df4c..28651230a5c8 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmps.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
@@ -1180,3 +1180,70 @@ define i1 @and_ranges_signed_pred(i64 %x) {
   %t5 = and i1 %t2, %t4
   ret i1 %t5
 }
+
+define i1 @and_two_ranges_to_mask_and_range(i8 %c)  {
+; CHECK-LABEL: @and_two_ranges_to_mask_and_range(
+; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[C:%.*]], -123
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ult i8 [[TMP1]], -26
+; CHECK-NEXT:    [[TMP2:%.*]] = add i8 [[C]], -91
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i8 [[TMP2]], -26
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %c.off = add i8 %c, -97
+  %cmp1 = icmp ugt i8 %c.off, 25
+  %c.off2 = add i8 %c, -65
+  %cmp2 = icmp ugt i8 %c.off2, 25
+  %and = and i1 %cmp1, %cmp2
+  ret i1 %and
+}
+
+define i1 @and_two_ranges_to_mask_and_range_not_pow2_
diff (i8 %c)  {
+; CHECK-LABEL: @and_two_ranges_to_mask_and_range_not_pow2_
diff (
+; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[C:%.*]], -123
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ult i8 [[TMP1]], -26
+; CHECK-NEXT:    [[TMP2:%.*]] = add i8 [[C]], -90
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i8 [[TMP2]], -26
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %c.off = add i8 %c, -97
+  %cmp1 = icmp ugt i8 %c.off, 25
+  %c.off2 = add i8 %c, -64
+  %cmp2 = icmp ugt i8 %c.off2, 25
+  %and = and i1 %cmp1, %cmp2
+  ret i1 %and
+}
+
+define i1 @and_two_ranges_to_mask_and_range_
diff erent_sizes(i8 %c)  {
+; CHECK-LABEL: @and_two_ranges_to_mask_and_range_
diff erent_sizes(
+; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[C:%.*]], -123
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ult i8 [[TMP1]], -26
+; CHECK-NEXT:    [[TMP2:%.*]] = add i8 [[C]], -90
+; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i8 [[TMP2]], -25
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %c.off = add i8 %c, -97
+  %cmp1 = icmp ugt i8 %c.off, 25
+  %c.off2 = add i8 %c, -65
+  %cmp2 = icmp ugt i8 %c.off2, 24
+  %and = and i1 %cmp1, %cmp2
+  ret i1 %and
+}
+
+define i1 @and_two_ranges_to_mask_and_range_no_add_on_one_range(i16 %x) {
+; CHECK-LABEL: @and_two_ranges_to_mask_and_range_no_add_on_one_range(
+; CHECK-NEXT:    [[CMP1:%.*]] = icmp ugt i16 [[X:%.*]], 11
+; CHECK-NEXT:    [[TMP1:%.*]] = add i16 [[X]], -28
+; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i16 [[TMP1]], -12
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[CMP1]], [[TMP2]]
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %cmp1 = icmp uge i16 %x, 12
+  %cmp2 = icmp ult i16 %x, 16
+  %cmp3 = icmp uge i16 %x, 28
+  %or = or i1 %cmp2, %cmp3
+  %and = and i1 %cmp1, %or
+  ret i1 %and
+}


        


More information about the llvm-commits mailing list