[PATCH] D154138: [InstCombine] Add tests for folding `(icmp eq/ne (or x, C), x)` -> `(icmp eq/ne (and x, C), C)`; NFC

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 12:50:19 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, spatel, RKSimon.
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/D154138

Files:
  llvm/test/Transforms/InstCombine/icmp-or-x-with-x.ll


Index: llvm/test/Transforms/InstCombine/icmp-or-x-with-x.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/icmp-or-x-with-x.ll
@@ -0,0 +1,84 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+declare void @use.i8(i8)
+define i1 @fold_or_eq(i8 %x) {
+; CHECK-LABEL: define i1 @fold_or_eq
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT:    [[XO:%.*]] = or i8 [[X]], 123
+; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[XO]], [[X]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %xo = or i8 %x, 123
+  %r = icmp eq i8 %xo, %x
+  ret i1 %r
+}
+
+define <2 x i1> @fold_or_ne(<2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i1> @fold_or_ne
+; CHECK-SAME: (<2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT:    [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT:    [[XO:%.*]] = or <2 x i8> [[X]], <i8 123, i8 12>
+; CHECK-NEXT:    [[R:%.*]] = icmp ne <2 x i8> [[X]], [[XO]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %x = mul <2 x i8> %xx, %xx
+  %xo = or <2 x i8> %x, <i8 123, i8 12>
+  %r = icmp ne <2 x i8> %x, %xo
+  ret <2 x i1> %r
+}
+
+define i1 @fold_or_eq_fail_multiuse(i8 %x) {
+; CHECK-LABEL: define i1 @fold_or_eq_fail_multiuse
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT:    [[XO:%.*]] = or i8 [[X]], 123
+; CHECK-NEXT:    call void @use.i8(i8 [[XO]])
+; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[XO]], [[X]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %xo = or i8 %x, 123
+  call void @use.i8(i8 %xo)
+  %r = icmp eq i8 %xo, %x
+  ret i1 %r
+}
+
+define i1 @fold_or_slt_fail(i8 %x) {
+; CHECK-LABEL: define i1 @fold_or_slt_fail
+; CHECK-SAME: (i8 [[X:%.*]]) {
+; CHECK-NEXT:    [[XO:%.*]] = or i8 [[X]], 123
+; CHECK-NEXT:    call void @use.i8(i8 [[XO]])
+; CHECK-NEXT:    ret i1 false
+;
+  %xo = or i8 %x, 123
+  call void @use.i8(i8 %xo)
+  %r = icmp slt i8 %xo, %x
+  ret i1 %r
+}
+
+define <2 x i1> @fold_or_ne_fail_wrong_args(<2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i1> @fold_or_ne_fail_wrong_args
+; CHECK-SAME: (<2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT:    [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT:    [[XO:%.*]] = or <2 x i8> [[X]], <i8 123, i8 12>
+; CHECK-NEXT:    [[R:%.*]] = icmp ne <2 x i8> [[XO]], [[XX]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %x = mul <2 x i8> %xx, %xx
+  %xo = or <2 x i8> %x, <i8 123, i8 12>
+  %r = icmp ne <2 x i8> %xx, %xo
+  ret <2 x i1> %r
+}
+
+define <2 x i1> @fold_or_ne_fail_non_const(<2 x i8> %xx) {
+; CHECK-LABEL: define <2 x i1> @fold_or_ne_fail_non_const
+; CHECK-SAME: (<2 x i8> [[XX:%.*]]) {
+; CHECK-NEXT:    [[X:%.*]] = mul <2 x i8> [[XX]], [[XX]]
+; CHECK-NEXT:    [[XO:%.*]] = or <2 x i8> [[X]], [[XX]]
+; CHECK-NEXT:    [[R:%.*]] = icmp ne <2 x i8> [[X]], [[XO]]
+; CHECK-NEXT:    ret <2 x i1> [[R]]
+;
+  %x = mul <2 x i8> %xx, %xx
+  %xo = or <2 x i8> %x, %xx
+  %r = icmp ne <2 x i8> %x, %xo
+  ret <2 x i1> %r
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154138.535961.patch
Type: text/x-patch
Size: 2939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/2f01b5ef/attachment.bin>


More information about the llvm-commits mailing list