[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 10:29:11 PDT 2023


XChy updated this revision to Diff 535879.
XChy added a comment.

Return to the situation before optimization


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154089/new/

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,35 @@
   %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 sgt i32 [[X:%.*]], 0
+; CHECK-NEXT:    [[X_LOBIT:%.*]] = lshr i32 [[X]], 31
+; CHECK-NEXT:    [[D:%.*]] = zext i1 [[B]] to i32
+; CHECK-NEXT:    [[E:%.*]] = or i32 [[X_LOBIT]], [[D]]
+; CHECK-NEXT:    ret i32 [[E]]
+;
+  %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 sgt i64 [[X:%.*]], 0
+; CHECK-NEXT:    [[X_LOBIT:%.*]] = lshr i64 [[X]], 63
+; CHECK-NEXT:    [[D:%.*]] = zext i1 [[B]] to i64
+; CHECK-NEXT:    [[E:%.*]] = or i64 [[X_LOBIT]], [[D]]
+; CHECK-NEXT:    ret i64 [[E]]
+;
+  %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.535879.patch
Type: text/x-patch
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/a1dfe5dc/attachment.bin>


More information about the llvm-commits mailing list