[llvm] 1657331 - [InstCombine] Test for fold of and of icmps with operands in the range(0,2) (NFC)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 5 03:12:15 PDT 2025


Author: Andreas Jonson
Date: 2025-04-05T12:07:38+02:00
New Revision: 16573315d986568641e536c37c84fcc5dd161bf6

URL: https://github.com/llvm/llvm-project/commit/16573315d986568641e536c37c84fcc5dd161bf6
DIFF: https://github.com/llvm/llvm-project/commit/16573315d986568641e536c37c84fcc5dd161bf6.diff

LOG: [InstCombine] Test for fold of and of icmps with operands in the range(0,2)  (NFC)

proof https://alive2.llvm.org/ce/z/xeazCu

this is a regression found in https://github.com/llvm/llvm-project/pull/128861
This fold is done when icmp eq/ne x, 1/0 is folded to trunc nuw x iff x is in the range(0,2)

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 9651858a0caef..8824ae48417b0 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmps.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
@@ -3409,3 +3409,31 @@ define i1 @and_ugt_to_mask_off_by_one(i8 %x) {
   %and2 = and i1 %cmp, %cmp2
   ret i1 %and2
 }
+
+; TODO: shall fold to trunc nuw i8 (and %x, %y) to i1.
+define i1 @and_icmp_ne_with_binary_range_operands(i8 range(i8 0, 2) %x, i8 range(i8 0, 2) %y) {
+; CHECK-LABEL: @and_icmp_ne_with_binary_range_operands(
+; CHECK-NEXT:    [[ICMP1:%.*]] = icmp ne i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[ICMP2:%.*]] = icmp ne i8 [[Y:%.*]], 0
+; CHECK-NEXT:    [[RET:%.*]] = and i1 [[ICMP1]], [[ICMP2]]
+; CHECK-NEXT:    ret i1 [[RET]]
+;
+  %icmp1 = icmp ne i8 %x, 0
+  %icmp2 = icmp ne i8 %y, 0
+  %ret = and i1 %icmp1, %icmp2
+  ret i1 %ret
+}
+
+; TODO: shall fold to trunc nuw i8 (and %x, %y) to i1.
+define i1 @and_icmp_eq_with_binary_range_operands(i8 range(i8 0, 2) %x, i8 range(i8 0, 2) %y) {
+; CHECK-LABEL: @and_icmp_eq_with_binary_range_operands(
+; CHECK-NEXT:    [[ICMP1:%.*]] = icmp ne i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[ICMP2:%.*]] = icmp ne i8 [[Y:%.*]], 0
+; CHECK-NEXT:    [[RET:%.*]] = and i1 [[ICMP1]], [[ICMP2]]
+; CHECK-NEXT:    ret i1 [[RET]]
+;
+  %icmp1 = icmp eq i8 %x, 1
+  %icmp2 = icmp eq i8 %y, 1
+  %ret = and i1 %icmp1, %icmp2
+  ret i1 %ret
+}


        


More information about the llvm-commits mailing list