On Wed, May 16, 2007 at 03:51:04PM +0200, Peter Halacsy wrote:
> hello guys,
>
> can the ocaml compiler figure out that this code can be simplified
>
> let id x = x
> let a = ref 1
> a := id !a
I suspect that the answer is no.
I had a look at the assembler generated by 'ocamlopt -S' but these new
relocatable x86-64 opcodes are rather hard to follow ... However it
did seem to be calling the id function rather than optimising it away.
Rich.
.quad 2048
.globl camlTest
camlTest:
.space 16
.data
.quad 2295
camlTest__1:
.quad camlTest__id_57
.quad 3
.text
.align 16
.globl camlTest__id_57
camlTest__id_57:
.L100:
ret
.text
.align 16
.globl camlTest__entry
camlTest__entry:
subq $8, %rsp
.L101:
movq $camlTest__1, %rax
movq %rax, camlTest(%rip)
call caml_alloc1
.L102:
leaq 8(%r15), %rax
movq $1024, -8(%rax)
movq $3, (%rax)
movq %rax, camlTest + 8(%rip)
movq camlTest + 8(%rip), %rbx
movq camlTest + 8(%rip), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movq $1, %rax
addq $8, %rsp
ret
.text
.globl camlTest__code_end
camlTest__code_end:
.data
.globl camlTest__data_end
camlTest__data_end:
.long 0
.globl camlTest__frametable
camlTest__frametable:
.quad 1
.quad .L102
.word 16
.word 0
.align 8
--
Richard Jones
Red Hat
.