Ticket #2016 (closed bug: duplicate)

Opened 5 years ago

Last modified 5 years ago

GHC generates bad code for pointer manipulations from .cmm

Reported by: wb.kloke Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.8.2
Keywords: Cc:
Operating System: FreeBSD Architecture: x86_64 (amd64)
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

In files rts/StgStdThunks.cmm (and rts/StgMiscClosures.cmm also) a natively booted x86_64 compiler generates the following wrong assembler output:

.text
        .align 8
        .quad   0
        .quad   34
.globl stg_sel_ret_0_upd_info
stg_sel_ret_0_upd_info:
        movl $4294967288,%eax
        movq %rbx,%rcx
        andq %rax,%rcx
        movq 8(%rcx),%rbx
        addq $8,%rbp
...

The correct code for the movl line is

       movq $-8,%rax

The real output from a correct compiler (such as the stage1 compiler crosscompiled from i386) is slightly different due to optimisation, but equivalent to my correction.

I checked this bug with different compilation flags in the stage1 and stage2 creation phase (with -fasm or -fvia-C). I am not sure whether the bug is present in other x86_64 OSs, which are supported for longer than FreeBSD. But it is easy to check. Just compile the file with -S with a stage2 compiler.

Change History

Changed 5 years ago by simonmar

  • status changed from new to closed
  • resolution set to duplicate

I strongly suspect you are experiencing another symptom of #1989. The code is compiled correctly for me:

~/builds/testing/rts > make StgStdThunks.s HC=../compiler/stage2/ghc-inplace
../compiler/stage2/ghc-inplace -Werror -H64m -Onot -fasm -optc-O2 -I../includes -I. -Iparallel -Ism -DCOMPILING_RTS -package-name rts -static -I../gmp/gmpbuild -I. -#include HCIncludes.h -dcmm-lint     -S StgStdThunks.cmm -o StgStdThunks.s
~/builds/testing/rts > head -50 StgStdThunks.s
.text
        .align 8
        .quad   0
        .quad   34
.globl stg_sel_ret_0_upd_info
.type stg_sel_ret_0_upd_info, @object
stg_sel_ret_0_upd_info:
.Lcg:
        movq %rbx,%rax
        andq $-8,%rax
        movq 8(%rax),%rbx
        addq $8,%rbp
.Lc3:
        testq $7,%rbx
        jne .Lce
.Lcd:
        movq (%rbx),%rax
        movslq -8(%rax),%rcx
        jmp *.Lnea(,%rcx,8)
.Lcb:
        movq 8(%rbx),%rbx
        jmp .Lc3
.Lca:
        jmp *(%rbp)
.Lcc:
        jmp *%rax
.Lce:
        jmp *(%rbp)
Note: See TracTickets for help on using tickets.