1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define float @select_fcmp_fsub_oeq(float %x) {
5 ; CHECK-LABEL: @select_fcmp_fsub_oeq(
6 ; CHECK-NEXT: ret float 0.000000e+00
8 %fcmp = fcmp oeq float %x, 2.0
9 %fadd = fsub float %x, 2.0
10 %sel = select i1 %fcmp, float %fadd, float 0.0
14 define float @select_fcmp_fsub_oeq_zero(float %x) {
15 ; CHECK-LABEL: @select_fcmp_fsub_oeq_zero(
16 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 0.000000e+00
17 ; CHECK-NEXT: [[FADD:%.*]] = fsub float [[X]], 2.000000e+00
18 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[FADD]], float 2.000000e+00
19 ; CHECK-NEXT: ret float [[SEL]]
21 %fcmp = fcmp oeq float %x, 0.0
22 %fadd = fsub float %x, 2.0
23 %sel = select i1 %fcmp, float %fadd, float 2.0
27 define float @select_fcmp_fsub_ueq(float %x) {
28 ; CHECK-LABEL: @select_fcmp_fsub_ueq(
29 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp ueq float [[X:%.*]], 2.000000e+00
30 ; CHECK-NEXT: [[FADD:%.*]] = fsub float [[X]], 2.000000e+00
31 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[FADD]], float 0.000000e+00
32 ; CHECK-NEXT: ret float [[SEL]]
34 %fcmp = fcmp ueq float %x, 2.0
35 %fadd = fsub float %x, 2.0
36 %sel = select i1 %fcmp, float %fadd, float 0.0
40 define float @select_fcmp_fsub_ueq_nnan(float %x) {
41 ; CHECK-LABEL: @select_fcmp_fsub_ueq_nnan(
42 ; CHECK-NEXT: ret float 0.000000e+00
44 %fcmp = fcmp nnan ueq float %x, 2.0
45 %fadd = fsub float %x, 2.0
46 %sel = select i1 %fcmp, float %fadd, float 0.0
50 define float @select_fcmp_fsub_une(float %x) {
51 ; CHECK-LABEL: @select_fcmp_fsub_une(
52 ; CHECK-NEXT: ret float 0.000000e+00
54 %fcmp = fcmp une float %x, 2.0
55 %fadd = fsub float %x, 2.0
56 %sel = select i1 %fcmp, float 0.0, float %fadd
60 define float @select_fcmp_fsub_une_zero(float %x) {
61 ; CHECK-LABEL: @select_fcmp_fsub_une_zero(
62 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp une float [[X:%.*]], 0.000000e+00
63 ; CHECK-NEXT: [[FADD:%.*]] = fsub float [[X]], 2.000000e+00
64 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float 2.000000e+00, float [[FADD]]
65 ; CHECK-NEXT: ret float [[SEL]]
67 %fcmp = fcmp une float %x, 0.0
68 %fadd = fsub float %x, 2.0
69 %sel = select i1 %fcmp, float 2.0, float %fadd
73 define float @select_fcmp_fsub_one(float %x) {
74 ; CHECK-LABEL: @select_fcmp_fsub_one(
75 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp one float [[X:%.*]], 2.000000e+00
76 ; CHECK-NEXT: [[FADD:%.*]] = fsub float [[X]], 2.000000e+00
77 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float 0.000000e+00, float [[FADD]]
78 ; CHECK-NEXT: ret float [[SEL]]
80 %fcmp = fcmp one float %x, 2.0
81 %fadd = fsub float %x, 2.0
82 %sel = select i1 %fcmp, float 0.0, float %fadd
86 define float @select_fcmp_fsub_one_nnan(float %x) {
87 ; CHECK-LABEL: @select_fcmp_fsub_one_nnan(
88 ; CHECK-NEXT: ret float 0.000000e+00
90 %fcmp = fcmp nnan one float %x, 2.0
91 %fadd = fsub float %x, 2.0
92 %sel = select i1 %fcmp, float 0.0, float %fadd
96 define float @select_fcmp_fadd(float %x) {
97 ; CHECK-LABEL: @select_fcmp_fadd(
98 ; CHECK-NEXT: ret float 4.000000e+00
100 %fcmp = fcmp oeq float %x, 2.0
101 %fadd = fadd float %x, 2.0
102 %sel = select i1 %fcmp, float %fadd, float 4.0
106 define <2 x float> @select_fcmp_fadd_vec(<2 x float> %x) {
107 ; CHECK-LABEL: @select_fcmp_fadd_vec(
108 ; CHECK-NEXT: ret <2 x float> splat (float 4.000000e+00)
110 %fcmp = fcmp oeq <2 x float> %x, <float 2.0, float 2.0>
111 %fadd = fadd <2 x float> %x, <float 2.0, float 2.0>
112 %sel = select <2 x i1> %fcmp, <2 x float> %fadd, <2 x float> <float 4.0, float 4.0>
117 ; Should not fold, because the fmul by identity may produce a different NaN
119 define float @select_fcmp_fmul_nonrefinement(float %x, float %y) {
120 ; CHECK-LABEL: @select_fcmp_fmul_nonrefinement(
121 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
122 ; CHECK-NEXT: [[FMUL:%.*]] = fmul float [[Y:%.*]], [[X]]
123 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[Y]], float [[FMUL]]
124 ; CHECK-NEXT: ret float [[SEL]]
126 %fcmp = fcmp oeq float %x, 1.0
127 %fmul = fmul float %y, %x
128 %sel = select i1 %fcmp, float %y, float %fmul
132 define float @select_fcmp_fmul(float %x) {
133 ; CHECK-LABEL: @select_fcmp_fmul(
134 ; CHECK-NEXT: ret float 4.000000e+00
136 %fcmp = fcmp oeq float %x, 2.0
137 %fmul = fmul float %x, 2.0
138 %sel = select i1 %fcmp, float %fmul, float 4.0
142 define float @select_fcmp_fdiv_nonrefinement(float %x, float %y) {
143 ; CHECK-LABEL: @select_fcmp_fdiv_nonrefinement(
144 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
145 ; CHECK-NEXT: [[FDIV:%.*]] = fdiv float [[Y:%.*]], [[X]]
146 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float [[Y]], float [[FDIV]]
147 ; CHECK-NEXT: ret float [[SEL]]
149 %fcmp = fcmp oeq float %x, 1.0
150 %fdiv = fdiv float %y, %x
151 %sel = select i1 %fcmp, float %y, float %fdiv
155 define float @select_fcmp_fdiv(float %x) {
156 ; CHECK-LABEL: @select_fcmp_fdiv(
157 ; CHECK-NEXT: ret float 1.000000e+00
159 %fcmp = fcmp oeq float %x, 2.0
160 %fdiv = fdiv float %x, 2.0
161 %sel = select i1 %fcmp, float %fdiv, float 1.0
165 define float @select_fcmp_frem(float %x) {
166 ; CHECK-LABEL: @select_fcmp_frem(
167 ; CHECK-NEXT: ret float 1.000000e+00
169 %fcmp = fcmp oeq float %x, 3.0
170 %frem = frem float %x, 2.0
171 %sel = select i1 %fcmp, float %frem, float 1.0
175 define <2 x float> @select_fcmp_insertelement(<2 x float> %x) {
176 ; CHECK-LABEL: @select_fcmp_insertelement(
177 ; CHECK-NEXT: ret <2 x float> <float 4.000000e+00, float 2.000000e+00>
179 %fcmp = fcmp oeq <2 x float> %x, <float 2.0, float 2.0>
180 %insert = insertelement <2 x float> %x, float 4.0, i64 0
181 %sel = select <2 x i1> %fcmp, <2 x float> %insert, <2 x float> <float 4.0, float 2.0>
185 define <4 x float> @select_fcmp_shufflevector_select(<4 x float> %x) {
186 ; CHECK-LABEL: @select_fcmp_shufflevector_select(
187 ; CHECK-NEXT: ret <4 x float> <float poison, float 2.000000e+00, float poison, float 2.000000e+00>
189 %fcmp = fcmp oeq <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
190 %shuffle = shufflevector <4 x float> %x, <4 x float> poison, <4 x i32> <i32 4, i32 1, i32 6, i32 3>
191 %sel = select <4 x i1> %fcmp, <4 x float> %shuffle, <4 x float> <float poison, float 2.0, float poison, float 2.0>
195 ; The hexfloat constant is PI / 2.
196 define float @select_fcmp_sin_nonrefinement(float %x) {
197 ; CHECK-LABEL: @select_fcmp_sin_nonrefinement(
198 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 0x3FF921FB60000000
199 ; CHECK-NEXT: [[SIN:%.*]] = call float @llvm.sin.f32(float [[X]])
200 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float 1.000000e+00, float [[SIN]]
201 ; CHECK-NEXT: ret float [[SEL]]
203 %fcmp = fcmp oeq float %x, 0x3FF921FB60000000
204 %sin = call float @llvm.sin.f32(float %x)
205 %sel = select i1 %fcmp, float 1.0, float %sin
209 ; The hexfloat constant is PI / 2.
210 define float @select_fcmp_sin(float %x) {
211 ; CHECK-LABEL: @select_fcmp_sin(
212 ; CHECK-NEXT: ret float 1.000000e+00
214 %fcmp = fcmp oeq float %x, 0x3FF921FB60000000
215 %sin = call float @llvm.sin.f32(float %x)
216 %sel = select i1 %fcmp, float %sin, float 1.0
220 ; The hexfloat constant is PI.
221 define float @select_fcmp_cos_nonrefinement(float %x) {
222 ; CHECK-LABEL: @select_fcmp_cos_nonrefinement(
223 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 0x400921FB60000000
224 ; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X]])
225 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], float -1.000000e+00, float [[COS]]
226 ; CHECK-NEXT: ret float [[SEL]]
228 %fcmp = fcmp oeq float %x, 0x400921FB60000000
229 %cos = call float @llvm.cos.f32(float %x)
230 %sel = select i1 %fcmp, float -1.0, float %cos
234 ; The hexfloat constant is PI.
235 define float @select_fcmp_cos(float %x) {
236 ; CHECK-LABEL: @select_fcmp_cos(
237 ; CHECK-NEXT: ret float -1.000000e+00
239 %fcmp = fcmp oeq float %x, 0x400921FB60000000
240 %cos = call float @llvm.cos.f32(float %x)
241 %sel = select i1 %fcmp, float %cos, float -1.0
245 define i32 @select_fcmp_lrint(float %x) {
246 ; CHECK-LABEL: @select_fcmp_lrint(
247 ; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[X:%.*]], 1.000000e+00
248 ; CHECK-NEXT: [[LRINT:%.*]] = call i32 @llvm.lrint.i32.f32(float [[X]])
249 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[FCMP]], i32 [[LRINT]], i32 1
250 ; CHECK-NEXT: ret i32 [[SEL]]
252 %fcmp = fcmp oeq float %x, 1.0
253 %lrint = call i32 @llvm.lrint.i32.f32(float %x)
254 %sel = select i1 %fcmp, i32 %lrint, i32 1