1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define float @select_fadd(i1 %cond, float %A, float %B) {
5 ; CHECK-LABEL: @select_fadd(
6 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float -0.000000e+00
7 ; CHECK-NEXT: [[D:%.*]] = fadd float [[C]], [[A:%.*]]
8 ; CHECK-NEXT: ret float [[D]]
10 %C = fadd float %A, %B
11 %D = select i1 %cond, float %C, float %A
15 define float @select_fadd_swapped(i1 %cond, float %A, float %B) {
16 ; CHECK-LABEL: @select_fadd_swapped(
17 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float -0.000000e+00, float [[B:%.*]]
18 ; CHECK-NEXT: [[D:%.*]] = fadd float [[C]], [[A:%.*]]
19 ; CHECK-NEXT: ret float [[D]]
21 %C = fadd float %A, %B
22 %D = select i1 %cond, float %A, float %C
26 define float @select_fadd_fast_math(i1 %cond, float %A, float %B) {
27 ; CHECK-LABEL: @select_fadd_fast_math(
28 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float -0.000000e+00
29 ; CHECK-NEXT: [[D:%.*]] = fadd fast float [[C]], [[A:%.*]]
30 ; CHECK-NEXT: ret float [[D]]
32 %C = fadd fast float %A, %B
33 %D = select i1 %cond, float %C, float %A
37 define float @select_fadd_swapped_fast_math(i1 %cond, float %A, float %B) {
38 ; CHECK-LABEL: @select_fadd_swapped_fast_math(
39 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float -0.000000e+00, float [[B:%.*]]
40 ; CHECK-NEXT: [[D:%.*]] = fadd fast float [[C]], [[A:%.*]]
41 ; CHECK-NEXT: ret float [[D]]
43 %C = fadd fast float %A, %B
44 %D = select i1 %cond, float %A, float %C
48 define <4 x float> @select_nsz_fadd_v4f32(<4 x i1> %cond, <4 x float> %A, <4 x float> %B) {
49 ; CHECK-LABEL: @select_nsz_fadd_v4f32(
50 ; CHECK-NEXT: [[C:%.*]] = select nnan nsz <4 x i1> [[COND:%.*]], <4 x float> [[B:%.*]], <4 x float> zeroinitializer
51 ; CHECK-NEXT: [[D:%.*]] = fadd nnan nsz <4 x float> [[C]], [[A:%.*]]
52 ; CHECK-NEXT: ret <4 x float> [[D]]
54 %C = fadd nsz nnan <4 x float> %A, %B
55 %D = select nsz nnan <4 x i1> %cond, <4 x float> %C, <4 x float> %A
59 define <vscale x 4 x float> @select_nsz_fadd_nxv4f32(<vscale x 4 x i1> %cond, <vscale x 4 x float> %A, <vscale x 4 x float> %B) {
60 ; CHECK-LABEL: @select_nsz_fadd_nxv4f32(
61 ; CHECK-NEXT: [[C:%.*]] = select nnan nsz <vscale x 4 x i1> [[COND:%.*]], <vscale x 4 x float> [[B:%.*]], <vscale x 4 x float> zeroinitializer
62 ; CHECK-NEXT: [[D:%.*]] = fadd nnan nsz <vscale x 4 x float> [[C]], [[A:%.*]]
63 ; CHECK-NEXT: ret <vscale x 4 x float> [[D]]
65 %C = fadd nsz nnan <vscale x 4 x float> %A, %B
66 %D = select nsz nnan <vscale x 4 x i1> %cond, <vscale x 4 x float> %C, <vscale x 4 x float> %A
67 ret <vscale x 4 x float> %D
70 define <vscale x 4 x float> @select_nsz_fadd_nxv4f32_swapops(<vscale x 4 x i1> %cond, <vscale x 4 x float> %A, <vscale x 4 x float> %B) {
71 ; CHECK-LABEL: @select_nsz_fadd_nxv4f32_swapops(
72 ; CHECK-NEXT: [[C:%.*]] = select fast <vscale x 4 x i1> [[COND:%.*]], <vscale x 4 x float> zeroinitializer, <vscale x 4 x float> [[B:%.*]]
73 ; CHECK-NEXT: [[D:%.*]] = fadd fast <vscale x 4 x float> [[C]], [[A:%.*]]
74 ; CHECK-NEXT: ret <vscale x 4 x float> [[D]]
76 %C = fadd fast <vscale x 4 x float> %A, %B
77 %D = select fast <vscale x 4 x i1> %cond, <vscale x 4 x float> %A, <vscale x 4 x float> %C
78 ret <vscale x 4 x float> %D
81 define float @select_fmul(i1 %cond, float %A, float %B) {
82 ; CHECK-LABEL: @select_fmul(
83 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 1.000000e+00
84 ; CHECK-NEXT: [[D:%.*]] = fmul float [[C]], [[A:%.*]]
85 ; CHECK-NEXT: ret float [[D]]
87 %C = fmul float %A, %B
88 %D = select i1 %cond, float %C, float %A
92 define float @select_fmul_swapped(i1 %cond, float %A, float %B) {
93 ; CHECK-LABEL: @select_fmul_swapped(
94 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float [[B:%.*]]
95 ; CHECK-NEXT: [[D:%.*]] = fmul float [[C]], [[A:%.*]]
96 ; CHECK-NEXT: ret float [[D]]
98 %C = fmul float %A, %B
99 %D = select i1 %cond, float %A, float %C
103 define float @select_fmul_fast_math(i1 %cond, float %A, float %B) {
104 ; CHECK-LABEL: @select_fmul_fast_math(
105 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 1.000000e+00
106 ; CHECK-NEXT: [[D:%.*]] = fmul fast float [[C]], [[A:%.*]]
107 ; CHECK-NEXT: ret float [[D]]
109 %C = fmul fast float %A, %B
110 %D = select i1 %cond, float %C, float %A
114 define float @select_fmul_swapped_fast_math(i1 %cond, float %A, float %B) {
115 ; CHECK-LABEL: @select_fmul_swapped_fast_math(
116 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float [[B:%.*]]
117 ; CHECK-NEXT: [[D:%.*]] = fmul fast float [[C]], [[A:%.*]]
118 ; CHECK-NEXT: ret float [[D]]
120 %C = fmul fast float %A, %B
121 %D = select i1 %cond, float %A, float %C
125 define float @select_fsub(i1 %cond, float %A, float %B) {
126 ; CHECK-LABEL: @select_fsub(
127 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 0.000000e+00
128 ; CHECK-NEXT: [[D:%.*]] = fsub float [[A:%.*]], [[C]]
129 ; CHECK-NEXT: ret float [[D]]
131 %C = fsub float %A, %B
132 %D = select i1 %cond, float %C, float %A
136 define float @select_fsub_swapped(i1 %cond, float %A, float %B) {
137 ; CHECK-LABEL: @select_fsub_swapped(
138 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 0.000000e+00, float [[B:%.*]]
139 ; CHECK-NEXT: [[D:%.*]] = fsub float [[A:%.*]], [[C]]
140 ; CHECK-NEXT: ret float [[D]]
142 %C = fsub float %A, %B
143 %D = select i1 %cond, float %A, float %C
147 define float @select_fsub_fast_math(i1 %cond, float %A, float %B) {
148 ; CHECK-LABEL: @select_fsub_fast_math(
149 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 0.000000e+00
150 ; CHECK-NEXT: [[D:%.*]] = fsub fast float [[A:%.*]], [[C]]
151 ; CHECK-NEXT: ret float [[D]]
153 %C = fsub fast float %A, %B
154 %D = select i1 %cond, float %C, float %A
158 define float @select_fsub_swapped_fast_math(i1 %cond, float %A, float %B) {
159 ; CHECK-LABEL: @select_fsub_swapped_fast_math(
160 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 0.000000e+00, float [[B:%.*]]
161 ; CHECK-NEXT: [[D:%.*]] = fsub fast float [[A:%.*]], [[C]]
162 ; CHECK-NEXT: ret float [[D]]
164 %C = fsub fast float %A, %B
165 %D = select i1 %cond, float %A, float %C
169 define <4 x float> @select_nsz_fsub_v4f32(<4 x i1> %cond, <4 x float> %A, <4 x float> %B) {
170 ; CHECK-LABEL: @select_nsz_fsub_v4f32(
171 ; CHECK-NEXT: [[C:%.*]] = select nsz <4 x i1> [[COND:%.*]], <4 x float> [[B:%.*]], <4 x float> zeroinitializer
172 ; CHECK-NEXT: [[D:%.*]] = fsub <4 x float> [[A:%.*]], [[C]]
173 ; CHECK-NEXT: ret <4 x float> [[D]]
175 %C = fsub <4 x float> %A, %B
176 %D = select nsz <4 x i1> %cond, <4 x float> %C, <4 x float> %A
180 define <vscale x 4 x float> @select_nsz_fsub_nxv4f32(<vscale x 4 x i1> %cond, <vscale x 4 x float> %A, <vscale x 4 x float> %B) {
181 ; CHECK-LABEL: @select_nsz_fsub_nxv4f32(
182 ; CHECK-NEXT: [[C:%.*]] = select nsz <vscale x 4 x i1> [[COND:%.*]], <vscale x 4 x float> [[B:%.*]], <vscale x 4 x float> zeroinitializer
183 ; CHECK-NEXT: [[D:%.*]] = fsub <vscale x 4 x float> [[A:%.*]], [[C]]
184 ; CHECK-NEXT: ret <vscale x 4 x float> [[D]]
186 %C = fsub <vscale x 4 x float> %A, %B
187 %D = select nsz <vscale x 4 x i1> %cond, <vscale x 4 x float> %C, <vscale x 4 x float> %A
188 ret <vscale x 4 x float> %D
191 ; 'fsub' can only fold on the amount subtracted.
192 define float @select_fsub_invalid(i1 %cond, float %A, float %B) {
193 ; CHECK-LABEL: @select_fsub_invalid(
194 ; CHECK-NEXT: [[C:%.*]] = fsub float [[B:%.*]], [[A:%.*]]
195 ; CHECK-NEXT: [[D:%.*]] = select i1 [[COND:%.*]], float [[C]], float [[A]]
196 ; CHECK-NEXT: ret float [[D]]
198 %C = fsub float %B, %A
199 %D = select i1 %cond, float %C, float %A
203 define float @select_fdiv(i1 %cond, float %A, float %B) {
204 ; CHECK-LABEL: @select_fdiv(
205 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 1.000000e+00
206 ; CHECK-NEXT: [[D:%.*]] = fdiv float [[A:%.*]], [[C]]
207 ; CHECK-NEXT: ret float [[D]]
209 %C = fdiv float %A, %B
210 %D = select i1 %cond, float %C, float %A
214 define float @select_fdiv_swapped(i1 %cond, float %A, float %B) {
215 ; CHECK-LABEL: @select_fdiv_swapped(
216 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float [[B:%.*]]
217 ; CHECK-NEXT: [[D:%.*]] = fdiv float [[A:%.*]], [[C]]
218 ; CHECK-NEXT: ret float [[D]]
220 %C = fdiv float %A, %B
221 %D = select i1 %cond, float %A, float %C
225 define float @select_fdiv_fast_math(i1 %cond, float %A, float %B) {
226 ; CHECK-LABEL: @select_fdiv_fast_math(
227 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float [[B:%.*]], float 1.000000e+00
228 ; CHECK-NEXT: [[D:%.*]] = fdiv fast float [[A:%.*]], [[C]]
229 ; CHECK-NEXT: ret float [[D]]
231 %C = fdiv fast float %A, %B
232 %D = select i1 %cond, float %C, float %A
236 define float @select_fdiv_swapped_fast_math(i1 %cond, float %A, float %B) {
237 ; CHECK-LABEL: @select_fdiv_swapped_fast_math(
238 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float [[B:%.*]]
239 ; CHECK-NEXT: [[D:%.*]] = fdiv fast float [[A:%.*]], [[C]]
240 ; CHECK-NEXT: ret float [[D]]
242 %C = fdiv fast float %A, %B
243 %D = select i1 %cond, float %A, float %C
247 ; 'fdiv' can only fold on the divisor amount.
248 define float @select_fdiv_invalid(i1 %cond, float %A, float %B) {
249 ; CHECK-LABEL: @select_fdiv_invalid(
250 ; CHECK-NEXT: [[C:%.*]] = fdiv float [[B:%.*]], [[A:%.*]]
251 ; CHECK-NEXT: [[D:%.*]] = select i1 [[COND:%.*]], float [[C]], float [[A]]
252 ; CHECK-NEXT: ret float [[D]]
254 %C = fdiv float %B, %A
255 %D = select i1 %cond, float %C, float %A