blob: 91a298358ff4f75a5d9a2bdafd493bede1fc4f40 [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(
11; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i64 %x, 0
12; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %x, %y
13; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i64 [[SOMEBITS]], 0
14; CHECK-NEXT: [[R:%.*]] = or i1 [[SOMEBITS_ARE_ZERO]], [[ISNULL]]
15; CHECK-NEXT: ret i1 [[R]]
16;
17 %isnull = icmp eq i64 %x, 0
18 %somebits = and i64 %x, %y
19 %somebits_are_zero = icmp eq i64 %somebits, 0
20 %r = or i1 %somebits_are_zero, %isnull
21 ret i1 %r
22}
23
24; or (icmp eq X, 0), (icmp eq (and X, ?), 0) --> icmp eq (and X, ?), 0
25
26define <2 x i1> @or_cmps_eq_zero_with_mask_commute2(<2 x i64> %x, <2 x i64> %y) {
27; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute2(
28; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq <2 x i64> %x, zeroinitializer
29; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i64> %x, %y
30; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i64> [[SOMEBITS]], zeroinitializer
31; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[ISNULL]], [[SOMEBITS_ARE_ZERO]]
32; CHECK-NEXT: ret <2 x i1> [[R]]
33;
34 %isnull = icmp eq <2 x i64> %x, zeroinitializer
35 %somebits = and <2 x i64> %x, %y
36 %somebits_are_zero = icmp eq <2 x i64> %somebits, zeroinitializer
37 %r = or <2 x i1> %isnull, %somebits_are_zero
38 ret <2 x i1> %r
39}
40
41; or (icmp eq (and ?, X), 0), (icmp eq X, 0) --> icmp eq (and ?, X), 0
42
43define i1 @or_cmps_eq_zero_with_mask_commute3(i4 %x, i4 %y) {
44; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute3(
45; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq i4 %x, 0
46; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %y, %x
47; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i4 [[SOMEBITS]], 0
48; CHECK-NEXT: [[R:%.*]] = or i1 [[SOMEBITS_ARE_ZERO]], [[ISNULL]]
49; CHECK-NEXT: ret i1 [[R]]
50;
51 %isnull = icmp eq i4 %x, 0
52 %somebits = and i4 %y, %x
53 %somebits_are_zero = icmp eq i4 %somebits, 0
54 %r = or i1 %somebits_are_zero, %isnull
55 ret i1 %r
56}
57
58; or (icmp eq X, 0), (icmp eq (and ?, X), 0) --> icmp eq (and ?, X), 0
59
60define <2 x i1> @or_cmps_eq_zero_with_mask_commute4(<2 x i4> %x, <2 x i4> %y) {
61; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute4(
62; CHECK-NEXT: [[ISNULL:%.*]] = icmp eq <2 x i4> %x, zeroinitializer
63; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i4> %y, %x
64; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[SOMEBITS]], zeroinitializer
65; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[ISNULL]], [[SOMEBITS_ARE_ZERO]]
66; CHECK-NEXT: ret <2 x i1> [[R]]
67;
68 %isnull = icmp eq <2 x i4> %x, zeroinitializer
69 %somebits = and <2 x i4> %y, %x
70 %somebits_are_zero = icmp eq <2 x i4> %somebits, zeroinitializer
71 %r = or <2 x i1> %isnull, %somebits_are_zero
72 ret <2 x i1> %r
73}
74
75; and (icmp ne (and X, ?), 0), (icmp ne X, 0) --> icmp ne (and X, ?), 0
76
77define <3 x i1> @and_cmps_eq_zero_with_mask_commute1(<3 x i4> %x, <3 x i4> %y) {
78; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute1(
79; CHECK-NEXT: [[ISNOTNULL:%.*]] = icmp ne <3 x i4> %x, zeroinitializer
80; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i4> %x, %y
81; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i4> [[SOMEBITS]], zeroinitializer
82; CHECK-NEXT: [[R:%.*]] = and <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]], [[ISNOTNULL]]
83; CHECK-NEXT: ret <3 x i1> [[R]]
84;
85 %isnotnull = icmp ne <3 x i4> %x, zeroinitializer
86 %somebits = and <3 x i4> %x, %y
87 %somebits_are_not_zero = icmp ne <3 x i4> %somebits, zeroinitializer
88 %r = and <3 x i1> %somebits_are_not_zero, %isnotnull
89 ret <3 x i1> %r
90}
91
92; and (icmp ne X, 0), (icmp ne (and X, ?), 0) --> icmp ne (and X, ?), 0
93
94define i1 @and_cmps_eq_zero_with_mask_commute2(i4 %x, i4 %y) {
95; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute2(
96; CHECK-NEXT: [[ISNOTNULL:%.*]] = icmp ne i4 %x, 0
97; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %x, %y
98; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i4 [[SOMEBITS]], 0
99; CHECK-NEXT: [[R:%.*]] = and i1 [[ISNOTNULL]], [[SOMEBITS_ARE_NOT_ZERO]]
100; CHECK-NEXT: ret i1 [[R]]
101;
102 %isnotnull = icmp ne i4 %x, 0
103 %somebits = and i4 %x, %y
104 %somebits_are_not_zero = icmp ne i4 %somebits, 0
105 %r = and i1 %isnotnull, %somebits_are_not_zero
106 ret i1 %r
107}
108
109; and (icmp ne (and ?, X), 0), (icmp ne X, 0) --> icmp ne (and ?, X), 0
110
111define <3 x i1> @and_cmps_eq_zero_with_mask_commute3(<3 x i64> %x, <3 x i64> %y) {
112; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute3(
113; CHECK-NEXT: [[ISNOTNULL:%.*]] = icmp ne <3 x i64> %x, zeroinitializer
114; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i64> %y, %x
115; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i64> [[SOMEBITS]], zeroinitializer
116; CHECK-NEXT: [[R:%.*]] = and <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]], [[ISNOTNULL]]
117; CHECK-NEXT: ret <3 x i1> [[R]]
118;
119 %isnotnull = icmp ne <3 x i64> %x, zeroinitializer
120 %somebits = and <3 x i64> %y, %x
121 %somebits_are_not_zero = icmp ne <3 x i64> %somebits, zeroinitializer
122 %r = and <3 x i1> %somebits_are_not_zero, %isnotnull
123 ret <3 x i1> %r
124}
125
126; and (icmp ne X, 0), (icmp ne (and ?, X), 0) --> icmp ne (and ?, X), 0
127
128define i1 @and_cmps_eq_zero_with_mask_commute4(i64 %x, i64 %y) {
129; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute4(
130; CHECK-NEXT: [[ISNOTNULL:%.*]] = icmp ne i64 %x, 0
131; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %y, %x
132; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i64 [[SOMEBITS]], 0
133; CHECK-NEXT: [[R:%.*]] = and i1 [[ISNOTNULL]], [[SOMEBITS_ARE_NOT_ZERO]]
134; CHECK-NEXT: ret i1 [[R]]
135;
136 %isnotnull = icmp ne i64 %x, 0
137 %somebits = and i64 %y, %x
138 %somebits_are_not_zero = icmp ne i64 %somebits, 0
139 %r = and i1 %isnotnull, %somebits_are_not_zero
140 ret i1 %r
141}
142