https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86236
Bug ID: 86236 Summary: -mstackrealign prologue clobbers %edi for fastcall functions with global register variable Product: gcc Version: 8.1.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: fw at gcc dot gnu.org Target Milestone: --- #include <xmmintrin.h> void f1 (void *, int); register int edi __asm__ ("edi"); __attribute__ ((fastcall)) void f2 (void) { // Force stack alignment. __m128i m; f1 (&m, edi); } Compile with “-m32 -O2 -march=x86-64 -msse2 -mfpmath=sse -mstackrealign”: .globl f2 .type f2, @function f2: .LFB504: .cfi_startproc leal 4(%esp), %edi .cfi_def_cfa 7, 0 andl $-16, %esp pushl -4(%edi) pushl %ebp .cfi_escape 0x10,0x5,0x2,0x75,0 movl %esp, %ebp pushl %edi .cfi_escape 0xf,0x3,0x75,0x7c,0x6 leal -24(%ebp), %eax subl $28, %esp pushl %edi pushl %eax call f1 movl -4(%ebp), %edi .cfi_def_cfa 7, 0 addl $16, %esp leave .cfi_restore 5 leal -4(%edi), %esp .cfi_def_cfa 4, 4 ret .cfi_endproc The value of %edi is clobbered before it is saved on the stack. I think %edi is callee-saved even for fastcall functions, so this is wrong on multiple levels.