[llvm-dev] llc generating code that writes below the stack pointer on darwin/x86-64

Jonas Maebe via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 13 09:12:24 PST 2016


Is there something wrong with my inline assembly below?

target datalayout = 
target triple = "x86_64-apple-macosx10.5"

define void @"\01_SYSTEM_$$_SETMXCSR$LONGWORD"(i32 %p.w) nobuiltin {
; [71] procedure SetMXCSR(w : dword);
         %tmp.1 = alloca i32, align 4
; Var w located at %tmp.1
; [72] begin
         store i32 %p.w, i32* %tmp.1, align 4
; [73] defaultmxcsr:=w;
         %reg.1_16 = load i32, i32* %tmp.1, align 4
         store i32 %reg.1_16, i32* @"\01_TC_$SYSTEM_$$_DEFAULTMXCSR", 
align 4
; [75] ldmxcsr w
         call void asm sideeffect "# 
; [77] end;
         br label %Lj1135
         ret void

@"\01_TC_$SYSTEM_$$_DEFAULTMXCSR" = global i32 6400, align 4

I know the clobber list is overly conservative, but it's automatically 
generated by our compiler, which does not have the necessary information 
to reduce it.

The resulting assembly generated by llc -O2 is:

         .section        __TEXT,__text,regular,pure_instructions
         .macosx_version_min 10, 5
         .globl  _SYSTEM_$$_SETMXCSR$LONGWORD
         .p2align        4, 0x90
## BB#0:
         movl    %edi, -4(%rsp)
         movl    %edi, _TC_$SYSTEM_$$_DEFAULTMXCSR(%rip)
         ## InlineAsm Start
         ## [math.inc]
         ldmxcsr -4(%rsp)
         ##  CPU ATHLON64

         ## InlineAsm End

         .section        __DATA,__data
         .globl  _TC_$SYSTEM_$$_DEFAULTMXCSR ## 
         .p2align        2
         .long   6400                    ## 0x1900


This code use a negative stack offset, which is forbidden on x86-64 
(there's no red zone). This happens with llc from llvm 3.7, 3.8 and 3.9.



More information about the llvm-dev mailing list