Hello,
I have this simple IR:
------------------------------------------------------------------------
define internal i32 @tmp(i32 %x) {
entry:
br label %entry2
entry2:
%x1 = alloca i32
%x2 = alloca i32
%retval = alloca i32
%dummy = alloca i32
store i32 %x, i32* %x1
store i32 %x, i32* %x2
%tmp1 = load i32* %x1
%tmp2 = add i32 %tmp1, %tmp1
%tmp3 = add i32 %tmp2, %tmp2
store i32 %tmp3, i32* %retval
br label %return
return:
%rc = load i32* %retval
ret i32 %rc
}
define i32 @main() nounwind {
entry:
%tmp = call i32 @tmp(i32 1) nounwind
ret i32 %tmp
}
------------------------------------------------------------------------
I am expecting the main function to return 4 (works fine on MacOS).
On MingW (i386-pc-mingw32), using the current SVN and lli or llc, it
returns a random value. The assembly below is the output of llc for that
target. I can clearly see the 4 allocas, x1 is at %edi, x2 is at %ebx,
%retval on the stack at -16(%ebp) and %dummy, which is unused is at %esp
%after the last alloca.
The first movl after the two addl is using a wrong address to store the
result (%esp points to %dummy, but the result should not be stored
there).
------------------------------------------------------------------------
.text
.align 16
.def _tmp; .scl 3; .type 32; .endef
_tmp:
pushl %ebp
Llabel1:
movl %esp, %ebp
Llabel2:
pushl %ebx
pushl %edi
pushl %esi
subl $4, %esp
LBB1_1: # entry2
movl $8, %esi
movl %esi, %eax
call __alloca
movl %esp, %edi
movl %esi, %eax
call __alloca
movl %esp, %ebx
movl %esi, %eax
call __alloca
movl %esp, -16(%ebp)
movl %esi, %eax
call __alloca
movl 8(%ebp), %eax
movl %eax, (%edi)
movl %eax, (%ebx)
movl (%edi), %eax
addl %eax, %eax
addl %eax, %eax
movl %eax, (%esp) <=== should be 8(%esp) or -40(%ebp) ?
LBB1_2: # return
movl -16(%ebp), %eax
movl (%eax), %eax
leal -12(%ebp), %esp
popl %esi
popl %edi
popl %ebx
popl %ebp
ret
.align 16
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
call ___main
movl $1, (%esp)
call _tmp
addl $8, %esp
popl %ebp
ret
------------------------------------------------------------------------
Any idea why this is happening ?
Thanks,
Julien
--
Julien Lerouge
PGP Key Id: 0xB1964A62
PGP Fingerprint: 392D 4BAD DB8B CE7F 4E5F FA3C 62DB 4AA7 B196 4A62
PGP Public Key from: keyserver.pgp.com