xref: /llvm-project/llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/select.ll (revision 373c343a77a7afaa07179db1754a52b620dfaf2e)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc  -O0 -mtriple=mipsel-linux-gnu -global-isel  -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32
3
4define i8 @select_i8(i1 %test, i8 %a, i8 %b) {
5; MIPS32-LABEL: select_i8:
6; MIPS32:       # %bb.0: # %entry
7; MIPS32-NEXT:    move $2, $6
8; MIPS32-NEXT:    andi $1, $4, 1
9; MIPS32-NEXT:    movn $2, $5, $1
10; MIPS32-NEXT:    jr $ra
11; MIPS32-NEXT:    nop
12entry:
13  %cond = select i1 %test, i8 %a, i8 %b
14  ret i8 %cond
15}
16
17define i16 @select_i16(i1 %test, i16 %a, i16 %b) {
18; MIPS32-LABEL: select_i16:
19; MIPS32:       # %bb.0: # %entry
20; MIPS32-NEXT:    move $2, $6
21; MIPS32-NEXT:    andi $1, $4, 1
22; MIPS32-NEXT:    movn $2, $5, $1
23; MIPS32-NEXT:    jr $ra
24; MIPS32-NEXT:    nop
25entry:
26  %cond = select i1 %test, i16 %a, i16 %b
27  ret i16 %cond
28}
29
30define i32 @select_i32(i1 %test, i32 %a, i32 %b) {
31; MIPS32-LABEL: select_i32:
32; MIPS32:       # %bb.0: # %entry
33; MIPS32-NEXT:    move $2, $6
34; MIPS32-NEXT:    andi $1, $4, 1
35; MIPS32-NEXT:    movn $2, $5, $1
36; MIPS32-NEXT:    jr $ra
37; MIPS32-NEXT:    nop
38entry:
39  %cond = select i1 %test, i32 %a, i32 %b
40  ret i32 %cond
41}
42
43define ptr @select_ptr(i1 %test, ptr %a, ptr %b) {
44; MIPS32-LABEL: select_ptr:
45; MIPS32:       # %bb.0: # %entry
46; MIPS32-NEXT:    move $2, $6
47; MIPS32-NEXT:    andi $1, $4, 1
48; MIPS32-NEXT:    movn $2, $5, $1
49; MIPS32-NEXT:    jr $ra
50; MIPS32-NEXT:    nop
51entry:
52  %cond = select i1 %test, ptr %a, ptr %b
53  ret ptr %cond
54}
55
56define i32 @select_with_negation(i32 %a, i32 %b, i32 %x, i32 %y) {
57; MIPS32-LABEL: select_with_negation:
58; MIPS32:       # %bb.0: # %entry
59; MIPS32-NEXT:    move $2, $7
60; MIPS32-NEXT:    slt $1, $4, $5
61; MIPS32-NEXT:    xori $1, $1, 1
62; MIPS32-NEXT:    movn $2, $6, $1
63; MIPS32-NEXT:    jr $ra
64; MIPS32-NEXT:    nop
65entry:
66  %cmp = icmp slt i32 %a, %b
67  %lneg = xor i1 %cmp, true
68  %cond = select i1 %lneg, i32 %x, i32 %y
69  ret i32 %cond
70}
71
72define i64 @select_i64(i1 %test, i64 %a, i64 %b) {
73; MIPS32-LABEL: select_i64:
74; MIPS32:       # %bb.0: # %entry
75; MIPS32-NEXT:    addiu $1, $sp, 16
76; MIPS32-NEXT:    lw $2, 0($1)
77; MIPS32-NEXT:    addiu $1, $sp, 20
78; MIPS32-NEXT:    lw $3, 0($1)
79; MIPS32-NEXT:    andi $1, $4, 1
80; MIPS32-NEXT:    movn $2, $6, $1
81; MIPS32-NEXT:    movn $3, $7, $1
82; MIPS32-NEXT:    jr $ra
83; MIPS32-NEXT:    nop
84entry:
85  %cond = select i1 %test, i64 %a, i64 %b
86  ret i64 %cond
87}
88
89define void @select_ambiguous_i64_in_fpr(i1 %test, ptr %i64_ptr_a, ptr %i64_ptr_b, ptr %i64_ptr_c) {
90; MIPS32-LABEL: select_ambiguous_i64_in_fpr:
91; MIPS32:       # %bb.0: # %entry
92; MIPS32-NEXT:    ldc1 $f2, 0($5)
93; MIPS32-NEXT:    ldc1 $f0, 0($6)
94; MIPS32-NEXT:    andi $1, $4, 1
95; MIPS32-NEXT:    movn.d $f0, $f2, $1
96; MIPS32-NEXT:    sdc1 $f0, 0($7)
97; MIPS32-NEXT:    jr $ra
98; MIPS32-NEXT:    nop
99entry:
100  %0 = load i64, ptr %i64_ptr_a, align 8
101  %1 = load i64, ptr %i64_ptr_b, align 8
102  %cond = select i1 %test, i64 %0, i64 %1
103  store i64 %cond, ptr %i64_ptr_c, align 8
104  ret void
105}
106
107define float @select_float(i1 %test, float %a, float %b) {
108; MIPS32-LABEL: select_float:
109; MIPS32:       # %bb.0: # %entry
110; MIPS32-NEXT:    andi $1, $4, 1
111; MIPS32-NEXT:    mtc1 $5, $f1
112; MIPS32-NEXT:    mtc1 $6, $f0
113; MIPS32-NEXT:    movn.s $f0, $f1, $1
114; MIPS32-NEXT:    jr $ra
115; MIPS32-NEXT:    nop
116entry:
117  %cond = select i1 %test, float %a, float %b
118  ret float %cond
119}
120
121define void @select_ambiguous_float_in_gpr(i1 %test, ptr %f32_ptr_a, ptr %f32_ptr_b, ptr %f32_ptr_c) {
122; MIPS32-LABEL: select_ambiguous_float_in_gpr:
123; MIPS32:       # %bb.0: # %entry
124; MIPS32-NEXT:    lw $2, 0($5)
125; MIPS32-NEXT:    lw $1, 0($6)
126; MIPS32-NEXT:    andi $3, $4, 1
127; MIPS32-NEXT:    movn $1, $2, $3
128; MIPS32-NEXT:    sw $1, 0($7)
129; MIPS32-NEXT:    jr $ra
130; MIPS32-NEXT:    nop
131entry:
132  %0 = load float, ptr %f32_ptr_a, align 4
133  %1 = load float, ptr %f32_ptr_b, align 4
134  %cond = select i1 %test, float %0, float %1
135  store float %cond, ptr %f32_ptr_c, align 4
136  ret void
137}
138
139define double @select_double(double %a, double %b, i1 %test) {
140; MIPS32-LABEL: select_double:
141; MIPS32:       # %bb.0: # %entry
142; MIPS32-NEXT:    mov.d $f0, $f14
143; MIPS32-NEXT:    addiu $1, $sp, 16
144; MIPS32-NEXT:    lw $1, 0($1)
145; MIPS32-NEXT:    andi $1, $1, 1
146; MIPS32-NEXT:    movn.d $f0, $f12, $1
147; MIPS32-NEXT:    jr $ra
148; MIPS32-NEXT:    nop
149entry:
150  %cond = select i1 %test, double %a, double %b
151  ret double %cond
152}
153