[PATCH] D142299: [InstSimplify] Add tests for `icmp eq/ne/ugt/ult X, 0` where `X` is known to be zero; NFC

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 21 21:56:14 PST 2023


goldstein.w.n created this revision.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142299

Files:
  llvm/test/Transforms/InstSimplify/icmp-constant.ll


Index: llvm/test/Transforms/InstSimplify/icmp-constant.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/icmp-constant.ll
+++ llvm/test/Transforms/InstSimplify/icmp-constant.ll
@@ -1140,3 +1140,64 @@
   %c = icmp ult <2 x i8> %x, <i8 undef, i8 poison>
   ret <2 x i1> %c
 }
+
+
+define i1 @cmp_ne_0_is_false(i32 %x) {
+; CHECK-LABEL: @cmp_ne_0_is_false(
+; CHECK-NEXT:    [[Y:%.*]] = add i32 [[X:%.*]], 1
+; CHECK-NEXT:    [[Z:%.*]] = and i32 [[X]], [[Y]]
+; CHECK-NEXT:    [[B:%.*]] = and i32 [[Z]], 1
+; CHECK-NEXT:    [[E:%.*]] = icmp ne i32 [[B]], 0
+; CHECK-NEXT:    ret i1 [[E]]
+;
+  %y = add i32 %x, 1
+  %z = and i32 %x, %y
+  %b = and i32 %z, 1
+  %e = icmp ne i32 %b, 0
+  ret i1 %e
+}
+
+define i1 @cmp_eq_0_is_true(i32 %x) {
+; CHECK-LABEL: @cmp_eq_0_is_true(
+; CHECK-NEXT:    [[Y:%.*]] = add i32 [[X:%.*]], 1
+; CHECK-NEXT:    [[Z:%.*]] = and i32 [[X]], [[Y]]
+; CHECK-NEXT:    [[B:%.*]] = and i32 [[Z]], 1
+; CHECK-NEXT:    [[E:%.*]] = icmp eq i32 [[B]], 0
+; CHECK-NEXT:    ret i1 [[E]]
+;
+  %y = add i32 %x, 1
+  %z = and i32 %x, %y
+  %b = and i32 %z, 1
+  %e = icmp eq i32 %b, 0
+  ret i1 %e
+}
+
+define <2 x i1> @cmp_ule_0_is_true(<2 x i32> %x) {
+; CHECK-LABEL: @cmp_ule_0_is_true(
+; CHECK-NEXT:    [[Y:%.*]] = add <2 x i32> [[X:%.*]], <i32 1, i32 1>
+; CHECK-NEXT:    [[Z:%.*]] = and <2 x i32> [[X]], [[Y]]
+; CHECK-NEXT:    [[B:%.*]] = and <2 x i32> [[Z]], <i32 1, i32 1>
+; CHECK-NEXT:    [[E:%.*]] = icmp ule <2 x i32> [[B]], zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[E]]
+;
+  %y = add <2 x i32> %x, <i32 1, i32 1>
+  %z = and <2 x i32> %x, %y
+  %b = and <2 x i32> %z, <i32 1, i32 1>
+  %e = icmp ule <2 x i32> %b, <i32 0, i32 0>
+  ret <2 x i1> %e
+}
+
+define <2 x i1> @cmp_ugt_0_is_false(<2 x i32> %x) {
+; CHECK-LABEL: @cmp_ugt_0_is_false(
+; CHECK-NEXT:    [[Y:%.*]] = add <2 x i32> [[X:%.*]], <i32 1, i32 1>
+; CHECK-NEXT:    [[Z:%.*]] = and <2 x i32> [[X]], [[Y]]
+; CHECK-NEXT:    [[B:%.*]] = and <2 x i32> [[Z]], <i32 1, i32 1>
+; CHECK-NEXT:    [[E:%.*]] = icmp ugt <2 x i32> [[B]], zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[E]]
+;
+  %y = add <2 x i32> %x, <i32 1, i32 1>
+  %z = and <2 x i32> %x, %y
+  %b = and <2 x i32> %z, <i32 1, i32 1>
+  %e = icmp ugt <2 x i32> %b, <i32 0, i32 0>
+  ret <2 x i1> %e
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142299.491128.patch
Type: text/x-patch
Size: 2325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230122/5d804422/attachment.bin>


More information about the llvm-commits mailing list