Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 1 | //===---------------------------------------------------------------------===// |
| 2 | // Random ideas for the X86 backend. |
| 3 | //===---------------------------------------------------------------------===// |
| 4 | |
| 5 | Add a MUL2U and MUL2S nodes to represent a multiply that returns both the |
| 6 | Hi and Lo parts (combination of MUL and MULH[SU] into one node). Add this to |
| 7 | X86, & make the dag combiner produce it when needed. This will eliminate one |
| 8 | imul from the code generated for: |
| 9 | |
| 10 | long long test(long long X, long long Y) { return X*Y; } |
| 11 | |
| 12 | by using the EAX result from the mul. We should add a similar node for |
| 13 | DIVREM. |
| 14 | |
Chris Lattner | 865874c | 2005-12-02 00:11:20 +0000 | [diff] [blame] | 15 | another case is: |
| 16 | |
| 17 | long long test(int X, int Y) { return (long long)X*Y; } |
| 18 | |
| 19 | ... which should only be one imul instruction. |
| 20 | |
Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 21 | //===---------------------------------------------------------------------===// |
| 22 | |
| 23 | This should be one DIV/IDIV instruction, not a libcall: |
| 24 | |
| 25 | unsigned test(unsigned long long X, unsigned Y) { |
| 26 | return X/Y; |
| 27 | } |
| 28 | |
| 29 | This can be done trivially with a custom legalizer. What about overflow |
| 30 | though? http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224 |
| 31 | |
| 32 | //===---------------------------------------------------------------------===// |
| 33 | |
Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 34 | Some targets (e.g. athlons) prefer freep to fstp ST(0): |
| 35 | http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00659.html |
| 36 | |
| 37 | //===---------------------------------------------------------------------===// |
| 38 | |
Evan Cheng | a3195e8 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 39 | This should use fiadd on chips where it is profitable: |
Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 40 | double foo(double P, int *I) { return P+*I; } |
| 41 | |
Evan Cheng | 755ee8f | 2006-02-20 19:58:27 +0000 | [diff] [blame] | 42 | We have fiadd patterns now but the followings have the same cost and |
| 43 | complexity. We need a way to specify the later is more profitable. |
| 44 | |
| 45 | def FpADD32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW, |
| 46 | [(set RFP:$dst, (fadd RFP:$src1, |
| 47 | (extloadf64f32 addr:$src2)))]>; |
| 48 | // ST(0) = ST(0) + [mem32] |
| 49 | |
| 50 | def FpIADD32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW, |
| 51 | [(set RFP:$dst, (fadd RFP:$src1, |
| 52 | (X86fild addr:$src2, i32)))]>; |
| 53 | // ST(0) = ST(0) + [mem32int] |
| 54 | |
Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 55 | //===---------------------------------------------------------------------===// |
| 56 | |
| 57 | The FP stackifier needs to be global. Also, it should handle simple permutates |
| 58 | to reduce number of shuffle instructions, e.g. turning: |
| 59 | |
| 60 | fld P -> fld Q |
| 61 | fld Q fld P |
| 62 | fxch |
| 63 | |
| 64 | or: |
| 65 | |
| 66 | fxch -> fucomi |
| 67 | fucomi jl X |
| 68 | jg X |
| 69 | |
Chris Lattner | 1db4b4f | 2006-01-16 17:53:00 +0000 | [diff] [blame] | 70 | Ideas: |
| 71 | http://gcc.gnu.org/ml/gcc-patches/2004-11/msg02410.html |
| 72 | |
| 73 | |
Chris Lattner | 1171ff4 | 2005-10-23 19:52:42 +0000 | [diff] [blame] | 74 | //===---------------------------------------------------------------------===// |
| 75 | |
| 76 | Improvements to the multiply -> shift/add algorithm: |
| 77 | http://gcc.gnu.org/ml/gcc-patches/2004-08/msg01590.html |
| 78 | |
| 79 | //===---------------------------------------------------------------------===// |
| 80 | |
| 81 | Improve code like this (occurs fairly frequently, e.g. in LLVM): |
| 82 | long long foo(int x) { return 1LL << x; } |
| 83 | |
| 84 | http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01109.html |
| 85 | http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01128.html |
| 86 | http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01136.html |
| 87 | |
| 88 | Another useful one would be ~0ULL >> X and ~0ULL << X. |
| 89 | |
Chris Lattner | ffff617 | 2005-10-23 21:44:59 +0000 | [diff] [blame] | 90 | //===---------------------------------------------------------------------===// |
| 91 | |
Chris Lattner | 1e4ed93 | 2005-11-28 04:52:39 +0000 | [diff] [blame] | 92 | Compile this: |
| 93 | _Bool f(_Bool a) { return a!=1; } |
| 94 | |
| 95 | into: |
| 96 | movzbl %dil, %eax |
| 97 | xorl $1, %eax |
| 98 | ret |
Evan Cheng | 8dee8cc | 2005-12-17 01:25:19 +0000 | [diff] [blame] | 99 | |
| 100 | //===---------------------------------------------------------------------===// |
| 101 | |
| 102 | Some isel ideas: |
| 103 | |
| 104 | 1. Dynamic programming based approach when compile time if not an |
| 105 | issue. |
| 106 | 2. Code duplication (addressing mode) during isel. |
| 107 | 3. Other ideas from "Register-Sensitive Selection, Duplication, and |
| 108 | Sequencing of Instructions". |
Chris Lattner | cb29890 | 2006-02-08 07:12:07 +0000 | [diff] [blame] | 109 | 4. Scheduling for reduced register pressure. E.g. "Minimum Register |
| 110 | Instruction Sequence Problem: Revisiting Optimal Code Generation for DAGs" |
| 111 | and other related papers. |
| 112 | http://citeseer.ist.psu.edu/govindarajan01minimum.html |
Evan Cheng | 8dee8cc | 2005-12-17 01:25:19 +0000 | [diff] [blame] | 113 | |
| 114 | //===---------------------------------------------------------------------===// |
| 115 | |
| 116 | Should we promote i16 to i32 to avoid partial register update stalls? |
Evan Cheng | 98abbfb | 2005-12-17 06:54:43 +0000 | [diff] [blame] | 117 | |
| 118 | //===---------------------------------------------------------------------===// |
| 119 | |
| 120 | Leave any_extend as pseudo instruction and hint to register |
| 121 | allocator. Delay codegen until post register allocation. |
Evan Cheng | a3195e8 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 122 | |
| 123 | //===---------------------------------------------------------------------===// |
| 124 | |
| 125 | Add a target specific hook to DAG combiner to handle SINT_TO_FP and |
| 126 | FP_TO_SINT when the source operand is already in memory. |
| 127 | |
| 128 | //===---------------------------------------------------------------------===// |
| 129 | |
Evan Cheng | e08c270 | 2006-01-13 01:20:42 +0000 | [diff] [blame] | 130 | Model X86 EFLAGS as a real register to avoid redudant cmp / test. e.g. |
| 131 | |
| 132 | cmpl $1, %eax |
| 133 | setg %al |
| 134 | testb %al, %al # unnecessary |
| 135 | jne .BB7 |
Chris Lattner | 1db4b4f | 2006-01-16 17:53:00 +0000 | [diff] [blame] | 136 | |
| 137 | //===---------------------------------------------------------------------===// |
| 138 | |
| 139 | Count leading zeros and count trailing zeros: |
| 140 | |
| 141 | int clz(int X) { return __builtin_clz(X); } |
| 142 | int ctz(int X) { return __builtin_ctz(X); } |
| 143 | |
| 144 | $ gcc t.c -S -o - -O3 -fomit-frame-pointer -masm=intel |
| 145 | clz: |
| 146 | bsr %eax, DWORD PTR [%esp+4] |
| 147 | xor %eax, 31 |
| 148 | ret |
| 149 | ctz: |
| 150 | bsf %eax, DWORD PTR [%esp+4] |
| 151 | ret |
| 152 | |
| 153 | however, check that these are defined for 0 and 32. Our intrinsics are, GCC's |
| 154 | aren't. |
| 155 | |
| 156 | //===---------------------------------------------------------------------===// |
| 157 | |
| 158 | Use push/pop instructions in prolog/epilog sequences instead of stores off |
| 159 | ESP (certain code size win, perf win on some [which?] processors). |
Evan Cheng | 53f280a | 2006-02-25 10:04:07 +0000 | [diff] [blame] | 160 | Also, it appears icc use push for parameter passing. Need to investigate. |
Chris Lattner | 1db4b4f | 2006-01-16 17:53:00 +0000 | [diff] [blame] | 161 | |
| 162 | //===---------------------------------------------------------------------===// |
| 163 | |
| 164 | Only use inc/neg/not instructions on processors where they are faster than |
| 165 | add/sub/xor. They are slower on the P4 due to only updating some processor |
| 166 | flags. |
| 167 | |
| 168 | //===---------------------------------------------------------------------===// |
| 169 | |
| 170 | Open code rint,floor,ceil,trunc: |
| 171 | http://gcc.gnu.org/ml/gcc-patches/2004-08/msg02006.html |
| 172 | http://gcc.gnu.org/ml/gcc-patches/2004-08/msg02011.html |
| 173 | |
| 174 | //===---------------------------------------------------------------------===// |
| 175 | |
| 176 | Combine: a = sin(x), b = cos(x) into a,b = sincos(x). |
| 177 | |
Chris Lattner | 8f77b73 | 2006-02-08 06:52:06 +0000 | [diff] [blame] | 178 | Expand these to calls of sin/cos and stores: |
| 179 | double sincos(double x, double *sin, double *cos); |
| 180 | float sincosf(float x, float *sin, float *cos); |
| 181 | long double sincosl(long double x, long double *sin, long double *cos); |
| 182 | |
| 183 | Doing so could allow SROA of the destination pointers. See also: |
| 184 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17687 |
| 185 | |
Evan Cheng | e826a01 | 2006-01-27 22:11:01 +0000 | [diff] [blame] | 186 | //===---------------------------------------------------------------------===// |
| 187 | |
Chris Lattner | b638cd8 | 2006-01-29 09:08:15 +0000 | [diff] [blame] | 188 | The instruction selector sometimes misses folding a load into a compare. The |
| 189 | pattern is written as (cmp reg, (load p)). Because the compare isn't |
| 190 | commutative, it is not matched with the load on both sides. The dag combiner |
| 191 | should be made smart enough to cannonicalize the load into the RHS of a compare |
| 192 | when it can invert the result of the compare for free. |
| 193 | |
Chris Lattner | 6a28456 | 2006-01-29 09:14:47 +0000 | [diff] [blame] | 194 | //===---------------------------------------------------------------------===// |
| 195 | |
Chris Lattner | 5164a31 | 2006-01-29 09:42:20 +0000 | [diff] [blame] | 196 | LSR should be turned on for the X86 backend and tuned to take advantage of its |
| 197 | addressing modes. |
| 198 | |
Chris Lattner | c7097af | 2006-01-29 09:46:06 +0000 | [diff] [blame] | 199 | //===---------------------------------------------------------------------===// |
| 200 | |
| 201 | When compiled with unsafemath enabled, "main" should enable SSE DAZ mode and |
| 202 | other fast SSE modes. |
Chris Lattner | bdde465 | 2006-01-31 00:20:38 +0000 | [diff] [blame] | 203 | |
| 204 | //===---------------------------------------------------------------------===// |
| 205 | |
Chris Lattner | 594086d | 2006-01-31 00:45:37 +0000 | [diff] [blame] | 206 | Think about doing i64 math in SSE regs. |
| 207 | |
Chris Lattner | 8e38ae6 | 2006-01-31 02:10:06 +0000 | [diff] [blame] | 208 | //===---------------------------------------------------------------------===// |
| 209 | |
| 210 | The DAG Isel doesn't fold the loads into the adds in this testcase. The |
| 211 | pattern selector does. This is because the chain value of the load gets |
| 212 | selected first, and the loads aren't checking to see if they are only used by |
| 213 | and add. |
| 214 | |
| 215 | .ll: |
| 216 | |
| 217 | int %test(int* %x, int* %y, int* %z) { |
| 218 | %X = load int* %x |
| 219 | %Y = load int* %y |
| 220 | %Z = load int* %z |
| 221 | %a = add int %X, %Y |
| 222 | %b = add int %a, %Z |
| 223 | ret int %b |
| 224 | } |
| 225 | |
| 226 | dag isel: |
| 227 | |
| 228 | _test: |
| 229 | movl 4(%esp), %eax |
| 230 | movl (%eax), %eax |
| 231 | movl 8(%esp), %ecx |
| 232 | movl (%ecx), %ecx |
| 233 | addl %ecx, %eax |
| 234 | movl 12(%esp), %ecx |
| 235 | movl (%ecx), %ecx |
| 236 | addl %ecx, %eax |
| 237 | ret |
| 238 | |
| 239 | pattern isel: |
| 240 | |
| 241 | _test: |
| 242 | movl 12(%esp), %ecx |
| 243 | movl 4(%esp), %edx |
| 244 | movl 8(%esp), %eax |
| 245 | movl (%eax), %eax |
| 246 | addl (%edx), %eax |
| 247 | addl (%ecx), %eax |
| 248 | ret |
| 249 | |
| 250 | This is bad for register pressure, though the dag isel is producing a |
| 251 | better schedule. :) |
Chris Lattner | 3e1d5e5 | 2006-02-01 01:44:25 +0000 | [diff] [blame] | 252 | |
| 253 | //===---------------------------------------------------------------------===// |
| 254 | |
| 255 | This testcase should have no SSE instructions in it, and only one load from |
| 256 | a constant pool: |
| 257 | |
| 258 | double %test3(bool %B) { |
| 259 | %C = select bool %B, double 123.412, double 523.01123123 |
| 260 | ret double %C |
| 261 | } |
| 262 | |
| 263 | Currently, the select is being lowered, which prevents the dag combiner from |
| 264 | turning 'select (load CPI1), (load CPI2)' -> 'load (select CPI1, CPI2)' |
| 265 | |
| 266 | The pattern isel got this one right. |
| 267 | |
Chris Lattner | 1f7c630 | 2006-02-01 06:40:32 +0000 | [diff] [blame] | 268 | //===---------------------------------------------------------------------===// |
| 269 | |
Chris Lattner | 3e2b94a | 2006-02-01 21:44:48 +0000 | [diff] [blame] | 270 | We need to lower switch statements to tablejumps when appropriate instead of |
| 271 | always into binary branch trees. |
Chris Lattner | 4d7db40 | 2006-02-01 23:38:08 +0000 | [diff] [blame] | 272 | |
| 273 | //===---------------------------------------------------------------------===// |
| 274 | |
| 275 | SSE doesn't have [mem] op= reg instructions. If we have an SSE instruction |
| 276 | like this: |
| 277 | |
| 278 | X += y |
| 279 | |
| 280 | and the register allocator decides to spill X, it is cheaper to emit this as: |
| 281 | |
| 282 | Y += [xslot] |
| 283 | store Y -> [xslot] |
| 284 | |
| 285 | than as: |
| 286 | |
| 287 | tmp = [xslot] |
| 288 | tmp += y |
| 289 | store tmp -> [xslot] |
| 290 | |
| 291 | ..and this uses one fewer register (so this should be done at load folding |
| 292 | time, not at spiller time). *Note* however that this can only be done |
| 293 | if Y is dead. Here's a testcase: |
| 294 | |
| 295 | %.str_3 = external global [15 x sbyte] ; <[15 x sbyte]*> [#uses=0] |
| 296 | implementation ; Functions: |
| 297 | declare void %printf(int, ...) |
| 298 | void %main() { |
| 299 | build_tree.exit: |
| 300 | br label %no_exit.i7 |
| 301 | no_exit.i7: ; preds = %no_exit.i7, %build_tree.exit |
| 302 | %tmp.0.1.0.i9 = phi double [ 0.000000e+00, %build_tree.exit ], [ %tmp.34.i18, %no_exit.i7 ] ; <double> [#uses=1] |
| 303 | %tmp.0.0.0.i10 = phi double [ 0.000000e+00, %build_tree.exit ], [ %tmp.28.i16, %no_exit.i7 ] ; <double> [#uses=1] |
| 304 | %tmp.28.i16 = add double %tmp.0.0.0.i10, 0.000000e+00 |
| 305 | %tmp.34.i18 = add double %tmp.0.1.0.i9, 0.000000e+00 |
| 306 | br bool false, label %Compute_Tree.exit23, label %no_exit.i7 |
| 307 | Compute_Tree.exit23: ; preds = %no_exit.i7 |
| 308 | tail call void (int, ...)* %printf( int 0 ) |
| 309 | store double %tmp.34.i18, double* null |
| 310 | ret void |
| 311 | } |
| 312 | |
| 313 | We currently emit: |
| 314 | |
| 315 | .BBmain_1: |
| 316 | xorpd %XMM1, %XMM1 |
| 317 | addsd %XMM0, %XMM1 |
| 318 | *** movsd %XMM2, QWORD PTR [%ESP + 8] |
| 319 | *** addsd %XMM2, %XMM1 |
| 320 | *** movsd QWORD PTR [%ESP + 8], %XMM2 |
| 321 | jmp .BBmain_1 # no_exit.i7 |
| 322 | |
| 323 | This is a bugpoint reduced testcase, which is why the testcase doesn't make |
| 324 | much sense (e.g. its an infinite loop). :) |
| 325 | |
Evan Cheng | 8b6e4e6 | 2006-02-02 02:40:17 +0000 | [diff] [blame] | 326 | //===---------------------------------------------------------------------===// |
| 327 | |
| 328 | None of the FPStack instructions are handled in |
| 329 | X86RegisterInfo::foldMemoryOperand, which prevents the spiller from |
| 330 | folding spill code into the instructions. |
Chris Lattner | 9acddcd | 2006-02-02 19:16:34 +0000 | [diff] [blame] | 331 | |
| 332 | //===---------------------------------------------------------------------===// |
| 333 | |
| 334 | In many cases, LLVM generates code like this: |
| 335 | |
| 336 | _test: |
| 337 | movl 8(%esp), %eax |
| 338 | cmpl %eax, 4(%esp) |
| 339 | setl %al |
| 340 | movzbl %al, %eax |
| 341 | ret |
| 342 | |
| 343 | on some processors (which ones?), it is more efficient to do this: |
| 344 | |
| 345 | _test: |
| 346 | movl 8(%esp), %ebx |
| 347 | xor %eax, %eax |
| 348 | cmpl %ebx, 4(%esp) |
| 349 | setl %al |
| 350 | ret |
| 351 | |
| 352 | Doing this correctly is tricky though, as the xor clobbers the flags. |
| 353 | |
Chris Lattner | d395d09 | 2006-02-02 19:43:28 +0000 | [diff] [blame] | 354 | //===---------------------------------------------------------------------===// |
| 355 | |
| 356 | We should generate 'test' instead of 'cmp' in various cases, e.g.: |
| 357 | |
| 358 | bool %test(int %X) { |
| 359 | %Y = shl int %X, ubyte 1 |
| 360 | %C = seteq int %Y, 0 |
| 361 | ret bool %C |
| 362 | } |
| 363 | bool %test(int %X) { |
| 364 | %Y = and int %X, 8 |
| 365 | %C = seteq int %Y, 0 |
| 366 | ret bool %C |
| 367 | } |
| 368 | |
| 369 | This may just be a matter of using 'test' to write bigger patterns for X86cmp. |
| 370 | |
| 371 | //===---------------------------------------------------------------------===// |
| 372 | |
Chris Lattner | d395d09 | 2006-02-02 19:43:28 +0000 | [diff] [blame] | 373 | SSE should implement 'select_cc' using 'emulated conditional moves' that use |
| 374 | pcmp/pand/pandn/por to do a selection instead of a conditional branch: |
| 375 | |
| 376 | double %X(double %Y, double %Z, double %A, double %B) { |
| 377 | %C = setlt double %A, %B |
| 378 | %z = add double %Z, 0.0 ;; select operand is not a load |
| 379 | %D = select bool %C, double %Y, double %z |
| 380 | ret double %D |
| 381 | } |
| 382 | |
| 383 | We currently emit: |
| 384 | |
| 385 | _X: |
| 386 | subl $12, %esp |
| 387 | xorpd %xmm0, %xmm0 |
| 388 | addsd 24(%esp), %xmm0 |
| 389 | movsd 32(%esp), %xmm1 |
| 390 | movsd 16(%esp), %xmm2 |
| 391 | ucomisd 40(%esp), %xmm1 |
| 392 | jb LBB_X_2 |
| 393 | LBB_X_1: |
| 394 | movsd %xmm0, %xmm2 |
| 395 | LBB_X_2: |
| 396 | movsd %xmm2, (%esp) |
| 397 | fldl (%esp) |
| 398 | addl $12, %esp |
| 399 | ret |
Chris Lattner | 9acddcd | 2006-02-02 19:16:34 +0000 | [diff] [blame] | 400 | |
Evan Cheng | 183fff9 | 2006-02-07 08:35:44 +0000 | [diff] [blame] | 401 | //===---------------------------------------------------------------------===// |
| 402 | |
Chris Lattner | 8f77b73 | 2006-02-08 06:52:06 +0000 | [diff] [blame] | 403 | We should generate bts/btr/etc instructions on targets where they are cheap or |
| 404 | when codesize is important. e.g., for: |
| 405 | |
| 406 | void setbit(int *target, int bit) { |
| 407 | *target |= (1 << bit); |
| 408 | } |
| 409 | void clearbit(int *target, int bit) { |
| 410 | *target &= ~(1 << bit); |
| 411 | } |
| 412 | |
Chris Lattner | dba382b | 2006-02-08 17:47:22 +0000 | [diff] [blame] | 413 | //===---------------------------------------------------------------------===// |
| 414 | |
Evan Cheng | 952b7d6 | 2006-02-14 08:25:32 +0000 | [diff] [blame] | 415 | Instead of the following for memset char*, 1, 10: |
| 416 | |
| 417 | movl $16843009, 4(%edx) |
| 418 | movl $16843009, (%edx) |
| 419 | movw $257, 8(%edx) |
| 420 | |
| 421 | It might be better to generate |
| 422 | |
| 423 | movl $16843009, %eax |
| 424 | movl %eax, 4(%edx) |
| 425 | movl %eax, (%edx) |
| 426 | movw al, 8(%edx) |
| 427 | |
| 428 | when we can spare a register. It reduces code size. |
Evan Cheng | 7634ac4 | 2006-02-17 00:04:28 +0000 | [diff] [blame] | 429 | |
| 430 | //===---------------------------------------------------------------------===// |
| 431 | |
| 432 | It's not clear whether we should use pxor or xorps / xorpd to clear XMM |
| 433 | registers. The choice may depend on subtarget information. We should do some |
| 434 | more experiments on different x86 machines. |
Chris Lattner | a648df2 | 2006-02-17 04:20:13 +0000 | [diff] [blame] | 435 | |
| 436 | //===---------------------------------------------------------------------===// |
| 437 | |
| 438 | Evaluate what the best way to codegen sdiv X, (2^C) is. For X/8, we currently |
| 439 | get this: |
| 440 | |
| 441 | int %test1(int %X) { |
| 442 | %Y = div int %X, 8 |
| 443 | ret int %Y |
| 444 | } |
| 445 | |
| 446 | _test1: |
| 447 | movl 4(%esp), %eax |
| 448 | movl %eax, %ecx |
| 449 | sarl $31, %ecx |
| 450 | shrl $29, %ecx |
| 451 | addl %ecx, %eax |
| 452 | sarl $3, %eax |
| 453 | ret |
| 454 | |
| 455 | GCC knows several different ways to codegen it, one of which is this: |
| 456 | |
| 457 | _test1: |
| 458 | movl 4(%esp), %eax |
| 459 | cmpl $-1, %eax |
| 460 | leal 7(%eax), %ecx |
| 461 | cmovle %ecx, %eax |
| 462 | sarl $3, %eax |
| 463 | ret |
| 464 | |
| 465 | which is probably slower, but it's interesting at least :) |
| 466 | |
Evan Cheng | 755ee8f | 2006-02-20 19:58:27 +0000 | [diff] [blame] | 467 | //===---------------------------------------------------------------------===// |
| 468 | |
| 469 | Currently the x86 codegen isn't very good at mixing SSE and FPStack |
| 470 | code: |
| 471 | |
| 472 | unsigned int foo(double x) { return x; } |
| 473 | |
| 474 | foo: |
| 475 | subl $20, %esp |
| 476 | movsd 24(%esp), %xmm0 |
| 477 | movsd %xmm0, 8(%esp) |
| 478 | fldl 8(%esp) |
| 479 | fisttpll (%esp) |
| 480 | movl (%esp), %eax |
| 481 | addl $20, %esp |
| 482 | ret |
| 483 | |
| 484 | This will be solved when we go to a dynamic programming based isel. |
Evan Cheng | 3032410 | 2006-02-23 02:50:21 +0000 | [diff] [blame] | 485 | |
| 486 | //===---------------------------------------------------------------------===// |
| 487 | |
Evan Cheng | 7ab5404 | 2006-03-21 07:18:26 +0000 | [diff] [blame] | 488 | Should generate min/max for stuff like: |
| 489 | |
| 490 | void minf(float a, float b, float *X) { |
| 491 | *X = a <= b ? a : b; |
| 492 | } |
| 493 | |
Evan Cheng | 3032410 | 2006-02-23 02:50:21 +0000 | [diff] [blame] | 494 | Make use of floating point min / max instructions. Perhaps introduce ISD::FMIN |
| 495 | and ISD::FMAX node types? |
| 496 | |
| 497 | //===---------------------------------------------------------------------===// |
| 498 | |
Chris Lattner | 205065a | 2006-02-23 05:17:43 +0000 | [diff] [blame] | 499 | The first BB of this code: |
| 500 | |
| 501 | declare bool %foo() |
| 502 | int %bar() { |
| 503 | %V = call bool %foo() |
| 504 | br bool %V, label %T, label %F |
| 505 | T: |
| 506 | ret int 1 |
| 507 | F: |
| 508 | call bool %foo() |
| 509 | ret int 12 |
| 510 | } |
| 511 | |
| 512 | compiles to: |
| 513 | |
| 514 | _bar: |
| 515 | subl $12, %esp |
| 516 | call L_foo$stub |
| 517 | xorb $1, %al |
| 518 | testb %al, %al |
| 519 | jne LBB_bar_2 # F |
| 520 | |
| 521 | It would be better to emit "cmp %al, 1" than a xor and test. |
| 522 | |
Evan Cheng | 53f280a | 2006-02-25 10:04:07 +0000 | [diff] [blame] | 523 | //===---------------------------------------------------------------------===// |
Chris Lattner | 205065a | 2006-02-23 05:17:43 +0000 | [diff] [blame] | 524 | |
Evan Cheng | 53f280a | 2006-02-25 10:04:07 +0000 | [diff] [blame] | 525 | Enable X86InstrInfo::convertToThreeAddress(). |
Evan Cheng | aafc141 | 2006-02-28 23:38:49 +0000 | [diff] [blame] | 526 | |
| 527 | //===---------------------------------------------------------------------===// |
| 528 | |
| 529 | Investigate whether it is better to codegen the following |
| 530 | |
| 531 | %tmp.1 = mul int %x, 9 |
| 532 | to |
| 533 | |
| 534 | movl 4(%esp), %eax |
| 535 | leal (%eax,%eax,8), %eax |
| 536 | |
| 537 | as opposed to what llc is currently generating: |
| 538 | |
| 539 | imull $9, 4(%esp), %eax |
| 540 | |
| 541 | Currently the load folding imull has a higher complexity than the LEA32 pattern. |
Evan Cheng | f42f516 | 2006-03-04 07:49:50 +0000 | [diff] [blame] | 542 | |
| 543 | //===---------------------------------------------------------------------===// |
| 544 | |
| 545 | Lower memcpy / memset to a series of SSE 128 bit move instructions when it's |
| 546 | feasible. |
Chris Lattner | a4929df | 2006-03-05 01:15:18 +0000 | [diff] [blame] | 547 | |
| 548 | //===---------------------------------------------------------------------===// |
| 549 | |
Chris Lattner | 9d5da1d | 2006-03-24 07:12:19 +0000 | [diff] [blame^] | 550 | Teach the coalescer to commute 2-addr instructions, allowing us to eliminate |
Chris Lattner | a4929df | 2006-03-05 01:15:18 +0000 | [diff] [blame] | 551 | the reg-reg copy in this example: |
| 552 | |
| 553 | float foo(int *x, float *y, unsigned c) { |
| 554 | float res = 0.0; |
| 555 | unsigned i; |
| 556 | for (i = 0; i < c; i++) { |
| 557 | float xx = (float)x[i]; |
| 558 | xx = xx * y[i]; |
| 559 | xx += res; |
| 560 | res = xx; |
| 561 | } |
| 562 | return res; |
| 563 | } |
| 564 | |
| 565 | LBB_foo_3: # no_exit |
| 566 | cvtsi2ss %XMM0, DWORD PTR [%EDX + 4*%ESI] |
| 567 | mulss %XMM0, DWORD PTR [%EAX + 4*%ESI] |
| 568 | addss %XMM0, %XMM1 |
| 569 | inc %ESI |
| 570 | cmp %ESI, %ECX |
| 571 | **** movaps %XMM1, %XMM0 |
| 572 | jb LBB_foo_3 # no_exit |
| 573 | |
| 574 | //===---------------------------------------------------------------------===// |
Chris Lattner | 181b9c6 | 2006-03-09 01:39:46 +0000 | [diff] [blame] | 575 | |
| 576 | Codegen: |
| 577 | if (copysign(1.0, x) == copysign(1.0, y)) |
| 578 | into: |
| 579 | if (x^y & mask) |
| 580 | when using SSE. |
| 581 | |
| 582 | //===---------------------------------------------------------------------===// |
| 583 | |
| 584 | Optimize this into something reasonable: |
| 585 | x * copysign(1.0, y) * copysign(1.0, z) |
| 586 | |
| 587 | //===---------------------------------------------------------------------===// |
| 588 | |
| 589 | Optimize copysign(x, *y) to use an integer load from y. |
| 590 | |
| 591 | //===---------------------------------------------------------------------===// |
| 592 | |
Evan Cheng | 2771d21 | 2006-03-16 22:44:22 +0000 | [diff] [blame] | 593 | %X = weak global int 0 |
| 594 | |
| 595 | void %foo(int %N) { |
| 596 | %N = cast int %N to uint |
| 597 | %tmp.24 = setgt int %N, 0 |
| 598 | br bool %tmp.24, label %no_exit, label %return |
| 599 | |
| 600 | no_exit: |
| 601 | %indvar = phi uint [ 0, %entry ], [ %indvar.next, %no_exit ] |
| 602 | %i.0.0 = cast uint %indvar to int |
| 603 | volatile store int %i.0.0, int* %X |
| 604 | %indvar.next = add uint %indvar, 1 |
| 605 | %exitcond = seteq uint %indvar.next, %N |
| 606 | br bool %exitcond, label %return, label %no_exit |
| 607 | |
| 608 | return: |
| 609 | ret void |
| 610 | } |
| 611 | |
| 612 | compiles into: |
| 613 | |
| 614 | .text |
| 615 | .align 4 |
| 616 | .globl _foo |
| 617 | _foo: |
| 618 | movl 4(%esp), %eax |
| 619 | cmpl $1, %eax |
| 620 | jl LBB_foo_4 # return |
| 621 | LBB_foo_1: # no_exit.preheader |
| 622 | xorl %ecx, %ecx |
| 623 | LBB_foo_2: # no_exit |
| 624 | movl L_X$non_lazy_ptr, %edx |
| 625 | movl %ecx, (%edx) |
| 626 | incl %ecx |
| 627 | cmpl %eax, %ecx |
| 628 | jne LBB_foo_2 # no_exit |
| 629 | LBB_foo_3: # return.loopexit |
| 630 | LBB_foo_4: # return |
| 631 | ret |
| 632 | |
| 633 | We should hoist "movl L_X$non_lazy_ptr, %edx" out of the loop after |
| 634 | remateralization is implemented. This can be accomplished with 1) a target |
| 635 | dependent LICM pass or 2) makeing SelectDAG represent the whole function. |
| 636 | |
| 637 | //===---------------------------------------------------------------------===// |
Evan Cheng | 0def9c3 | 2006-03-19 06:08:11 +0000 | [diff] [blame] | 638 | |
| 639 | The following tests perform worse with LSR: |
| 640 | |
| 641 | lambda, siod, optimizer-eval, ackermann, hash2, nestedloop, strcat, and Treesor. |
Chris Lattner | 8bcf926 | 2006-03-19 22:27:41 +0000 | [diff] [blame] | 642 | |
| 643 | //===---------------------------------------------------------------------===// |
| 644 | |
Chris Lattner | 9d5da1d | 2006-03-24 07:12:19 +0000 | [diff] [blame^] | 645 | Teach the coalescer to coalesce vregs of different register classes. e.g. FR32 / |
Evan Cheng | 50a6d8c | 2006-03-21 07:12:57 +0000 | [diff] [blame] | 646 | FR64 to VR128. |
Evan Cheng | b20aace | 2006-03-24 02:57:03 +0000 | [diff] [blame] | 647 | |
| 648 | //===---------------------------------------------------------------------===// |
| 649 | |
| 650 | mov $reg, 48(%esp) |
| 651 | ... |
| 652 | leal 48(%esp), %eax |
| 653 | mov %eax, (%esp) |
| 654 | call _foo |
| 655 | |
| 656 | Obviously it would have been better for the first mov (or any op) to store |
| 657 | directly %esp[0] if there are no other uses. |
Evan Cheng | 5217a5b | 2006-03-24 06:40:32 +0000 | [diff] [blame] | 658 | |
| 659 | //===---------------------------------------------------------------------===// |
| 660 | |
| 661 | Add more vector shuffle special cases using unpckhps and unpcklps. |