[PATCH] D154089: [InstCombine] Add tests for (A > 0) | (A < 0) -> zext (A != 0) fold (NFC)

Hongyu Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 07:39:14 PDT 2023


XChy created this revision.
XChy added reviewers: spatel, nikic, k-arrows, RKSimon.
Herald added a subscriber: StephenFan.
Herald added a project: All.
XChy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Tests for an upcoming  (A > 0) | (A < 0) -> zext (A != 0) fold.
Related issue:
(a > b) | (a < b) is not simplified only for the case b=0 <https://github.com/llvm/llvm-project/issues/62586>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154089

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


Index: llvm/test/Transforms/InstCombine/and-or-icmps.ll
===================================================================
--- llvm/test/Transforms/InstCombine/and-or-icmps.ll
+++ llvm/test/Transforms/InstCombine/and-or-icmps.ll
@@ -2568,3 +2568,31 @@
   %r = or <2 x i1> %rx, %ry
   ret <2 x i1> %r
 }
+
+define i32 @icmp_slt_0_or_icmp_sgt_0_i32(i32 %x) {
+; CHECK-LABEL: @icmp_slt_0_or_icmp_sgt_0_i32(
+; CHECK-NEXT:    [[B:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[C:%.*]] = zext i1 [[B:%.*]] to i32
+; CHECK-NEXT:    ret i32 [[C]]
+;
+  %A = icmp slt i32 %x, 0
+  %B = icmp sgt i32 %x, 0
+  %C = zext i1 %A to i32
+  %D = zext i1 %B to i32
+  %E = or i32 %C, %D
+  ret i32 %E
+}
+
+define i64 @icmp_slt_0_or_icmp_sgt_0_i64(i64 %x) {
+; CHECK-LABEL: @icmp_slt_0_or_icmp_sgt_0_i64(
+; CHECK-NEXT:    [[B:%.*]] = icmp ne i64 [[X:%.*]], 0
+; CHECK-NEXT:    [[C:%.*]] = zext i1 [[B:%.*]] to i64
+; CHECK-NEXT:    ret i64 [[C]]
+;
+  %A = icmp slt i64 %x, 0
+  %B = icmp sgt i64 %x, 0
+  %C = zext i1 %A to i64
+  %D = zext i1 %B to i64
+  %E = or i64 %C, %D
+  ret i64 %E
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154089.535785.patch
Type: text/x-patch
Size: 1086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/e29873e8/attachment.bin>


More information about the llvm-commits mailing list