[llvm] r175576 - [ms-inline asm] Force the use of a base pointer if the MachineFunction includes

Chad Rosier chad.rosier at gmail.com
Thu Aug 8 10:56:23 PDT 2013


That sounds like a reasonable step forward.  Inline assembly does have a
diagnostics handler, so we should prefer the use of that over reporting the
use of a fatal error.  Unfortunately, I'm off breaking other parts of the
compiler, so I don't know if or when I would be able to get to this.
Patches are welcome!

 Chad

On Thu, Aug 8, 2013 at 1:42 PM, Reid Kleckner <rnk at google.com> wrote:

> gcc will try really hard to find a free register from which to address
> your stack variables, starting with esp, and then falling back to any free
> register.  If you clobber every register except for ebp *and* require stack
> realignment, it errors out.
>
> If you remove any clobber from the following example, it will compile.
>
> $ cat realign_inline_asm.c
> int foo(int a) {
>   __attribute__((aligned(16))) int r = -1;
>   asm volatile ("push %%edi\n\t"
>                 "xor %%eax, %%eax\n\t"
>                 "xor %%ebx, %%ebx\n\t"
>                 "xor %%ecx, %%ecx\n\t"
>                 "xor %%edx, %%edx\n\t"
>                 "xor %%esi, %%esi\n\t"
>                 "mov %0, %%eax\n\t"
>                 "pop %%edi\n\t"
>                 "xor %%edi, %%edi\n\t"
>                 : "=m"(r) /* out */
>                 : /* in */
>                 : "eax", "ebx", "ecx", "edx", "esi", "edi", "esp");
>   return r;
> }
>
> $ gcc -m32 -c realign_inline_asm.c -S -o -  -mstackrealign
>         .file   "realign_inline_asm.c"
> realign_inline_asm.c: In function ‘foo’:
> realign_inline_asm.c:3:3: error: can’t find a register in class
> ‘GENERAL_REGS’ while reloading ‘asm’
>
> For now, at least, it would be nice to report a fatal error when we want
> to use esi for the BP, but we have inline asm that clobbers it.  We already
> have the clobber list with that info.
>
>
> On Thu, Aug 8, 2013 at 7:39 AM, Chad Rosier <chad.rosier at gmail.com> wrote:
>
>>
>> On Wed, Aug 7, 2013 at 8:38 PM, Jakob Stoklund Olesen <stoklund at 2pi.dk>wrote:
>>
>>> On Aug 7, 2013, at 5:17 PM, Reid Kleckner <rnk at google.com> wrote:
>>>
>>> > Wouldn't it be much better to use ebp for the base pointer and put the
>>> pre-alignment SP into a local that could be spilled or register allocated
>>> as necessary?  Is that just a matter of work?
>>>
>>> I think stack unwinders would expect to find the frame pointer in %ebp.
>>>
>>> /jakob
>>
>>
>> Unfortunately, I can't think of a simple solution here.  How does gcc
>> handle this case?  IIRC, gcc was the original motivating factor for forcing
>> the use of the FP?
>>
>>  Chad
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130808/f3e0b063/attachment.html>


More information about the llvm-commits mailing list