1 //===- README_X86_64.txt - Notes for X86-64 code gen ----------------------===//
3 Implement different PIC models? Right now we only support Mac OS X with small
6 //===---------------------------------------------------------------------===//
8 Make use of "Red Zone".
10 //===---------------------------------------------------------------------===//
12 Implement __int128 and long double support.
14 //===---------------------------------------------------------------------===//
29 We need to do the tailcall optimization as well.
31 //===---------------------------------------------------------------------===//
33 AMD64 Optimization Manual 8.2 has some nice information about optimizing integer
34 multiplication by a constant. How much of it applies to Intel's X86-64
35 implementation? There are definite trade-offs to consider: latency vs. register
36 pressure vs. code size.
38 //===---------------------------------------------------------------------===//
40 Are we better off using branches instead of cmove to implement FP to
44 ucomiss LC0(%rip), %xmm0
45 cvttss2siq %xmm0, %rdx
47 subss LC0(%rip), %xmm0
48 movabsq $-9223372036854775808, %rax
49 cvttss2siq %xmm0, %rdx
58 movss LCPI1_0(%rip), %xmm1
59 cvttss2siq %xmm0, %rcx
62 cvttss2siq %xmm2, %rax
63 movabsq $-9223372036854775808, %rdx
69 Seems like the jb branch has high likelyhood of being taken. It would have
70 saved a few instructions.
72 //===---------------------------------------------------------------------===//
79 memset(X, b, 2*sizeof(X[0]));
83 movq _b@GOTPCREL(%rip), %rax
93 movq _X@GOTPCREL(%rip), %rdx
99 movq _b@GOTPCREL(%rip), %rax
100 movabsq $72340172838076673, %rdx
103 movq _X@GOTPCREL(%rip), %rdx
107 //===---------------------------------------------------------------------===//
109 Vararg function prologue can be further optimized. Currently all XMM registers
110 are stored into register save area. Most of them can be eliminated since the
111 upper bound of the number of XMM registers used are passed in %al. gcc produces
112 something like the following:
115 leaq 0(,%rdx,4), %rax
116 leaq 4+L2(%rip), %rdx
119 movaps %xmm7, -15(%rax)
120 movaps %xmm6, -31(%rax)
121 movaps %xmm5, -47(%rax)
122 movaps %xmm4, -63(%rax)
123 movaps %xmm3, -79(%rax)
124 movaps %xmm2, -95(%rax)
125 movaps %xmm1, -111(%rax)
126 movaps %xmm0, -127(%rax)
129 It jumps over the movaps that do not need to be stored. Hard to see this being
130 significant as it added 5 instruciton (including a indirect branch) to avoid
131 executing 0 to 8 stores in the function prologue.
133 Perhaps we can optimize for the common case where no XMM registers are used for
134 parameter passing. i.e. is %al == 0 jump over all stores. Or in the case of a
135 leaf function where we can determine that no XMM input parameter is need, avoid
136 emitting the stores at all.
138 //===---------------------------------------------------------------------===//
140 AMD64 has a complex calling convention for aggregate passing by value:
142 1. If the size of an object is larger than two eightbytes, or in C++, is a non-
143 POD structure or union type, or contains unaligned fields, it has class
145 2. Both eightbytes get initialized to class NO_CLASS.
146 3. Each field of an object is classified recursively so that always two fields
147 are considered. The resulting class is calculated according to the classes
148 of the fields in the eightbyte:
149 (a) If both classes are equal, this is the resulting class.
150 (b) If one of the classes is NO_CLASS, the resulting class is the other
152 (c) If one of the classes is MEMORY, the result is the MEMORY class.
153 (d) If one of the classes is INTEGER, the result is the INTEGER.
154 (e) If one of the classes is X87, X87UP, COMPLEX_X87 class, MEMORY is used as
156 (f) Otherwise class SSE is used.
157 4. Then a post merger cleanup is done:
158 (a) If one of the classes is MEMORY, the whole argument is passed in memory.
159 (b) If SSEUP is not preceeded by SSE, it is converted to SSE.
161 Currently llvm frontend does not handle this correctly.
164 typedef struct { int i; double d; } QuadWordS;
165 It is currently passed in two i64 integer registers. However, gcc compiled
166 callee expects the second element 'd' to be passed in XMM0.
169 typedef struct { int32_t i; float j; double d; } QuadWordS;
170 The size of the first two fields == i64 so they will be combined and passed in
171 a integer register RDI. The third field is still passed in XMM0.
174 typedef struct { int64_t i; int8_t j; int64_t d; } S;
176 The size of this aggregate is greater than two i64 so it should be passed in
177 memory. Currently llvm breaks this down and passed it in three integer
181 Taking problem 3 one step ahead where a function expects a aggregate value
182 in memory followed by more parameter(s) passed in register(s).
183 void test(S s, int b)
185 LLVM IR does not allow parameter passing by aggregates, therefore it must break
186 the aggregates value (in problem 3 and 4) into a number of scalar values:
187 void %test(long %s.i, byte %s.j, long %s.d);
189 However, if the backend were to lower this code literally it would pass the 3
190 values in integer registers. To force it be passed in memory, the frontend
191 should change the function signiture to:
192 void %test(long %undef1, long %undef2, long %undef3, long %undef4,
193 long %undef5, long %undef6,
194 long %s.i, byte %s.j, long %s.d);
195 And the callee would look something like this:
196 call void %test( undef, undef, undef, undef, undef, undef,
197 %tmp.s.i, %tmp.s.j, %tmp.s.d );
198 The first 6 undef parameters would exhaust the 6 integer registers used for
199 parameter passing. The following three integer values would then be forced into
202 For problem 4, the parameter 'd' would be moved to the front of the parameter
203 list so it will be passed in register:
205 long %undef1, long %undef2, long %undef3, long %undef4,
206 long %undef5, long %undef6,
207 long %s.i, byte %s.j, long %s.d);
209 //===---------------------------------------------------------------------===//
211 Right now the asm printer assumes GlobalAddress are accessed via RIP relative
212 addressing. Therefore, it is not possible to generate this:
213 movabsq $__ZTV10polynomialIdE+16, %rax
215 That is ok for now since we currently only support small model. So the above
217 leaq __ZTV10polynomialIdE+16(%rip), %rax
219 This is probably slightly slower but is much shorter than movabsq. However, if
220 we were to support medium or larger code models, we need to use the movabs
221 instruction. We should probably introduce something like AbsoluteAddress to
222 distinguish it from GlobalAddress so the asm printer and JIT code emitter can
225 //===---------------------------------------------------------------------===//
227 It's not possible to reference AH, BH, CH, and DH registers in an instruction
228 requiring REX prefix. However, divb and mulb both produce results in AH. If isel
229 emits a CopyFromReg which gets turned into a movb and that can be allocated a
232 To get around this, isel emits a CopyFromReg from AX and then right shift it
233 down by 8 and truncate it. It's not pretty but it works. We need some register
234 allocation magic to make the hack go away (e.g. putting additional constraints
235 on the result of the movb).