[LLVMbugs] [Bug 3695] New: llvm-gcc -S different from llvm-gcc -emit-llvm | llc

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Mar 1 10:20:23 PST 2009


http://llvm.org/bugs/show_bug.cgi?id=3695

           Summary: llvm-gcc -S different from llvm-gcc -emit-llvm | llc
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nicholas at mxc.ca
                CC: llvmbugs at cs.uiuc.edu


I'm not sure what's causing this discrepancy. I have a tiny function:

  # cat x.c
  int foo(double x)
  {
    return (int)x;
  }

which produces large amounts of x87 stack gunk when built with llvm-gcc:

  # llvm-gcc -O2 x.c -S -o -
  [...]
  foo:
          pushl   %ebp
          movl    %esp, %ebp
          subl    $6, %esp
          fldl    8(%ebp)
          fnstcw  -6(%ebp)
          movw    -6(%ebp), %ax
          movw    $3199, -6(%ebp)
          fldcw   -6(%ebp)
          movw    %ax, -6(%ebp)
          fistpl  -4(%ebp)
          fldcw   -6(%ebp)
          movl    -4(%ebp), %eax
          addl    $6, %esp
          popl    %ebp
          ret

wait, using x87 stack? I configured llvm-gcc --host=i686-pc-linux-gnu
--build=i686-pc-linux-gnu. Surely it could do better than that.

  # llvm-gcc -O2 x.c -c -o - -emit-llvm | llc -o -
  [...]
  foo:
          cvttsd2si       4(%esp), %eax
          ret

Much better. Why didn't llvm-gcc do that? What target triple is llvm-gcc
emitting anyways?

  # llvm-gcc -O2 x.c -S -o - -emit-llvm
  ; ModuleID = 'x.c'
  target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
  target triple = "i386-pc-linux-gnu"

  define i32 @foo(double %x) nounwind readnone {
  entry:
          %0 = fptosi double %x to i32            ; <i32> [#uses=1]
          ret i32 %0
  }

i386-pc-linux-gnu?! If you say so. Is llc ignoring the target triple? Or is
llvm-gcc setting something in the codegen that turns SSE support off? Let's try
that:

  # llvm-gcc -O2 x.c -c -o - -emit-llvm | llc -o - -mattr=-sse
  [...]
  foo:
          subl    $6, %esp
          fldl    10(%esp)
          fnstcw  (%esp)
          movw    (%esp), %ax
          movw    $3199, (%esp)
          fldcw   (%esp)
          movw    %ax, (%esp)
          fistpl  2(%esp)
          fldcw   (%esp)
          movl    2(%esp), %eax
          addl    $6, %esp
          ret

Note that it's *not the same*. The code directly emitted by llvm-gcc showed
push/mov pair in the prologue, while this skips straight to the subl. What on
Earth is going on?


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list