[llvm-commits] X86 FastISel: Emit immediate call arguments locally to save stack size when compiling with -O0
Jakob Stoklund Olesen
stoklund at 2pi.dk
Tue Aug 2 14:01:58 PDT 2011
On Aug 2, 2011, at 12:55 PM, Ivan Krasin wrote:
> Hi Jacob,
>
> On Mon, Aug 1, 2011 at 10:35 PM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>>
>> On Aug 1, 2011, at 2:13 PM, Ivan Krasin wrote:
>>
>> this patch fixes the FastISel stack allocation strategy issue described
>> here:
>> http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-July/041452.html
>> The solution is to emit immediate int arguments just before the call
>> (instead of spilling them on stack at the beginning of the function)
>>
>> Thanks for working on this, Ivan.
>> I don't think there is any reason to special-case function arguments. It is
>> just as bad when fast-isel hoists the immediate in 'x+1'.
>> I would prefer an approach that handled all immediates.
> Thanks, it's a good point. I have tried to use double arguments as
> immediates as well, but FastISel fails on them.
> I think it also should be fixed, but I would prefer to make it in the next CL.
Floating point constants are probably not important. They will be folded as constant pool loads most of the time, I expect.
What I meant was, don't treat function arguments as a special case. You should handle all integer constants, whether they are used as function arguments or 'add' operands.
Your patch doesn't work or this code, right?
f(y + 5);
f(x + 5);
That '5' gets hoisted to the top of the block and spilled because of the first call. It shouldn't.
Here is how fast isel currently works: It emits instructions bottom-up. When it needs a constant, the code for the constant is emitted to the top of the block, and it makes a note that the constant is now in a virtual register. Further uses of that constant simply get the virtual register.
Here is what you should do: When you need a constant, don't emit the code immediately, but do allocate a virtual register and make a note that the constant needs to be materialized. Whenever you are about to emit a call, materialize all the pending constants. Then insert the call instruction.
That way, virtual registers holding constants will never cross a call instruction, so they won't get spilled (much).
For patches like this, please provide measurements of code size and compile time as well.
Thanks,
/jakob
More information about the llvm-commits
mailing list