1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=powerpc64le-unknown-unknown -verify-machineinstrs -mattr=+isel | FileCheck %s --check-prefix=ALL --check-prefix=ISEL
3; RUN: llc < %s -mtriple=powerpc64le-unknown-unknown -verify-machineinstrs -mattr=-isel | FileCheck %s --check-prefix=ALL --check-prefix=NO_ISEL
4
5; Select of constants: control flow / conditional moves can always be replaced by logic+math (but may not be worth it?).
6; Test the zeroext/signext variants of each pattern to see if that makes a difference.
7
8; select Cond, 0, 1 --> zext (!Cond)
9
10define i32 @select_0_or_1(i1 %cond) {
11; ALL-LABEL: select_0_or_1:
12; ALL:       # %bb.0:
13; ALL-NEXT:    not 3, 3
14; ALL-NEXT:    clrldi 3, 3, 63
15; ALL-NEXT:    blr
16  %sel = select i1 %cond, i32 0, i32 1
17  ret i32 %sel
18}
19
20define i32 @select_0_or_1_zeroext(i1 zeroext %cond) {
21; ALL-LABEL: select_0_or_1_zeroext:
22; ALL:       # %bb.0:
23; ALL-NEXT:    xori 3, 3, 1
24; ALL-NEXT:    blr
25  %sel = select i1 %cond, i32 0, i32 1
26  ret i32 %sel
27}
28
29define i32 @select_0_or_1_signext(i1 signext %cond) {
30; ALL-LABEL: select_0_or_1_signext:
31; ALL:       # %bb.0:
32; ALL-NEXT:    not 3, 3
33; ALL-NEXT:    clrldi 3, 3, 63
34; ALL-NEXT:    blr
35  %sel = select i1 %cond, i32 0, i32 1
36  ret i32 %sel
37}
38
39; select Cond, 1, 0 --> zext (Cond)
40
41define i32 @select_1_or_0(i1 %cond) {
42; ALL-LABEL: select_1_or_0:
43; ALL:       # %bb.0:
44; ALL-NEXT:    clrldi 3, 3, 63
45; ALL-NEXT:    blr
46  %sel = select i1 %cond, i32 1, i32 0
47  ret i32 %sel
48}
49
50define i32 @select_1_or_0_zeroext(i1 zeroext %cond) {
51; ALL-LABEL: select_1_or_0_zeroext:
52; ALL:       # %bb.0:
53; ALL-NEXT:    blr
54  %sel = select i1 %cond, i32 1, i32 0
55  ret i32 %sel
56}
57
58define i32 @select_1_or_0_signext(i1 signext %cond) {
59; ALL-LABEL: select_1_or_0_signext:
60; ALL:       # %bb.0:
61; ALL-NEXT:    clrldi 3, 3, 63
62; ALL-NEXT:    blr
63  %sel = select i1 %cond, i32 1, i32 0
64  ret i32 %sel
65}
66
67; select Cond, 0, -1 --> sext (!Cond)
68
69define i32 @select_0_or_neg1(i1 %cond) {
70; ISEL-LABEL: select_0_or_neg1:
71; ISEL:       # %bb.0:
72; ISEL-NEXT:    li 4, 0
73; ISEL-NEXT:    andi. 3, 3, 1
74; ISEL-NEXT:    oris 3, 4, 65535
75; ISEL-NEXT:    ori 3, 3, 65535
76; ISEL-NEXT:    isel 3, 0, 3, 1
77; ISEL-NEXT:    blr
78;
79; NO_ISEL-LABEL: select_0_or_neg1:
80; NO_ISEL:       # %bb.0:
81; NO_ISEL-NEXT:    li 4, 0
82; NO_ISEL-NEXT:    andi. 3, 3, 1
83; NO_ISEL-NEXT:    oris 3, 4, 65535
84; NO_ISEL-NEXT:    ori 3, 3, 65535
85; NO_ISEL-NEXT:    bc 12, 1, .LBB6_1
86; NO_ISEL-NEXT:    blr
87; NO_ISEL-NEXT:  .LBB6_1:
88; NO_ISEL-NEXT:    addi 3, 0, 0
89; NO_ISEL-NEXT:    blr
90  %sel = select i1 %cond, i32 0, i32 -1
91  ret i32 %sel
92}
93
94define i32 @select_0_or_neg1_zeroext(i1 zeroext %cond) {
95; ISEL-LABEL: select_0_or_neg1_zeroext:
96; ISEL:       # %bb.0:
97; ISEL-NEXT:    li 4, 0
98; ISEL-NEXT:    andi. 3, 3, 1
99; ISEL-NEXT:    oris 3, 4, 65535
100; ISEL-NEXT:    ori 3, 3, 65535
101; ISEL-NEXT:    isel 3, 0, 3, 1
102; ISEL-NEXT:    blr
103;
104; NO_ISEL-LABEL: select_0_or_neg1_zeroext:
105; NO_ISEL:       # %bb.0:
106; NO_ISEL-NEXT:    li 4, 0
107; NO_ISEL-NEXT:    andi. 3, 3, 1
108; NO_ISEL-NEXT:    oris 3, 4, 65535
109; NO_ISEL-NEXT:    ori 3, 3, 65535
110; NO_ISEL-NEXT:    bc 12, 1, .LBB7_1
111; NO_ISEL-NEXT:    blr
112; NO_ISEL-NEXT:  .LBB7_1:
113; NO_ISEL-NEXT:    addi 3, 0, 0
114; NO_ISEL-NEXT:    blr
115  %sel = select i1 %cond, i32 0, i32 -1
116  ret i32 %sel
117}
118
119define i32 @select_0_or_neg1_signext(i1 signext %cond) {
120; ISEL-LABEL: select_0_or_neg1_signext:
121; ISEL:       # %bb.0:
122; ISEL-NEXT:    li 4, 0
123; ISEL-NEXT:    andi. 3, 3, 1
124; ISEL-NEXT:    oris 3, 4, 65535
125; ISEL-NEXT:    ori 3, 3, 65535
126; ISEL-NEXT:    isel 3, 0, 3, 1
127; ISEL-NEXT:    blr
128;
129; NO_ISEL-LABEL: select_0_or_neg1_signext:
130; NO_ISEL:       # %bb.0:
131; NO_ISEL-NEXT:    li 4, 0
132; NO_ISEL-NEXT:    andi. 3, 3, 1
133; NO_ISEL-NEXT:    oris 3, 4, 65535
134; NO_ISEL-NEXT:    ori 3, 3, 65535
135; NO_ISEL-NEXT:    bc 12, 1, .LBB8_1
136; NO_ISEL-NEXT:    blr
137; NO_ISEL-NEXT:  .LBB8_1:
138; NO_ISEL-NEXT:    addi 3, 0, 0
139; NO_ISEL-NEXT:    blr
140  %sel = select i1 %cond, i32 0, i32 -1
141  ret i32 %sel
142}
143
144; select Cond, -1, 0 --> sext (Cond)
145
146define i32 @select_neg1_or_0(i1 %cond) {
147; ISEL-LABEL: select_neg1_or_0:
148; ISEL:       # %bb.0:
149; ISEL-NEXT:    li 4, 0
150; ISEL-NEXT:    andi. 3, 3, 1
151; ISEL-NEXT:    oris 3, 4, 65535
152; ISEL-NEXT:    ori 3, 3, 65535
153; ISEL-NEXT:    isel 3, 3, 4, 1
154; ISEL-NEXT:    blr
155;
156; NO_ISEL-LABEL: select_neg1_or_0:
157; NO_ISEL:       # %bb.0:
158; NO_ISEL-NEXT:    li 4, 0
159; NO_ISEL-NEXT:    andi. 3, 3, 1
160; NO_ISEL-NEXT:    oris 3, 4, 65535
161; NO_ISEL-NEXT:    ori 3, 3, 65535
162; NO_ISEL-NEXT:    bclr 12, 1, 0
163; NO_ISEL-NEXT:  # %bb.1:
164; NO_ISEL-NEXT:    ori 3, 4, 0
165; NO_ISEL-NEXT:    blr
166  %sel = select i1 %cond, i32 -1, i32 0
167  ret i32 %sel
168}
169
170define i32 @select_neg1_or_0_zeroext(i1 zeroext %cond) {
171; ISEL-LABEL: select_neg1_or_0_zeroext:
172; ISEL:       # %bb.0:
173; ISEL-NEXT:    li 4, 0
174; ISEL-NEXT:    andi. 3, 3, 1
175; ISEL-NEXT:    oris 3, 4, 65535
176; ISEL-NEXT:    ori 3, 3, 65535
177; ISEL-NEXT:    isel 3, 3, 4, 1
178; ISEL-NEXT:    blr
179;
180; NO_ISEL-LABEL: select_neg1_or_0_zeroext:
181; NO_ISEL:       # %bb.0:
182; NO_ISEL-NEXT:    li 4, 0
183; NO_ISEL-NEXT:    andi. 3, 3, 1
184; NO_ISEL-NEXT:    oris 3, 4, 65535
185; NO_ISEL-NEXT:    ori 3, 3, 65535
186; NO_ISEL-NEXT:    bclr 12, 1, 0
187; NO_ISEL-NEXT:  # %bb.1:
188; NO_ISEL-NEXT:    ori 3, 4, 0
189; NO_ISEL-NEXT:    blr
190  %sel = select i1 %cond, i32 -1, i32 0
191  ret i32 %sel
192}
193
194define i32 @select_neg1_or_0_signext(i1 signext %cond) {
195; ISEL-LABEL: select_neg1_or_0_signext:
196; ISEL:       # %bb.0:
197; ISEL-NEXT:    li 4, 0
198; ISEL-NEXT:    andi. 3, 3, 1
199; ISEL-NEXT:    oris 3, 4, 65535
200; ISEL-NEXT:    ori 3, 3, 65535
201; ISEL-NEXT:    isel 3, 3, 4, 1
202; ISEL-NEXT:    blr
203;
204; NO_ISEL-LABEL: select_neg1_or_0_signext:
205; NO_ISEL:       # %bb.0:
206; NO_ISEL-NEXT:    li 4, 0
207; NO_ISEL-NEXT:    andi. 3, 3, 1
208; NO_ISEL-NEXT:    oris 3, 4, 65535
209; NO_ISEL-NEXT:    ori 3, 3, 65535
210; NO_ISEL-NEXT:    bclr 12, 1, 0
211; NO_ISEL-NEXT:  # %bb.1:
212; NO_ISEL-NEXT:    ori 3, 4, 0
213; NO_ISEL-NEXT:    blr
214  %sel = select i1 %cond, i32 -1, i32 0
215  ret i32 %sel
216}
217
218; select Cond, C+1, C --> add (zext Cond), C
219
220define i32 @select_Cplus1_C(i1 %cond) {
221; ALL-LABEL: select_Cplus1_C:
222; ALL:       # %bb.0:
223; ALL-NEXT:    clrldi 3, 3, 63
224; ALL-NEXT:    addi 3, 3, 41
225; ALL-NEXT:    blr
226  %sel = select i1 %cond, i32 42, i32 41
227  ret i32 %sel
228}
229
230define i32 @select_Cplus1_C_zeroext(i1 zeroext %cond) {
231; ALL-LABEL: select_Cplus1_C_zeroext:
232; ALL:       # %bb.0:
233; ALL-NEXT:    addi 3, 3, 41
234; ALL-NEXT:    blr
235  %sel = select i1 %cond, i32 42, i32 41
236  ret i32 %sel
237}
238
239define i32 @select_Cplus1_C_signext(i1 signext %cond) {
240; ALL-LABEL: select_Cplus1_C_signext:
241; ALL:       # %bb.0:
242; ALL-NEXT:    subfic 3, 3, 41
243; ALL-NEXT:    blr
244  %sel = select i1 %cond, i32 42, i32 41
245  ret i32 %sel
246}
247
248; select Cond, C, C+1 --> add (sext Cond), C
249
250define i32 @select_C_Cplus1(i1 %cond) {
251; ALL-LABEL: select_C_Cplus1:
252; ALL:       # %bb.0:
253; ALL-NEXT:    clrldi 3, 3, 63
254; ALL-NEXT:    subfic 3, 3, 42
255; ALL-NEXT:    blr
256  %sel = select i1 %cond, i32 41, i32 42
257  ret i32 %sel
258}
259
260define i32 @select_C_Cplus1_zeroext(i1 zeroext %cond) {
261; ALL-LABEL: select_C_Cplus1_zeroext:
262; ALL:       # %bb.0:
263; ALL-NEXT:    subfic 3, 3, 42
264; ALL-NEXT:    blr
265  %sel = select i1 %cond, i32 41, i32 42
266  ret i32 %sel
267}
268
269define i32 @select_C_Cplus1_signext(i1 signext %cond) {
270; ALL-LABEL: select_C_Cplus1_signext:
271; ALL:       # %bb.0:
272; ALL-NEXT:    addi 3, 3, 42
273; ALL-NEXT:    blr
274  %sel = select i1 %cond, i32 41, i32 42
275  ret i32 %sel
276}
277
278; In general, select of 2 constants could be:
279; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2 --> add (and (sext Cond), C1-C2), C2
280
281define i32 @select_C1_C2(i1 %cond) {
282; ISEL-LABEL: select_C1_C2:
283; ISEL:       # %bb.0:
284; ISEL-NEXT:    andi. 3, 3, 1
285; ISEL-NEXT:    li 4, 421
286; ISEL-NEXT:    li 3, 42
287; ISEL-NEXT:    isel 3, 4, 3, 1
288; ISEL-NEXT:    blr
289;
290; NO_ISEL-LABEL: select_C1_C2:
291; NO_ISEL:       # %bb.0:
292; NO_ISEL-NEXT:    andi. 3, 3, 1
293; NO_ISEL-NEXT:    li 4, 421
294; NO_ISEL-NEXT:    li 3, 42
295; NO_ISEL-NEXT:    bc 12, 1, .LBB18_1
296; NO_ISEL-NEXT:    blr
297; NO_ISEL-NEXT:  .LBB18_1:
298; NO_ISEL-NEXT:    addi 3, 4, 0
299; NO_ISEL-NEXT:    blr
300  %sel = select i1 %cond, i32 421, i32 42
301  ret i32 %sel
302}
303
304define i32 @select_C1_C2_zeroext(i1 zeroext %cond) {
305; ISEL-LABEL: select_C1_C2_zeroext:
306; ISEL:       # %bb.0:
307; ISEL-NEXT:    andi. 3, 3, 1
308; ISEL-NEXT:    li 4, 421
309; ISEL-NEXT:    li 3, 42
310; ISEL-NEXT:    isel 3, 4, 3, 1
311; ISEL-NEXT:    blr
312;
313; NO_ISEL-LABEL: select_C1_C2_zeroext:
314; NO_ISEL:       # %bb.0:
315; NO_ISEL-NEXT:    andi. 3, 3, 1
316; NO_ISEL-NEXT:    li 4, 421
317; NO_ISEL-NEXT:    li 3, 42
318; NO_ISEL-NEXT:    bc 12, 1, .LBB19_1
319; NO_ISEL-NEXT:    blr
320; NO_ISEL-NEXT:  .LBB19_1:
321; NO_ISEL-NEXT:    addi 3, 4, 0
322; NO_ISEL-NEXT:    blr
323  %sel = select i1 %cond, i32 421, i32 42
324  ret i32 %sel
325}
326
327define i32 @select_C1_C2_signext(i1 signext %cond) {
328; ISEL-LABEL: select_C1_C2_signext:
329; ISEL:       # %bb.0:
330; ISEL-NEXT:    andi. 3, 3, 1
331; ISEL-NEXT:    li 4, 421
332; ISEL-NEXT:    li 3, 42
333; ISEL-NEXT:    isel 3, 4, 3, 1
334; ISEL-NEXT:    blr
335;
336; NO_ISEL-LABEL: select_C1_C2_signext:
337; NO_ISEL:       # %bb.0:
338; NO_ISEL-NEXT:    andi. 3, 3, 1
339; NO_ISEL-NEXT:    li 4, 421
340; NO_ISEL-NEXT:    li 3, 42
341; NO_ISEL-NEXT:    bc 12, 1, .LBB20_1
342; NO_ISEL-NEXT:    blr
343; NO_ISEL-NEXT:  .LBB20_1:
344; NO_ISEL-NEXT:    addi 3, 4, 0
345; NO_ISEL-NEXT:    blr
346  %sel = select i1 %cond, i32 421, i32 42
347  ret i32 %sel
348}
349
350; A binary operator with constant after the select should always get folded into the select.
351
352define i8 @sel_constants_add_constant(i1 %cond) {
353; ISEL-LABEL: sel_constants_add_constant:
354; ISEL:       # %bb.0:
355; ISEL-NEXT:    andi. 3, 3, 1
356; ISEL-NEXT:    li 4, 1
357; ISEL-NEXT:    li 3, 28
358; ISEL-NEXT:    isel 3, 4, 3, 1
359; ISEL-NEXT:    blr
360;
361; NO_ISEL-LABEL: sel_constants_add_constant:
362; NO_ISEL:       # %bb.0:
363; NO_ISEL-NEXT:    andi. 3, 3, 1
364; NO_ISEL-NEXT:    li 4, 1
365; NO_ISEL-NEXT:    li 3, 28
366; NO_ISEL-NEXT:    bc 12, 1, .LBB21_1
367; NO_ISEL-NEXT:    blr
368; NO_ISEL-NEXT:  .LBB21_1:
369; NO_ISEL-NEXT:    addi 3, 4, 0
370; NO_ISEL-NEXT:    blr
371  %sel = select i1 %cond, i8 -4, i8 23
372  %bo = add i8 %sel, 5
373  ret i8 %bo
374}
375
376define i8 @sel_constants_sub_constant(i1 %cond) {
377; ISEL-LABEL: sel_constants_sub_constant:
378; ISEL:       # %bb.0:
379; ISEL-NEXT:    li 4, 0
380; ISEL-NEXT:    andi. 3, 3, 1
381; ISEL-NEXT:    oris 3, 4, 65535
382; ISEL-NEXT:    li 4, 18
383; ISEL-NEXT:    ori 3, 3, 65527
384; ISEL-NEXT:    isel 3, 3, 4, 1
385; ISEL-NEXT:    blr
386;
387; NO_ISEL-LABEL: sel_constants_sub_constant:
388; NO_ISEL:       # %bb.0:
389; NO_ISEL-NEXT:    li 4, 0
390; NO_ISEL-NEXT:    andi. 3, 3, 1
391; NO_ISEL-NEXT:    oris 3, 4, 65535
392; NO_ISEL-NEXT:    li 4, 18
393; NO_ISEL-NEXT:    ori 3, 3, 65527
394; NO_ISEL-NEXT:    bclr 12, 1, 0
395; NO_ISEL-NEXT:  # %bb.1:
396; NO_ISEL-NEXT:    ori 3, 4, 0
397; NO_ISEL-NEXT:    blr
398  %sel = select i1 %cond, i8 -4, i8 23
399  %bo = sub i8 %sel, 5
400  ret i8 %bo
401}
402
403define i8 @sel_constants_mul_constant(i1 %cond) {
404; ISEL-LABEL: sel_constants_mul_constant:
405; ISEL:       # %bb.0:
406; ISEL-NEXT:    lis 4, 16383
407; ISEL-NEXT:    andi. 3, 3, 1
408; ISEL-NEXT:    ori 3, 4, 65531
409; ISEL-NEXT:    li 4, 115
410; ISEL-NEXT:    sldi 3, 3, 2
411; ISEL-NEXT:    isel 3, 3, 4, 1
412; ISEL-NEXT:    blr
413;
414; NO_ISEL-LABEL: sel_constants_mul_constant:
415; NO_ISEL:       # %bb.0:
416; NO_ISEL-NEXT:    lis 4, 16383
417; NO_ISEL-NEXT:    andi. 3, 3, 1
418; NO_ISEL-NEXT:    ori 3, 4, 65531
419; NO_ISEL-NEXT:    li 4, 115
420; NO_ISEL-NEXT:    sldi 3, 3, 2
421; NO_ISEL-NEXT:    bclr 12, 1, 0
422; NO_ISEL-NEXT:  # %bb.1:
423; NO_ISEL-NEXT:    ori 3, 4, 0
424; NO_ISEL-NEXT:    blr
425  %sel = select i1 %cond, i8 -4, i8 23
426  %bo = mul i8 %sel, 5
427  ret i8 %bo
428}
429
430define i8 @sel_constants_sdiv_constant(i1 %cond) {
431; ISEL-LABEL: sel_constants_sdiv_constant:
432; ISEL:       # %bb.0:
433; ISEL-NEXT:    andi. 3, 3, 1
434; ISEL-NEXT:    li 3, 4
435; ISEL-NEXT:    isel 3, 0, 3, 1
436; ISEL-NEXT:    blr
437;
438; NO_ISEL-LABEL: sel_constants_sdiv_constant:
439; NO_ISEL:       # %bb.0:
440; NO_ISEL-NEXT:    andi. 3, 3, 1
441; NO_ISEL-NEXT:    li 3, 4
442; NO_ISEL-NEXT:    bc 12, 1, .LBB24_1
443; NO_ISEL-NEXT:    blr
444; NO_ISEL-NEXT:  .LBB24_1:
445; NO_ISEL-NEXT:    addi 3, 0, 0
446; NO_ISEL-NEXT:    blr
447  %sel = select i1 %cond, i8 -4, i8 23
448  %bo = sdiv i8 %sel, 5
449  ret i8 %bo
450}
451
452define i8 @sel_constants_udiv_constant(i1 %cond) {
453; ISEL-LABEL: sel_constants_udiv_constant:
454; ISEL:       # %bb.0:
455; ISEL-NEXT:    andi. 3, 3, 1
456; ISEL-NEXT:    li 4, 50
457; ISEL-NEXT:    li 3, 4
458; ISEL-NEXT:    isel 3, 4, 3, 1
459; ISEL-NEXT:    blr
460;
461; NO_ISEL-LABEL: sel_constants_udiv_constant:
462; NO_ISEL:       # %bb.0:
463; NO_ISEL-NEXT:    andi. 3, 3, 1
464; NO_ISEL-NEXT:    li 4, 50
465; NO_ISEL-NEXT:    li 3, 4
466; NO_ISEL-NEXT:    bc 12, 1, .LBB25_1
467; NO_ISEL-NEXT:    blr
468; NO_ISEL-NEXT:  .LBB25_1:
469; NO_ISEL-NEXT:    addi 3, 4, 0
470; NO_ISEL-NEXT:    blr
471  %sel = select i1 %cond, i8 -4, i8 23
472  %bo = udiv i8 %sel, 5
473  ret i8 %bo
474}
475
476define i8 @sel_constants_srem_constant(i1 %cond) {
477; ISEL-LABEL: sel_constants_srem_constant:
478; ISEL:       # %bb.0:
479; ISEL-NEXT:    lis 4, 16383
480; ISEL-NEXT:    andi. 3, 3, 1
481; ISEL-NEXT:    ori 3, 4, 65535
482; ISEL-NEXT:    li 4, 3
483; ISEL-NEXT:    sldi 3, 3, 2
484; ISEL-NEXT:    isel 3, 3, 4, 1
485; ISEL-NEXT:    blr
486;
487; NO_ISEL-LABEL: sel_constants_srem_constant:
488; NO_ISEL:       # %bb.0:
489; NO_ISEL-NEXT:    lis 4, 16383
490; NO_ISEL-NEXT:    andi. 3, 3, 1
491; NO_ISEL-NEXT:    ori 3, 4, 65535
492; NO_ISEL-NEXT:    li 4, 3
493; NO_ISEL-NEXT:    sldi 3, 3, 2
494; NO_ISEL-NEXT:    bclr 12, 1, 0
495; NO_ISEL-NEXT:  # %bb.1:
496; NO_ISEL-NEXT:    ori 3, 4, 0
497; NO_ISEL-NEXT:    blr
498  %sel = select i1 %cond, i8 -4, i8 23
499  %bo = srem i8 %sel, 5
500  ret i8 %bo
501}
502
503define i8 @sel_constants_urem_constant(i1 %cond) {
504; ALL-LABEL: sel_constants_urem_constant:
505; ALL:       # %bb.0:
506; ALL-NEXT:    rlwinm 3, 3, 0, 31, 31
507; ALL-NEXT:    subfic 3, 3, 3
508; ALL-NEXT:    blr
509  %sel = select i1 %cond, i8 -4, i8 23
510  %bo = urem i8 %sel, 5
511  ret i8 %bo
512}
513
514define i8 @sel_constants_and_constant(i1 %cond) {
515; ALL-LABEL: sel_constants_and_constant:
516; ALL:       # %bb.0:
517; ALL-NEXT:    rlwinm 3, 3, 0, 31, 31
518; ALL-NEXT:    subfic 3, 3, 5
519; ALL-NEXT:    blr
520  %sel = select i1 %cond, i8 -4, i8 23
521  %bo = and i8 %sel, 5
522  ret i8 %bo
523}
524
525define i8 @sel_constants_or_constant(i1 %cond) {
526; ISEL-LABEL: sel_constants_or_constant:
527; ISEL:       # %bb.0:
528; ISEL-NEXT:    li 4, 0
529; ISEL-NEXT:    andi. 3, 3, 1
530; ISEL-NEXT:    oris 3, 4, 65535
531; ISEL-NEXT:    li 4, 23
532; ISEL-NEXT:    ori 3, 3, 65533
533; ISEL-NEXT:    isel 3, 3, 4, 1
534; ISEL-NEXT:    blr
535;
536; NO_ISEL-LABEL: sel_constants_or_constant:
537; NO_ISEL:       # %bb.0:
538; NO_ISEL-NEXT:    li 4, 0
539; NO_ISEL-NEXT:    andi. 3, 3, 1
540; NO_ISEL-NEXT:    oris 3, 4, 65535
541; NO_ISEL-NEXT:    li 4, 23
542; NO_ISEL-NEXT:    ori 3, 3, 65533
543; NO_ISEL-NEXT:    bclr 12, 1, 0
544; NO_ISEL-NEXT:  # %bb.1:
545; NO_ISEL-NEXT:    ori 3, 4, 0
546; NO_ISEL-NEXT:    blr
547  %sel = select i1 %cond, i8 -4, i8 23
548  %bo = or i8 %sel, 5
549  ret i8 %bo
550}
551
552define i8 @sel_constants_xor_constant(i1 %cond) {
553; ISEL-LABEL: sel_constants_xor_constant:
554; ISEL:       # %bb.0:
555; ISEL-NEXT:    li 4, 0
556; ISEL-NEXT:    andi. 3, 3, 1
557; ISEL-NEXT:    oris 3, 4, 65535
558; ISEL-NEXT:    li 4, 18
559; ISEL-NEXT:    ori 3, 3, 65529
560; ISEL-NEXT:    isel 3, 3, 4, 1
561; ISEL-NEXT:    blr
562;
563; NO_ISEL-LABEL: sel_constants_xor_constant:
564; NO_ISEL:       # %bb.0:
565; NO_ISEL-NEXT:    li 4, 0
566; NO_ISEL-NEXT:    andi. 3, 3, 1
567; NO_ISEL-NEXT:    oris 3, 4, 65535
568; NO_ISEL-NEXT:    li 4, 18
569; NO_ISEL-NEXT:    ori 3, 3, 65529
570; NO_ISEL-NEXT:    bclr 12, 1, 0
571; NO_ISEL-NEXT:  # %bb.1:
572; NO_ISEL-NEXT:    ori 3, 4, 0
573; NO_ISEL-NEXT:    blr
574  %sel = select i1 %cond, i8 -4, i8 23
575  %bo = xor i8 %sel, 5
576  ret i8 %bo
577}
578
579define i8 @sel_constants_shl_constant(i1 %cond) {
580; ISEL-LABEL: sel_constants_shl_constant:
581; ISEL:       # %bb.0:
582; ISEL-NEXT:    lis 5, 511
583; ISEL-NEXT:    lis 4, 2047
584; ISEL-NEXT:    andi. 3, 3, 1
585; ISEL-NEXT:    ori 3, 4, 65535
586; ISEL-NEXT:    ori 12, 5, 65535
587; ISEL-NEXT:    sldi 3, 3, 5
588; ISEL-NEXT:    sldi 4, 12, 7
589; ISEL-NEXT:    isel 3, 4, 3, 1
590; ISEL-NEXT:    blr
591;
592; NO_ISEL-LABEL: sel_constants_shl_constant:
593; NO_ISEL:       # %bb.0:
594; NO_ISEL-NEXT:    lis 5, 511
595; NO_ISEL-NEXT:    lis 4, 2047
596; NO_ISEL-NEXT:    andi. 3, 3, 1
597; NO_ISEL-NEXT:    ori 3, 4, 65535
598; NO_ISEL-NEXT:    ori 12, 5, 65535
599; NO_ISEL-NEXT:    sldi 3, 3, 5
600; NO_ISEL-NEXT:    sldi 4, 12, 7
601; NO_ISEL-NEXT:    bc 12, 1, .LBB31_1
602; NO_ISEL-NEXT:    blr
603; NO_ISEL-NEXT:  .LBB31_1:
604; NO_ISEL-NEXT:    addi 3, 4, 0
605; NO_ISEL-NEXT:    blr
606  %sel = select i1 %cond, i8 -4, i8 23
607  %bo = shl i8 %sel, 5
608  ret i8 %bo
609}
610
611define i8 @sel_constants_lshr_constant(i1 %cond) {
612; ISEL-LABEL: sel_constants_lshr_constant:
613; ISEL:       # %bb.0:
614; ISEL-NEXT:    andi. 3, 3, 1
615; ISEL-NEXT:    li 4, 7
616; ISEL-NEXT:    li 3, 0
617; ISEL-NEXT:    isel 3, 4, 3, 1
618; ISEL-NEXT:    blr
619;
620; NO_ISEL-LABEL: sel_constants_lshr_constant:
621; NO_ISEL:       # %bb.0:
622; NO_ISEL-NEXT:    andi. 3, 3, 1
623; NO_ISEL-NEXT:    li 4, 7
624; NO_ISEL-NEXT:    li 3, 0
625; NO_ISEL-NEXT:    bc 12, 1, .LBB32_1
626; NO_ISEL-NEXT:    blr
627; NO_ISEL-NEXT:  .LBB32_1:
628; NO_ISEL-NEXT:    addi 3, 4, 0
629; NO_ISEL-NEXT:    blr
630  %sel = select i1 %cond, i8 -4, i8 23
631  %bo = lshr i8 %sel, 5
632  ret i8 %bo
633}
634
635define i8 @sel_constants_ashr_constant(i1 %cond) {
636; ALL-LABEL: sel_constants_ashr_constant:
637; ALL:       # %bb.0:
638; ALL-NEXT:    clrldi 3, 3, 63
639; ALL-NEXT:    neg 3, 3
640; ALL-NEXT:    blr
641  %sel = select i1 %cond, i8 -4, i8 23
642  %bo = ashr i8 %sel, 5
643  ret i8 %bo
644}
645
646define double @sel_constants_fadd_constant(i1 %cond) {
647; ISEL-LABEL: sel_constants_fadd_constant:
648; ISEL:       # %bb.0:
649; ISEL-NEXT:    andi. 3, 3, 1
650; ISEL-NEXT:    addis 4, 2, .LCPI34_0@toc@ha
651; ISEL-NEXT:    addis 3, 2, .LCPI34_1@toc@ha
652; ISEL-NEXT:    addi 4, 4, .LCPI34_0@toc@l
653; ISEL-NEXT:    addi 3, 3, .LCPI34_1@toc@l
654; ISEL-NEXT:    isel 3, 3, 4, 1
655; ISEL-NEXT:    lxsdx 1, 0, 3
656; ISEL-NEXT:    blr
657;
658; NO_ISEL-LABEL: sel_constants_fadd_constant:
659; NO_ISEL:       # %bb.0:
660; NO_ISEL-NEXT:    andi. 3, 3, 1
661; NO_ISEL-NEXT:    addis 4, 2, .LCPI34_0@toc@ha
662; NO_ISEL-NEXT:    addis 3, 2, .LCPI34_1@toc@ha
663; NO_ISEL-NEXT:    addi 4, 4, .LCPI34_0@toc@l
664; NO_ISEL-NEXT:    addi 3, 3, .LCPI34_1@toc@l
665; NO_ISEL-NEXT:    bc 12, 1, .LBB34_2
666; NO_ISEL-NEXT:  # %bb.1:
667; NO_ISEL-NEXT:    ori 3, 4, 0
668; NO_ISEL-NEXT:    b .LBB34_2
669; NO_ISEL-NEXT:  .LBB34_2:
670; NO_ISEL-NEXT:    lxsdx 1, 0, 3
671; NO_ISEL-NEXT:    blr
672  %sel = select i1 %cond, double -4.0, double 23.3
673  %bo = fadd double %sel, 5.1
674  ret double %bo
675}
676
677define double @sel_constants_fsub_constant(i1 %cond) {
678; ISEL-LABEL: sel_constants_fsub_constant:
679; ISEL:       # %bb.0:
680; ISEL-NEXT:    andi. 3, 3, 1
681; ISEL-NEXT:    addis 4, 2, .LCPI35_0@toc@ha
682; ISEL-NEXT:    addis 3, 2, .LCPI35_1@toc@ha
683; ISEL-NEXT:    addi 4, 4, .LCPI35_0@toc@l
684; ISEL-NEXT:    addi 3, 3, .LCPI35_1@toc@l
685; ISEL-NEXT:    isel 3, 3, 4, 1
686; ISEL-NEXT:    lxsdx 1, 0, 3
687; ISEL-NEXT:    blr
688;
689; NO_ISEL-LABEL: sel_constants_fsub_constant:
690; NO_ISEL:       # %bb.0:
691; NO_ISEL-NEXT:    andi. 3, 3, 1
692; NO_ISEL-NEXT:    addis 4, 2, .LCPI35_0@toc@ha
693; NO_ISEL-NEXT:    addis 3, 2, .LCPI35_1@toc@ha
694; NO_ISEL-NEXT:    addi 4, 4, .LCPI35_0@toc@l
695; NO_ISEL-NEXT:    addi 3, 3, .LCPI35_1@toc@l
696; NO_ISEL-NEXT:    bc 12, 1, .LBB35_2
697; NO_ISEL-NEXT:  # %bb.1:
698; NO_ISEL-NEXT:    ori 3, 4, 0
699; NO_ISEL-NEXT:    b .LBB35_2
700; NO_ISEL-NEXT:  .LBB35_2:
701; NO_ISEL-NEXT:    lxsdx 1, 0, 3
702; NO_ISEL-NEXT:    blr
703  %sel = select i1 %cond, double -4.0, double 23.3
704  %bo = fsub double %sel, 5.1
705  ret double %bo
706}
707
708define double @sel_constants_fmul_constant(i1 %cond) {
709; ISEL-LABEL: sel_constants_fmul_constant:
710; ISEL:       # %bb.0:
711; ISEL-NEXT:    andi. 3, 3, 1
712; ISEL-NEXT:    addis 4, 2, .LCPI36_0@toc@ha
713; ISEL-NEXT:    addis 3, 2, .LCPI36_1@toc@ha
714; ISEL-NEXT:    addi 4, 4, .LCPI36_0@toc@l
715; ISEL-NEXT:    addi 3, 3, .LCPI36_1@toc@l
716; ISEL-NEXT:    isel 3, 3, 4, 1
717; ISEL-NEXT:    lxsdx 1, 0, 3
718; ISEL-NEXT:    blr
719;
720; NO_ISEL-LABEL: sel_constants_fmul_constant:
721; NO_ISEL:       # %bb.0:
722; NO_ISEL-NEXT:    andi. 3, 3, 1
723; NO_ISEL-NEXT:    addis 4, 2, .LCPI36_0@toc@ha
724; NO_ISEL-NEXT:    addis 3, 2, .LCPI36_1@toc@ha
725; NO_ISEL-NEXT:    addi 4, 4, .LCPI36_0@toc@l
726; NO_ISEL-NEXT:    addi 3, 3, .LCPI36_1@toc@l
727; NO_ISEL-NEXT:    bc 12, 1, .LBB36_2
728; NO_ISEL-NEXT:  # %bb.1:
729; NO_ISEL-NEXT:    ori 3, 4, 0
730; NO_ISEL-NEXT:    b .LBB36_2
731; NO_ISEL-NEXT:  .LBB36_2:
732; NO_ISEL-NEXT:    lxsdx 1, 0, 3
733; NO_ISEL-NEXT:    blr
734  %sel = select i1 %cond, double -4.0, double 23.3
735  %bo = fmul double %sel, 5.1
736  ret double %bo
737}
738
739define double @sel_constants_fdiv_constant(i1 %cond) {
740; ISEL-LABEL: sel_constants_fdiv_constant:
741; ISEL:       # %bb.0:
742; ISEL-NEXT:    andi. 3, 3, 1
743; ISEL-NEXT:    addis 4, 2, .LCPI37_0@toc@ha
744; ISEL-NEXT:    addis 3, 2, .LCPI37_1@toc@ha
745; ISEL-NEXT:    addi 4, 4, .LCPI37_0@toc@l
746; ISEL-NEXT:    addi 3, 3, .LCPI37_1@toc@l
747; ISEL-NEXT:    isel 3, 3, 4, 1
748; ISEL-NEXT:    lxsdx 1, 0, 3
749; ISEL-NEXT:    blr
750;
751; NO_ISEL-LABEL: sel_constants_fdiv_constant:
752; NO_ISEL:       # %bb.0:
753; NO_ISEL-NEXT:    andi. 3, 3, 1
754; NO_ISEL-NEXT:    addis 4, 2, .LCPI37_0@toc@ha
755; NO_ISEL-NEXT:    addis 3, 2, .LCPI37_1@toc@ha
756; NO_ISEL-NEXT:    addi 4, 4, .LCPI37_0@toc@l
757; NO_ISEL-NEXT:    addi 3, 3, .LCPI37_1@toc@l
758; NO_ISEL-NEXT:    bc 12, 1, .LBB37_2
759; NO_ISEL-NEXT:  # %bb.1:
760; NO_ISEL-NEXT:    ori 3, 4, 0
761; NO_ISEL-NEXT:    b .LBB37_2
762; NO_ISEL-NEXT:  .LBB37_2:
763; NO_ISEL-NEXT:    lxsdx 1, 0, 3
764; NO_ISEL-NEXT:    blr
765  %sel = select i1 %cond, double -4.0, double 23.3
766  %bo = fdiv double %sel, 5.1
767  ret double %bo
768}
769
770define double @sel_constants_frem_constant(i1 %cond) {
771; ALL-LABEL: sel_constants_frem_constant:
772; ALL:       # %bb.0:
773; ALL-NEXT:    andi. 3, 3, 1
774; ALL-NEXT:    bc 12, 1, .LBB38_2
775; ALL-NEXT:  # %bb.1:
776; ALL-NEXT:    addis 3, 2, .LCPI38_0@toc@ha
777; ALL-NEXT:    addi 3, 3, .LCPI38_0@toc@l
778; ALL-NEXT:    lxsdx 1, 0, 3
779; ALL-NEXT:    blr
780; ALL-NEXT:  .LBB38_2:
781; ALL-NEXT:    addis 3, 2, .LCPI38_1@toc@ha
782; ALL-NEXT:    addi 3, 3, .LCPI38_1@toc@l
783; ALL-NEXT:    lfsx 1, 0, 3
784; ALL-NEXT:    blr
785  %sel = select i1 %cond, double -4.0, double 23.3
786  %bo = frem double %sel, 5.1
787  ret double %bo
788}
789
790