1 //===---------------------------------------------------------------------===//
2 // Random ideas for the X86 backend.
3 //===---------------------------------------------------------------------===//
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:
10 long long test(long long X, long long Y) { return X*Y; }
12 by using the EAX result from the mul. We should add a similar node for
17 long long test(int X, int Y) { return (long long)X*Y; }
19 ... which should only be one imul instruction.
21 //===---------------------------------------------------------------------===//
23 This should be one DIV/IDIV instruction, not a libcall:
25 unsigned test(unsigned long long X, unsigned Y) {
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
32 //===---------------------------------------------------------------------===//
34 Some targets (e.g. athlons) prefer freep to fstp ST(0):
35 http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00659.html
37 //===---------------------------------------------------------------------===//
39 This should use fiadd on chips where it is profitable:
40 double foo(double P, int *I) { return P+*I; }
42 //===---------------------------------------------------------------------===//
44 The FP stackifier needs to be global. Also, it should handle simple permutates
45 to reduce number of shuffle instructions, e.g. turning:
58 http://gcc.gnu.org/ml/gcc-patches/2004-11/msg02410.html
61 //===---------------------------------------------------------------------===//
63 Improvements to the multiply -> shift/add algorithm:
64 http://gcc.gnu.org/ml/gcc-patches/2004-08/msg01590.html
66 //===---------------------------------------------------------------------===//
68 Improve code like this (occurs fairly frequently, e.g. in LLVM):
69 long long foo(int x) { return 1LL << x; }
71 http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01109.html
72 http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01128.html
73 http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01136.html
75 Another useful one would be ~0ULL >> X and ~0ULL << X.
77 //===---------------------------------------------------------------------===//
80 _Bool f(_Bool a) { return a!=1; }
87 //===---------------------------------------------------------------------===//
91 1. Dynamic programming based approach when compile time if not an
93 2. Code duplication (addressing mode) during isel.
94 3. Other ideas from "Register-Sensitive Selection, Duplication, and
95 Sequencing of Instructions".
97 //===---------------------------------------------------------------------===//
99 Should we promote i16 to i32 to avoid partial register update stalls?
101 //===---------------------------------------------------------------------===//
103 Leave any_extend as pseudo instruction and hint to register
104 allocator. Delay codegen until post register allocation.
106 //===---------------------------------------------------------------------===//
108 Add a target specific hook to DAG combiner to handle SINT_TO_FP and
109 FP_TO_SINT when the source operand is already in memory.
111 //===---------------------------------------------------------------------===//
113 Check if load folding would add a cycle in the dag.
115 //===---------------------------------------------------------------------===//
117 Model X86 EFLAGS as a real register to avoid redudant cmp / test. e.g.
121 testb %al, %al # unnecessary
124 //===---------------------------------------------------------------------===//
126 Count leading zeros and count trailing zeros:
128 int clz(int X) { return __builtin_clz(X); }
129 int ctz(int X) { return __builtin_ctz(X); }
131 $ gcc t.c -S -o - -O3 -fomit-frame-pointer -masm=intel
133 bsr %eax, DWORD PTR [%esp+4]
137 bsf %eax, DWORD PTR [%esp+4]
140 however, check that these are defined for 0 and 32. Our intrinsics are, GCC's
143 //===---------------------------------------------------------------------===//
145 Use push/pop instructions in prolog/epilog sequences instead of stores off
146 ESP (certain code size win, perf win on some [which?] processors).
148 //===---------------------------------------------------------------------===//
150 Only use inc/neg/not instructions on processors where they are faster than
151 add/sub/xor. They are slower on the P4 due to only updating some processor
154 //===---------------------------------------------------------------------===//
156 Open code rint,floor,ceil,trunc:
157 http://gcc.gnu.org/ml/gcc-patches/2004-08/msg02006.html
158 http://gcc.gnu.org/ml/gcc-patches/2004-08/msg02011.html
160 //===---------------------------------------------------------------------===//
162 Combine: a = sin(x), b = cos(x) into a,b = sincos(x).
164 //===---------------------------------------------------------------------===//
166 The instruction selector sometimes misses folding a load into a compare. The
167 pattern is written as (cmp reg, (load p)). Because the compare isn't
168 commutative, it is not matched with the load on both sides. The dag combiner
169 should be made smart enough to cannonicalize the load into the RHS of a compare
170 when it can invert the result of the compare for free.
172 //===---------------------------------------------------------------------===//
174 LSR should be turned on for the X86 backend and tuned to take advantage of its
177 //===---------------------------------------------------------------------===//
179 When compiled with unsafemath enabled, "main" should enable SSE DAZ mode and
180 other fast SSE modes.
182 //===---------------------------------------------------------------------===//
184 Think about doing i64 math in SSE regs.
186 //===---------------------------------------------------------------------===//
188 The DAG Isel doesn't fold the loads into the adds in this testcase. The
189 pattern selector does. This is because the chain value of the load gets
190 selected first, and the loads aren't checking to see if they are only used by
195 int %test(int* %x, int* %y, int* %z) {
228 This is bad for register pressure, though the dag isel is producing a
231 //===---------------------------------------------------------------------===//
233 This testcase should have no SSE instructions in it, and only one load from
236 double %test3(bool %B) {
237 %C = select bool %B, double 123.412, double 523.01123123
241 Currently, the select is being lowered, which prevents the dag combiner from
242 turning 'select (load CPI1), (load CPI2)' -> 'load (select CPI1, CPI2)'
244 The pattern isel got this one right.
246 //===---------------------------------------------------------------------===//
248 We need to lower switch statements to tablejumps when appropriate instead of
249 always into binary branch trees.
251 //===---------------------------------------------------------------------===//
253 SSE doesn't have [mem] op= reg instructions. If we have an SSE instruction
258 and the register allocator decides to spill X, it is cheaper to emit this as:
269 ..and this uses one fewer register (so this should be done at load folding
270 time, not at spiller time). *Note* however that this can only be done
271 if Y is dead. Here's a testcase:
273 %.str_3 = external global [15 x sbyte] ; <[15 x sbyte]*> [#uses=0]
274 implementation ; Functions:
275 declare void %printf(int, ...)
279 no_exit.i7: ; preds = %no_exit.i7, %build_tree.exit
280 %tmp.0.1.0.i9 = phi double [ 0.000000e+00, %build_tree.exit ], [ %tmp.34.i18, %no_exit.i7 ] ; <double> [#uses=1]
281 %tmp.0.0.0.i10 = phi double [ 0.000000e+00, %build_tree.exit ], [ %tmp.28.i16, %no_exit.i7 ] ; <double> [#uses=1]
282 %tmp.28.i16 = add double %tmp.0.0.0.i10, 0.000000e+00
283 %tmp.34.i18 = add double %tmp.0.1.0.i9, 0.000000e+00
284 br bool false, label %Compute_Tree.exit23, label %no_exit.i7
285 Compute_Tree.exit23: ; preds = %no_exit.i7
286 tail call void (int, ...)* %printf( int 0 )
287 store double %tmp.34.i18, double* null
296 *** movsd %XMM2, QWORD PTR [%ESP + 8]
297 *** addsd %XMM2, %XMM1
298 *** movsd QWORD PTR [%ESP + 8], %XMM2
299 jmp .BBmain_1 # no_exit.i7
301 This is a bugpoint reduced testcase, which is why the testcase doesn't make
302 much sense (e.g. its an infinite loop). :)
304 //===---------------------------------------------------------------------===//
306 None of the FPStack instructions are handled in
307 X86RegisterInfo::foldMemoryOperand, which prevents the spiller from
308 folding spill code into the instructions.
310 //===---------------------------------------------------------------------===//
312 In many cases, LLVM generates code like this:
321 on some processors (which ones?), it is more efficient to do this:
330 Doing this correctly is tricky though, as the xor clobbers the flags.
332 //===---------------------------------------------------------------------===//
334 We should generate 'test' instead of 'cmp' in various cases, e.g.:
337 %Y = shl int %X, ubyte 1
347 This may just be a matter of using 'test' to write bigger patterns for X86cmp.
349 //===---------------------------------------------------------------------===//
351 Evaluate whether using movapd for SSE reg-reg moves is faster than using
352 movsd/movss for them. It may eliminate false partial register dependences by
353 writing the whole result register.
355 //===---------------------------------------------------------------------===//
357 SSE should implement 'select_cc' using 'emulated conditional moves' that use
358 pcmp/pand/pandn/por to do a selection instead of a conditional branch:
360 double %X(double %Y, double %Z, double %A, double %B) {
361 %C = setlt double %A, %B
362 %z = add double %Z, 0.0 ;; select operand is not a load
363 %D = select bool %C, double %Y, double %z
372 addsd 24(%esp), %xmm0
373 movsd 32(%esp), %xmm1
374 movsd 16(%esp), %xmm2
375 ucomisd 40(%esp), %xmm1
385 //===---------------------------------------------------------------------===//
387 The x86 backend currently supports dynamic-no-pic. Need to add asm
388 printer support for static and PIC.