blob: af384fa62a0ea6da6cd5b5f56ed2514fb933be23 [file] [log] [blame]
Sanjay Patelac0edcb2018-01-11 22:48:07 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3; In the next 8 tests (4 commutes * 2 (and/or)), eliminate the simple (not) null
4; check because that compare is implied by the masked compare of the same operand.
5; Vary types between scalar and vector and weird for extra coverage.
6
7; or (icmp eq (and X, ?), 0), (icmp eq X, 0) --> icmp eq (and X, ?), 0
8
9define i1 @or_cmps_eq_zero_with_mask_commute1(i64 %x, i64 %y) {
10; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute1(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000011; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %x, %y
12; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i64 [[SOMEBITS]], 0
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000013; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000014;
15 %isnull = icmp eq i64 %x, 0
16 %somebits = and i64 %x, %y
17 %somebits_are_zero = icmp eq i64 %somebits, 0
18 %r = or i1 %somebits_are_zero, %isnull
19 ret i1 %r
20}
21
22; or (icmp eq X, 0), (icmp eq (and X, ?), 0) --> icmp eq (and X, ?), 0
23
24define <2 x i1> @or_cmps_eq_zero_with_mask_commute2(<2 x i64> %x, <2 x i64> %y) {
25; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute2(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000026; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i64> %x, %y
27; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i64> [[SOMEBITS]], zeroinitializer
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000028; CHECK-NEXT: ret <2 x i1> [[SOMEBITS_ARE_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000029;
30 %isnull = icmp eq <2 x i64> %x, zeroinitializer
31 %somebits = and <2 x i64> %x, %y
32 %somebits_are_zero = icmp eq <2 x i64> %somebits, zeroinitializer
33 %r = or <2 x i1> %isnull, %somebits_are_zero
34 ret <2 x i1> %r
35}
36
37; or (icmp eq (and ?, X), 0), (icmp eq X, 0) --> icmp eq (and ?, X), 0
38
39define i1 @or_cmps_eq_zero_with_mask_commute3(i4 %x, i4 %y) {
40; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute3(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000041; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %y, %x
42; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i4 [[SOMEBITS]], 0
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000043; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000044;
45 %isnull = icmp eq i4 %x, 0
46 %somebits = and i4 %y, %x
47 %somebits_are_zero = icmp eq i4 %somebits, 0
48 %r = or i1 %somebits_are_zero, %isnull
49 ret i1 %r
50}
51
52; or (icmp eq X, 0), (icmp eq (and ?, X), 0) --> icmp eq (and ?, X), 0
53
54define <2 x i1> @or_cmps_eq_zero_with_mask_commute4(<2 x i4> %x, <2 x i4> %y) {
55; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute4(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000056; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i4> %y, %x
57; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[SOMEBITS]], zeroinitializer
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000058; CHECK-NEXT: ret <2 x i1> [[SOMEBITS_ARE_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000059;
60 %isnull = icmp eq <2 x i4> %x, zeroinitializer
61 %somebits = and <2 x i4> %y, %x
62 %somebits_are_zero = icmp eq <2 x i4> %somebits, zeroinitializer
63 %r = or <2 x i1> %isnull, %somebits_are_zero
64 ret <2 x i1> %r
65}
66
67; and (icmp ne (and X, ?), 0), (icmp ne X, 0) --> icmp ne (and X, ?), 0
68
69define <3 x i1> @and_cmps_eq_zero_with_mask_commute1(<3 x i4> %x, <3 x i4> %y) {
70; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute1(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000071; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i4> %x, %y
72; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i4> [[SOMEBITS]], zeroinitializer
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000073; CHECK-NEXT: ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000074;
75 %isnotnull = icmp ne <3 x i4> %x, zeroinitializer
76 %somebits = and <3 x i4> %x, %y
77 %somebits_are_not_zero = icmp ne <3 x i4> %somebits, zeroinitializer
78 %r = and <3 x i1> %somebits_are_not_zero, %isnotnull
79 ret <3 x i1> %r
80}
81
82; and (icmp ne X, 0), (icmp ne (and X, ?), 0) --> icmp ne (and X, ?), 0
83
84define i1 @and_cmps_eq_zero_with_mask_commute2(i4 %x, i4 %y) {
85; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute2(
Sanjay Patelac0edcb2018-01-11 22:48:07 +000086; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %x, %y
87; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i4 [[SOMEBITS]], 0
Sanjay Patel6ef6aa92018-01-11 23:27:37 +000088; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_NOT_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +000089;
90 %isnotnull = icmp ne i4 %x, 0
91 %somebits = and i4 %x, %y
92 %somebits_are_not_zero = icmp ne i4 %somebits, 0
93 %r = and i1 %isnotnull, %somebits_are_not_zero
94 ret i1 %r
95}
96
97; and (icmp ne (and ?, X), 0), (icmp ne X, 0) --> icmp ne (and ?, X), 0
98
99define <3 x i1> @and_cmps_eq_zero_with_mask_commute3(<3 x i64> %x, <3 x i64> %y) {
100; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute3(
Sanjay Patelac0edcb2018-01-11 22:48:07 +0000101; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i64> %y, %x
102; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i64> [[SOMEBITS]], zeroinitializer
Sanjay Patel6ef6aa92018-01-11 23:27:37 +0000103; CHECK-NEXT: ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +0000104;
105 %isnotnull = icmp ne <3 x i64> %x, zeroinitializer
106 %somebits = and <3 x i64> %y, %x
107 %somebits_are_not_zero = icmp ne <3 x i64> %somebits, zeroinitializer
108 %r = and <3 x i1> %somebits_are_not_zero, %isnotnull
109 ret <3 x i1> %r
110}
111
112; and (icmp ne X, 0), (icmp ne (and ?, X), 0) --> icmp ne (and ?, X), 0
113
114define i1 @and_cmps_eq_zero_with_mask_commute4(i64 %x, i64 %y) {
115; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute4(
Sanjay Patelac0edcb2018-01-11 22:48:07 +0000116; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %y, %x
117; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i64 [[SOMEBITS]], 0
Sanjay Patel6ef6aa92018-01-11 23:27:37 +0000118; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_NOT_ZERO]]
Sanjay Patelac0edcb2018-01-11 22:48:07 +0000119;
120 %isnotnull = icmp ne i64 %x, 0
121 %somebits = and i64 %y, %x
122 %somebits_are_not_zero = icmp ne i64 %somebits, 0
123 %r = and i1 %isnotnull, %somebits_are_not_zero
124 ret i1 %r
125}
126