[llvm] b349098 - [InstCombine] add tests for logic-of-icmps; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 21 11:23:57 PDT 2020
Author: Sanjay Patel
Date: 2020-04-21T14:23:05-04:00
New Revision: b349098d2297f8637525ed162bf37506ed70d7c7
URL: https://github.com/llvm/llvm-project/commit/b349098d2297f8637525ed162bf37506ed70d7c7
DIFF: https://github.com/llvm/llvm-project/commit/b349098d2297f8637525ed162bf37506ed70d7c7.diff
LOG: [InstCombine] add tests for logic-of-icmps; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/and-or-icmps.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/and-or-icmps.ll b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
index 8d5471790739..175103886ff4 100644
--- a/llvm/test/Transforms/InstCombine/and-or-icmps.ll
+++ b/llvm/test/Transforms/InstCombine/and-or-icmps.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
+declare void @use(i1)
+
define i1 @PR1817_1(i32 %X) {
; CHECK-LABEL: @PR1817_1(
; CHECK-NEXT: [[B:%.*]] = icmp ult i32 [[X:%.*]], 10
@@ -368,3 +370,180 @@ define i1 @PR42691_10(i32 %x) {
%c = and i1 %c1, %c2
ret i1 %c
}
+
+define i1 @substitute_constant_and_eq_eq(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_eq(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C1]], [[C2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ %c2 = icmp eq i8 %x, %y
+ %r = and i1 %c1, %c2
+ ret i1 %r
+}
+
+define i1 @substitute_constant_and_eq_eq_commute(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_eq_commute(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp eq i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ %c2 = icmp eq i8 %x, %y
+ %r = and i1 %c2, %c1
+ ret i1 %r
+}
+
+define i1 @substitute_constant_and_eq_ugt_swap(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_ugt_swap(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp ugt i8 [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ %c2 = icmp ugt i8 %y, %x
+ %r = and i1 %c2, %c1
+ ret i1 %r
+}
+
+define <2 x i1> @substitute_constant_and_eq_ne_vec(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_ne_vec(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 42, i8 97>
+; CHECK-NEXT: [[C2:%.*]] = icmp ne <2 x i8> [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[C1]], [[C2]]
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %c1 = icmp eq <2 x i8> %x, <i8 42, i8 97>
+ %c2 = icmp ne <2 x i8> %x, %y
+ %r = and <2 x i1> %c1, %c2
+ ret <2 x i1> %r
+}
+
+define i1 @substitute_constant_and_eq_sgt_use(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_sgt_use(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: call void @use(i1 [[C1]])
+; CHECK-NEXT: [[C2:%.*]] = icmp sgt i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ call void @use(i1 %c1)
+ %c2 = icmp sgt i8 %x, %y
+ %r = and i1 %c2, %c1
+ ret i1 %r
+}
+
+define i1 @substitute_constant_and_eq_sgt_use2(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_eq_sgt_use2(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp sgt i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: call void @use(i1 [[C2]])
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ %c2 = icmp sgt i8 %x, %y
+ call void @use(i1 %c2)
+ %r = and i1 %c2, %c1
+ ret i1 %r
+}
+
+define i1 @substitute_constant_and_ne_ugt_swap(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_and_ne_ugt_swap(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp ugt i8 [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = and i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp ne i8 %x, 42
+ %c2 = icmp ugt i8 %y, %x
+ %r = and i1 %c2, %c1
+ ret i1 %r
+}
+
+define i1 @substitute_constant_or_ne_swap_sle(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_or_ne_swap_sle(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp sle i8 [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C1]], [[C2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp ne i8 %x, 42
+ %c2 = icmp sle i8 %y, %x
+ %r = or i1 %c1, %c2
+ ret i1 %r
+}
+
+define i1 @substitute_constant_or_ne_uge_commute(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_or_ne_uge_commute(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp uge i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp ne i8 %x, 42
+ %c2 = icmp uge i8 %x, %y
+ %r = or i1 %c2, %c1
+ ret i1 %r
+}
+
+define <2 x i1> @substitute_constant_or_ne_slt_swap_vec(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: @substitute_constant_or_ne_slt_swap_vec(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne <2 x i8> [[X:%.*]], <i8 42, i8 undef>
+; CHECK-NEXT: [[C2:%.*]] = icmp slt <2 x i8> [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[C1]], [[C2]]
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %c1 = icmp ne <2 x i8> %x, <i8 42, i8 undef>
+ %c2 = icmp slt <2 x i8> %y, %x
+ %r = or <2 x i1> %c1, %c2
+ ret <2 x i1> %r
+}
+
+define i1 @substitute_constant_or_eq_swap_ne(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_or_eq_swap_ne(
+; CHECK-NEXT: [[C1:%.*]] = icmp eq i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp ne i8 [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C1]], [[C2]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp eq i8 %x, 42
+ %c2 = icmp ne i8 %y, %x
+ %r = or i1 %c1, %c2
+ ret i1 %r
+}
+
+define i1 @substitute_constant_or_ne_sge_use(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_or_ne_sge_use(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[X:%.*]], 42
+; CHECK-NEXT: call void @use(i1 [[C1]])
+; CHECK-NEXT: [[C2:%.*]] = icmp sge i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp ne i8 %x, 42
+ call void @use(i1 %c1)
+ %c2 = icmp sge i8 %x, %y
+ %r = or i1 %c2, %c1
+ ret i1 %r
+}
+
+define i1 @substitute_constant_or_ne_ule_use2(i8 %x, i8 %y) {
+; CHECK-LABEL: @substitute_constant_or_ne_ule_use2(
+; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[X:%.*]], 42
+; CHECK-NEXT: [[C2:%.*]] = icmp ule i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: call void @use(i1 [[C2]])
+; CHECK-NEXT: [[R:%.*]] = or i1 [[C2]], [[C1]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %c1 = icmp ne i8 %x, 42
+ %c2 = icmp ule i8 %x, %y
+ call void @use(i1 %c2)
+ %r = or i1 %c2, %c1
+ ret i1 %r
+}
More information about the llvm-commits
mailing list