blob: 37e6a90d2af3d2e088c79edcb8e682d6c6a037a4 [file] [log] [blame]
Sanjay Patelb6f107d2017-11-16 15:25:59 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3; Cycle through commuted variants where one operand of fcmp ord/uno is
4; known not-a-NAN and the other is repeated in the logically-connected fcmp.
5
6define i1 @ord1(float %x, float %y) {
7; CHECK-LABEL: @ord1(
8; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord float 0.000000e+00, %x
9; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord float %x, %y
10; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP1]], [[CMP2]]
11; CHECK-NEXT: ret i1 [[R]]
12;
13 %cmp1 = fcmp ord float 0.0, %x
14 %cmp2 = fcmp ord float %x, %y
15 %r = and i1 %cmp1, %cmp2
16 ret i1 %r
17}
18
19define i1 @ord2(double %x, double %y) {
20; CHECK-LABEL: @ord2(
21; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord double 4.200000e+01, %x
22; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord double %y, %x
23; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP1]], [[CMP2]]
24; CHECK-NEXT: ret i1 [[R]]
25;
26 %cmp1 = fcmp ord double 42.0, %x
27 %cmp2 = fcmp ord double %y, %x
28 %r = and i1 %cmp1, %cmp2
29 ret i1 %r
30}
31
32define <2 x i1> @ord3(<2 x float> %x, <2 x float> %y) {
33; CHECK-LABEL: @ord3(
34; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord <2 x float> %x, zeroinitializer
35; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <2 x float> %x, %y
36; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]
37; CHECK-NEXT: ret <2 x i1> [[R]]
38;
39 %cmp1 = fcmp ord <2 x float> %x, zeroinitializer
40 %cmp2 = fcmp ord <2 x float> %x, %y
41 %r = and <2 x i1> %cmp1, %cmp2
42 ret <2 x i1> %r
43}
44
45define <2 x i1> @ord4(<2 x double> %x, <2 x double> %y) {
46; CHECK-LABEL: @ord4(
47; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord <2 x double> %x, <double 4.200000e+01, double 4.200000e+01>
48; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <2 x double> %y, %x
49; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]
50; CHECK-NEXT: ret <2 x i1> [[R]]
51;
52 %cmp1 = fcmp ord <2 x double> %x, <double 42.0, double 42.0>
53 %cmp2 = fcmp ord <2 x double> %y, %x
54 %r = and <2 x i1> %cmp1, %cmp2
55 ret <2 x i1> %r
56}
57
58define i1 @ord5(float %x, float %y) {
59; CHECK-LABEL: @ord5(
60; CHECK-NEXT: [[NNAN:%.*]] = fdiv nnan float %x, %y
61; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord float %x, %y
62; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord float [[NNAN]], %x
63; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP1]], [[CMP2]]
64; CHECK-NEXT: ret i1 [[R]]
65;
66 %nnan = fdiv nnan float %x, %y
67 %cmp1 = fcmp ord float %x, %y
68 %cmp2 = fcmp ord float %nnan, %x
69 %r = and i1 %cmp1, %cmp2
70 ret i1 %r
71}
72
73define i1 @ord6(double %x, double %y) {
74; CHECK-LABEL: @ord6(
75; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord double %y, %x
76; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord double 4.200000e+01, %x
77; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP1]], [[CMP2]]
78; CHECK-NEXT: ret i1 [[R]]
79;
80 %cmp1 = fcmp ord double %y, %x
81 %cmp2 = fcmp ord double 42.0, %x
82 %r = and i1 %cmp1, %cmp2
83 ret i1 %r
84}
85
86define <2 x i1> @ord7(<2 x float> %x, <2 x float> %y) {
87; CHECK-LABEL: @ord7(
88; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord <2 x float> %x, %y
89; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <2 x float> %x, zeroinitializer
90; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]
91; CHECK-NEXT: ret <2 x i1> [[R]]
92;
93 %cmp1 = fcmp ord <2 x float> %x, %y
94 %cmp2 = fcmp ord <2 x float> %x, zeroinitializer
95 %r = and <2 x i1> %cmp1, %cmp2
96 ret <2 x i1> %r
97}
98
99define <2 x i1> @ord8(<2 x double> %x, <2 x double> %y) {
100; CHECK-LABEL: @ord8(
101; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord <2 x double> %y, %x
102; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <2 x double> %x, <double 0.000000e+00, double 4.200000e+01>
103; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[CMP1]], [[CMP2]]
104; CHECK-NEXT: ret <2 x i1> [[R]]
105;
106 %cmp1 = fcmp ord <2 x double> %y, %x
107 %cmp2 = fcmp ord <2 x double> %x, <double 0.0, double 42.0>
108 %r = and <2 x i1> %cmp1, %cmp2
109 ret <2 x i1> %r
110}
111
112define i1 @uno1(float %x, float %y) {
113; CHECK-LABEL: @uno1(
114; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno float 0.000000e+00, %x
115; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno float %x, %y
116; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP1]], [[CMP2]]
117; CHECK-NEXT: ret i1 [[R]]
118;
119 %cmp1 = fcmp uno float 0.0, %x
120 %cmp2 = fcmp uno float %x, %y
121 %r = or i1 %cmp1, %cmp2
122 ret i1 %r
123}
124
125define i1 @uno2(double %x, double %y) {
126; CHECK-LABEL: @uno2(
127; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno double 4.200000e+01, %x
128; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno double %y, %x
129; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP1]], [[CMP2]]
130; CHECK-NEXT: ret i1 [[R]]
131;
132 %cmp1 = fcmp uno double 42.0, %x
133 %cmp2 = fcmp uno double %y, %x
134 %r = or i1 %cmp1, %cmp2
135 ret i1 %r
136}
137
138define <2 x i1> @uno3(<2 x float> %x, <2 x float> %y) {
139; CHECK-LABEL: @uno3(
140; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno <2 x float> %x, zeroinitializer
141; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <2 x float> %x, %y
142; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[CMP1]], [[CMP2]]
143; CHECK-NEXT: ret <2 x i1> [[R]]
144;
145 %cmp1 = fcmp uno <2 x float> %x, zeroinitializer
146 %cmp2 = fcmp uno <2 x float> %x, %y
147 %r = or <2 x i1> %cmp1, %cmp2
148 ret <2 x i1> %r
149}
150
151define <2 x i1> @uno4(<2 x double> %x, <2 x double> %y) {
152; CHECK-LABEL: @uno4(
153; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno <2 x double> %x, <double 4.200000e+01, double 4.200000e+01>
154; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <2 x double> %y, %x
155; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[CMP1]], [[CMP2]]
156; CHECK-NEXT: ret <2 x i1> [[R]]
157;
158 %cmp1 = fcmp uno <2 x double> %x, <double 42.0, double 42.0>
159 %cmp2 = fcmp uno <2 x double> %y, %x
160 %r = or <2 x i1> %cmp1, %cmp2
161 ret <2 x i1> %r
162}
163
164define i1 @uno5(float %x, float %y) {
165; CHECK-LABEL: @uno5(
166; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno float %x, %y
167; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno float 0.000000e+00, %x
168; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP1]], [[CMP2]]
169; CHECK-NEXT: ret i1 [[R]]
170;
171 %cmp1 = fcmp uno float %x, %y
172 %cmp2 = fcmp uno float 0.0, %x
173 %r = or i1 %cmp1, %cmp2
174 ret i1 %r
175}
176
177define i1 @uno6(double %x, double %y) {
178; CHECK-LABEL: @uno6(
179; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno double %y, %x
180; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno double 4.200000e+01, %x
181; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP1]], [[CMP2]]
182; CHECK-NEXT: ret i1 [[R]]
183;
184 %cmp1 = fcmp uno double %y, %x
185 %cmp2 = fcmp uno double 42.0, %x
186 %r = or i1 %cmp1, %cmp2
187 ret i1 %r
188}
189
190define <2 x i1> @uno7(<2 x float> %x, <2 x float> %y) {
191; CHECK-LABEL: @uno7(
192; CHECK-NEXT: [[NNAN:%.*]] = fdiv nnan <2 x float> %x, %y
193; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno <2 x float> %x, %y
194; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <2 x float> %x, [[NNAN]]
195; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[CMP1]], [[CMP2]]
196; CHECK-NEXT: ret <2 x i1> [[R]]
197;
198 %nnan = fdiv nnan <2 x float> %x, %y
199 %cmp1 = fcmp uno <2 x float> %x, %y
200 %cmp2 = fcmp uno <2 x float> %x, %nnan
201 %r = or <2 x i1> %cmp1, %cmp2
202 ret <2 x i1> %r
203}
204
205define <2 x i1> @uno8(<2 x double> %x, <2 x double> %y) {
206; CHECK-LABEL: @uno8(
207; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno <2 x double> %y, %x
208; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <2 x double> %x, <double 0x7FF0000000000000, double 4.200000e+01>
209; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[CMP1]], [[CMP2]]
210; CHECK-NEXT: ret <2 x i1> [[R]]
211;
212 %cmp1 = fcmp uno <2 x double> %y, %x
213 %cmp2 = fcmp uno <2 x double> %x, <double 0x7ff0000000000000, double 42.0>
214 %r = or <2 x i1> %cmp1, %cmp2
215 ret <2 x i1> %r
216}
217