[LLVMdev] ASM appears to be incorrect from llc

Eli Friedman eli.friedman at gmail.com
Wed Feb 15 16:11:00 PST 2012


On Wed, Feb 15, 2012 at 3:36 PM, Matthew Huck <matthew.huck at gmail.com> wrote:
> Hi,
>   I'm trying to compile an intermediate representation file to ASM (intel
> style), and I believe that the resultant ASM is invalid. The IR is:
>
> ; ModuleID = 'test.u'
>
> %vec2 = type { float, float }
> @t = global %vec2 zeroinitializer
> @x = global i32 0
>
> define i32 @main__i__v() nounwind {
> locals:
>   %0 = load float* getelementptr inbounds (%vec2* @t, i32 0, i32 0)
>   %1 = fptosi float %0 to i64
>   %2 = trunc i64 %1 to i32
>   store i32 %2, i32* @x
>   ret i32 0
> }
>
>
>
> Now, I know no memory is allocated for t (ignore that), we'll just expect
> the final program to crash
>
> Running this through
> llvm-as.exe test.trunk.ll -f -o test.bc
> and then
> llc -x86-asm-syntax=intel -o test.trunk.S test.bc
>
> yields:
>
> .def _main__i__v;
> .scl 2;
> .type 32;
> .endef
> .text
> .globl _main__i__v
> .align 16, 0x90
> _main__i__v:                            # @main__i__v
> # BB#0:                                 # %locals
> sub ESP, 20
> movss XMM0, DWORD PTR [_t]
> movss DWORD PTR [ESP + 8], XMM0
> fld DWORD PTR [ESP + 8]
> fisttp QWORD PTR [ESP]
> mov EAX, DWORD PTR [ESP]
> mov _x, EAX
> xor EAX, EAX
> add ESP, 20
> ret
>
> .data
> .globl _t                      # @t
> .align 8
> _t:
> .zero 8
>
> .globl _x                      # @x
> .align 4
> _x:
> .long 0                       # 0x0
>
>
>
>
> Now, the bit I think is wrong is
> mov _x,EAX
>
> I think it should be
> mov [_x], eax
>
> Thoughts?

What makes you think it's wrong?

-Eli




More information about the llvm-dev mailing list