|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: llc < %s -mtriple=mipsel-unknown-linux-gnu -O3 | FileCheck %s --check-prefix=M32 |
| 3 | +; RUN: llc < %s -mtriple=mips64el-unknown-linux-gnu -O3 | FileCheck %s --check-prefix=M64 |
| 4 | + |
| 5 | +; Portable edge case tests |
| 6 | + |
| 7 | +; Test with small integer types |
| 8 | +define i1 @test_ctselect_i1(i1 %cond, i1 %a, i1 %b) { |
| 9 | +; M32-LABEL: test_ctselect_i1: |
| 10 | +; M32: # %bb.0: |
| 11 | +; M32-NEXT: xori $2, $4, 1 |
| 12 | +; M32-NEXT: and $1, $4, $5 |
| 13 | +; M32-NEXT: and $2, $2, $6 |
| 14 | +; M32-NEXT: jr $ra |
| 15 | +; M32-NEXT: or $2, $1, $2 |
| 16 | +; |
| 17 | +; M64-LABEL: test_ctselect_i1: |
| 18 | +; M64: # %bb.0: |
| 19 | +; M64-NEXT: sll $2, $4, 0 |
| 20 | +; M64-NEXT: sll $1, $6, 0 |
| 21 | +; M64-NEXT: xori $2, $2, 1 |
| 22 | +; M64-NEXT: and $1, $2, $1 |
| 23 | +; M64-NEXT: and $2, $4, $5 |
| 24 | +; M64-NEXT: sll $2, $2, 0 |
| 25 | +; M64-NEXT: jr $ra |
| 26 | +; M64-NEXT: or $2, $2, $1 |
| 27 | + %result = call i1 @llvm.ct.select.i1(i1 %cond, i1 %a, i1 %b) |
| 28 | + ret i1 %result |
| 29 | +} |
| 30 | + |
| 31 | +; Test with extremal values |
| 32 | +define i32 @test_ctselect_extremal_values(i1 %cond) { |
| 33 | +; M32-LABEL: test_ctselect_extremal_values: |
| 34 | +; M32: # %bb.0: |
| 35 | +; M32-NEXT: lui $3, 32767 |
| 36 | +; M32-NEXT: andi $1, $4, 1 |
| 37 | +; M32-NEXT: negu $2, $1 |
| 38 | +; M32-NEXT: ori $3, $3, 65535 |
| 39 | +; M32-NEXT: addiu $1, $1, -1 |
| 40 | +; M32-NEXT: and $2, $2, $3 |
| 41 | +; M32-NEXT: lui $3, 32768 |
| 42 | +; M32-NEXT: and $1, $1, $3 |
| 43 | +; M32-NEXT: jr $ra |
| 44 | +; M32-NEXT: or $2, $2, $1 |
| 45 | +; |
| 46 | +; M64-LABEL: test_ctselect_extremal_values: |
| 47 | +; M64: # %bb.0: |
| 48 | +; M64-NEXT: sll $1, $4, 0 |
| 49 | +; M64-NEXT: lui $3, 32767 |
| 50 | +; M64-NEXT: andi $1, $1, 1 |
| 51 | +; M64-NEXT: ori $3, $3, 65535 |
| 52 | +; M64-NEXT: negu $2, $1 |
| 53 | +; M64-NEXT: addiu $1, $1, -1 |
| 54 | +; M64-NEXT: and $2, $2, $3 |
| 55 | +; M64-NEXT: lui $3, 32768 |
| 56 | +; M64-NEXT: and $1, $1, $3 |
| 57 | +; M64-NEXT: jr $ra |
| 58 | +; M64-NEXT: or $2, $2, $1 |
| 59 | + %result = call i32 @llvm.ct.select.i32(i1 %cond, i32 2147483647, i32 -2147483648) |
| 60 | + ret i32 %result |
| 61 | +} |
| 62 | + |
| 63 | +; Test with null pointers |
| 64 | +define ptr @test_ctselect_null_ptr(i1 %cond, ptr %ptr) { |
| 65 | +; M32-LABEL: test_ctselect_null_ptr: |
| 66 | +; M32: # %bb.0: |
| 67 | +; M32-NEXT: andi $1, $4, 1 |
| 68 | +; M32-NEXT: negu $1, $1 |
| 69 | +; M32-NEXT: jr $ra |
| 70 | +; M32-NEXT: and $2, $1, $5 |
| 71 | +; |
| 72 | +; M64-LABEL: test_ctselect_null_ptr: |
| 73 | +; M64: # %bb.0: |
| 74 | +; M64-NEXT: andi $1, $4, 1 |
| 75 | +; M64-NEXT: dnegu $1, $1 |
| 76 | +; M64-NEXT: jr $ra |
| 77 | +; M64-NEXT: and $2, $1, $5 |
| 78 | + %result = call ptr @llvm.ct.select.p0(i1 %cond, ptr %ptr, ptr null) |
| 79 | + ret ptr %result |
| 80 | +} |
| 81 | + |
| 82 | +; Test with function pointers |
| 83 | +define ptr @test_ctselect_function_ptr(i1 %cond, ptr %func1, ptr %func2) { |
| 84 | +; M32-LABEL: test_ctselect_function_ptr: |
| 85 | +; M32: # %bb.0: |
| 86 | +; M32-NEXT: andi $1, $4, 1 |
| 87 | +; M32-NEXT: negu $2, $1 |
| 88 | +; M32-NEXT: addiu $1, $1, -1 |
| 89 | +; M32-NEXT: and $2, $2, $5 |
| 90 | +; M32-NEXT: and $1, $1, $6 |
| 91 | +; M32-NEXT: jr $ra |
| 92 | +; M32-NEXT: or $2, $2, $1 |
| 93 | +; |
| 94 | +; M64-LABEL: test_ctselect_function_ptr: |
| 95 | +; M64: # %bb.0: |
| 96 | +; M64-NEXT: andi $1, $4, 1 |
| 97 | +; M64-NEXT: dnegu $2, $1 |
| 98 | +; M64-NEXT: daddiu $1, $1, -1 |
| 99 | +; M64-NEXT: and $2, $2, $5 |
| 100 | +; M64-NEXT: and $1, $1, $6 |
| 101 | +; M64-NEXT: jr $ra |
| 102 | +; M64-NEXT: or $2, $2, $1 |
| 103 | + %result = call ptr @llvm.ct.select.p0(i1 %cond, ptr %func1, ptr %func2) |
| 104 | + ret ptr %result |
| 105 | +} |
| 106 | + |
| 107 | +; Test with condition from icmp on pointers |
| 108 | +define ptr @test_ctselect_ptr_cmp(ptr %p1, ptr %p2, ptr %a, ptr %b) { |
| 109 | +; M32-LABEL: test_ctselect_ptr_cmp: |
| 110 | +; M32: # %bb.0: |
| 111 | +; M32-NEXT: xor $1, $4, $5 |
| 112 | +; M32-NEXT: sltu $1, $zero, $1 |
| 113 | +; M32-NEXT: addiu $1, $1, -1 |
| 114 | +; M32-NEXT: and $2, $1, $6 |
| 115 | +; M32-NEXT: not $1, $1 |
| 116 | +; M32-NEXT: and $1, $1, $7 |
| 117 | +; M32-NEXT: jr $ra |
| 118 | +; M32-NEXT: or $2, $2, $1 |
| 119 | +; |
| 120 | +; M64-LABEL: test_ctselect_ptr_cmp: |
| 121 | +; M64: # %bb.0: |
| 122 | +; M64-NEXT: xor $1, $4, $5 |
| 123 | +; M64-NEXT: daddiu $3, $zero, -1 |
| 124 | +; M64-NEXT: daddiu $2, $zero, -1 |
| 125 | +; M64-NEXT: movn $3, $zero, $1 |
| 126 | +; M64-NEXT: xor $2, $3, $2 |
| 127 | +; M64-NEXT: and $1, $3, $6 |
| 128 | +; M64-NEXT: and $2, $2, $7 |
| 129 | +; M64-NEXT: jr $ra |
| 130 | +; M64-NEXT: or $2, $1, $2 |
| 131 | + %cmp = icmp eq ptr %p1, %p2 |
| 132 | + %result = call ptr @llvm.ct.select.p0(i1 %cmp, ptr %a, ptr %b) |
| 133 | + ret ptr %result |
| 134 | +} |
| 135 | + |
| 136 | +; Test with struct pointer types |
| 137 | +%struct.pair = type { i32, i32 } |
| 138 | + |
| 139 | +define ptr @test_ctselect_struct_ptr(i1 %cond, ptr %a, ptr %b) { |
| 140 | +; M32-LABEL: test_ctselect_struct_ptr: |
| 141 | +; M32: # %bb.0: |
| 142 | +; M32-NEXT: andi $1, $4, 1 |
| 143 | +; M32-NEXT: negu $2, $1 |
| 144 | +; M32-NEXT: addiu $1, $1, -1 |
| 145 | +; M32-NEXT: and $2, $2, $5 |
| 146 | +; M32-NEXT: and $1, $1, $6 |
| 147 | +; M32-NEXT: jr $ra |
| 148 | +; M32-NEXT: or $2, $2, $1 |
| 149 | +; |
| 150 | +; M64-LABEL: test_ctselect_struct_ptr: |
| 151 | +; M64: # %bb.0: |
| 152 | +; M64-NEXT: andi $1, $4, 1 |
| 153 | +; M64-NEXT: dnegu $2, $1 |
| 154 | +; M64-NEXT: daddiu $1, $1, -1 |
| 155 | +; M64-NEXT: and $2, $2, $5 |
| 156 | +; M64-NEXT: and $1, $1, $6 |
| 157 | +; M64-NEXT: jr $ra |
| 158 | +; M64-NEXT: or $2, $2, $1 |
| 159 | + %result = call ptr @llvm.ct.select.p0(i1 %cond, ptr %a, ptr %b) |
| 160 | + ret ptr %result |
| 161 | +} |
| 162 | + |
| 163 | +; Test with deeply nested conditions |
| 164 | +define i32 @test_ctselect_deeply_nested(i1 %c1, i1 %c2, i1 %c3, i1 %c4, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { |
| 165 | +; M32-LABEL: test_ctselect_deeply_nested: |
| 166 | +; M32: # %bb.0: |
| 167 | +; M32-NEXT: andi $1, $4, 1 |
| 168 | +; M32-NEXT: lw $3, 16($sp) |
| 169 | +; M32-NEXT: lw $9, 32($sp) |
| 170 | +; M32-NEXT: lw $8, 28($sp) |
| 171 | +; M32-NEXT: negu $2, $1 |
| 172 | +; M32-NEXT: addiu $1, $1, -1 |
| 173 | +; M32-NEXT: and $2, $2, $3 |
| 174 | +; M32-NEXT: lw $3, 20($sp) |
| 175 | +; M32-NEXT: and $1, $1, $3 |
| 176 | +; M32-NEXT: andi $3, $5, 1 |
| 177 | +; M32-NEXT: or $1, $2, $1 |
| 178 | +; M32-NEXT: andi $2, $6, 1 |
| 179 | +; M32-NEXT: andi $6, $7, 1 |
| 180 | +; M32-NEXT: negu $4, $3 |
| 181 | +; M32-NEXT: addiu $3, $3, -1 |
| 182 | +; M32-NEXT: addiu $7, $6, -1 |
| 183 | +; M32-NEXT: and $1, $4, $1 |
| 184 | +; M32-NEXT: addiu $5, $2, -1 |
| 185 | +; M32-NEXT: negu $2, $2 |
| 186 | +; M32-NEXT: negu $6, $6 |
| 187 | +; M32-NEXT: and $4, $7, $9 |
| 188 | +; M32-NEXT: lw $7, 24($sp) |
| 189 | +; M32-NEXT: and $5, $5, $8 |
| 190 | +; M32-NEXT: and $3, $3, $7 |
| 191 | +; M32-NEXT: or $1, $1, $3 |
| 192 | +; M32-NEXT: and $1, $2, $1 |
| 193 | +; M32-NEXT: or $1, $1, $5 |
| 194 | +; M32-NEXT: and $1, $6, $1 |
| 195 | +; M32-NEXT: jr $ra |
| 196 | +; M32-NEXT: or $2, $1, $4 |
| 197 | +; |
| 198 | +; M64-LABEL: test_ctselect_deeply_nested: |
| 199 | +; M64: # %bb.0: |
| 200 | +; M64-NEXT: sll $1, $4, 0 |
| 201 | +; M64-NEXT: sll $3, $8, 0 |
| 202 | +; M64-NEXT: sll $4, $5, 0 |
| 203 | +; M64-NEXT: lw $8, 0($sp) |
| 204 | +; M64-NEXT: andi $1, $1, 1 |
| 205 | +; M64-NEXT: andi $4, $4, 1 |
| 206 | +; M64-NEXT: negu $2, $1 |
| 207 | +; M64-NEXT: addiu $1, $1, -1 |
| 208 | +; M64-NEXT: negu $5, $4 |
| 209 | +; M64-NEXT: addiu $4, $4, -1 |
| 210 | +; M64-NEXT: and $2, $2, $3 |
| 211 | +; M64-NEXT: sll $3, $9, 0 |
| 212 | +; M64-NEXT: and $1, $1, $3 |
| 213 | +; M64-NEXT: sll $3, $11, 0 |
| 214 | +; M64-NEXT: or $1, $2, $1 |
| 215 | +; M64-NEXT: sll $2, $6, 0 |
| 216 | +; M64-NEXT: sll $6, $7, 0 |
| 217 | +; M64-NEXT: andi $2, $2, 1 |
| 218 | +; M64-NEXT: and $1, $5, $1 |
| 219 | +; M64-NEXT: andi $6, $6, 1 |
| 220 | +; M64-NEXT: addiu $5, $2, -1 |
| 221 | +; M64-NEXT: negu $2, $2 |
| 222 | +; M64-NEXT: addiu $7, $6, -1 |
| 223 | +; M64-NEXT: negu $6, $6 |
| 224 | +; M64-NEXT: and $3, $5, $3 |
| 225 | +; M64-NEXT: sll $5, $10, 0 |
| 226 | +; M64-NEXT: and $7, $7, $8 |
| 227 | +; M64-NEXT: and $4, $4, $5 |
| 228 | +; M64-NEXT: or $1, $1, $4 |
| 229 | +; M64-NEXT: and $1, $2, $1 |
| 230 | +; M64-NEXT: or $1, $1, $3 |
| 231 | +; M64-NEXT: and $1, $6, $1 |
| 232 | +; M64-NEXT: jr $ra |
| 233 | +; M64-NEXT: or $2, $1, $7 |
| 234 | + %sel1 = call i32 @llvm.ct.select.i32(i1 %c1, i32 %a, i32 %b) |
| 235 | + %sel2 = call i32 @llvm.ct.select.i32(i1 %c2, i32 %sel1, i32 %c) |
| 236 | + %sel3 = call i32 @llvm.ct.select.i32(i1 %c3, i32 %sel2, i32 %d) |
| 237 | + %sel4 = call i32 @llvm.ct.select.i32(i1 %c4, i32 %sel3, i32 %e) |
| 238 | + ret i32 %sel4 |
| 239 | +} |
| 240 | + |
| 241 | +; Declare the intrinsics |
| 242 | +declare i1 @llvm.ct.select.i1(i1, i1, i1) |
| 243 | +declare i32 @llvm.ct.select.i32(i1, i32, i32) |
| 244 | +declare ptr @llvm.ct.select.p0(i1, ptr, ptr) |
0 commit comments