[PATCH] D157311: [InstCombine] Add tests for transforming `(or/and (icmp eq/ne X,0),(icmp eq/ne X,Pow2OrZero))`; NFC
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 7 10:49:48 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, Allen.
Herald added a subscriber: StephenFan.
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/D157311
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
@@ -3046,3 +3046,92 @@
%D = or i32 %C, %B
ret i32 %D
}
+
+define i1 @icmp_eq_or_z_or_pow2orz(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_eq_or_z_or_pow2orz(
+; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y:%.*]]
+; CHECK-NEXT: [[POW2ORZ:%.*]] = and i8 [[NY]], [[Y]]
+; CHECK-NEXT: [[C0:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT: [[CP2:%.*]] = icmp eq i8 [[POW2ORZ]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C0]], [[CP2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %ny = sub i8 0, %y
+ %pow2orz = and i8 %ny, %y
+
+ %c0 = icmp eq i8 %x, 0
+ %cp2 = icmp eq i8 %x, %pow2orz
+ %r = or i1 %c0, %cp2
+ ret i1 %r
+}
+
+define <2 x i1> @icmp_ne_and_z_and_pow2orz(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @icmp_ne_and_z_and_pow2orz(
+; CHECK-NEXT: [[NY:%.*]] = sub <2 x i8> zeroinitializer, [[Y:%.*]]
+; CHECK-NEXT: [[POW2ORZ:%.*]] = and <2 x i8> [[NY]], [[Y]]
+; CHECK-NEXT: [[C0:%.*]] = icmp ne <2 x i8> [[X:%.*]], zeroinitializer
+; CHECK-NEXT: [[CP2:%.*]] = icmp ne <2 x i8> [[POW2ORZ]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[C0]], [[CP2]]
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %ny = sub <2 x i8> zeroinitializer, %y
+ %pow2orz = and <2 x i8> %ny, %y
+
+ %c0 = icmp ne <2 x i8> %x, zeroinitializer
+ %cp2 = icmp ne <2 x i8> %x, %pow2orz
+ %r = and <2 x i1> %c0, %cp2
+ ret <2 x i1> %r
+}
+
+define i1 @icmp_eq_or_z_or_pow2orz_fail_not_pow2(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_eq_or_z_or_pow2orz_fail_not_pow2(
+; CHECK-NEXT: [[NY:%.*]] = sub i8 1, [[Y:%.*]]
+; CHECK-NEXT: [[POW2ORZ:%.*]] = and i8 [[NY]], [[Y]]
+; CHECK-NEXT: [[C0:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT: [[CP2:%.*]] = icmp eq i8 [[POW2ORZ]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C0]], [[CP2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %ny = sub i8 1, %y
+ %pow2orz = and i8 %ny, %y
+
+ %c0 = icmp eq i8 %x, 0
+ %cp2 = icmp eq i8 %x, %pow2orz
+ %r = or i1 %c0, %cp2
+ ret i1 %r
+}
+
+define <2 x i1> @icmp_ne_and_z_and_pow2orz_fail_bad_pred(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @icmp_ne_and_z_and_pow2orz_fail_bad_pred(
+; CHECK-NEXT: [[NY:%.*]] = sub <2 x i8> zeroinitializer, [[Y:%.*]]
+; CHECK-NEXT: [[POW2ORZ:%.*]] = and <2 x i8> [[NY]], [[Y]]
+; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i8> [[POW2ORZ]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[TMP1]], zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %ny = sub <2 x i8> zeroinitializer, %y
+ %pow2orz = and <2 x i8> %ny, %y
+
+ %c0 = icmp eq <2 x i8> %x, zeroinitializer
+ %cp2 = icmp eq <2 x i8> %x, %pow2orz
+ %r = and <2 x i1> %c0, %cp2
+ ret <2 x i1> %r
+}
+
+define i1 @icmp_eq_or_z_or_pow2orz_fail_bad_pred2(i8 %x, i8 %y) {
+; CHECK-LABEL: @icmp_eq_or_z_or_pow2orz_fail_bad_pred2(
+; CHECK-NEXT: [[NY:%.*]] = sub i8 0, [[Y:%.*]]
+; CHECK-NEXT: [[POW2ORZ:%.*]] = and i8 [[NY]], [[Y]]
+; CHECK-NEXT: [[C0:%.*]] = icmp slt i8 [[X:%.*]], 1
+; CHECK-NEXT: [[CP2:%.*]] = icmp sge i8 [[POW2ORZ]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C0]], [[CP2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %ny = sub i8 0, %y
+ %pow2orz = and i8 %ny, %y
+
+ %c0 = icmp sle i8 %x, 0
+ %cp2 = icmp sle i8 %x, %pow2orz
+ %r = or i1 %c0, %cp2
+ ret i1 %r
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157311.547858.patch
Type: text/x-patch
Size: 3425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230807/0faca701/attachment.bin>
More information about the llvm-commits
mailing list