Opened 5 years ago

Closed 5 years ago

#3182 closed bug (fixed)

Bad FP code generated by x86_64 native code generator.

Reported by: igloo Owned by: benl
Priority: normal Milestone: 6.12.1
Component: Compiler (NCG) Version: 6.11
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

With this module:

main :: IO ()
main = mapM_ print $ map log2 vals

log2 :: Int -> Double
log2 x = logBase 2 (fromIntegral x)

vals :: [Int]
vals = [1, 2, 17]

on amd64/Linux with the HEAD, I'm seeing:

$ ghc -fforce-recomp -O -fregs-graph -o num012 num012.hs; ./num012
0.0
1.2607434391239006e13
5.153241959769104e13

Ben, are you able to take a look please?

Change History (6)

comment:1 Changed 5 years ago by benl

  • Status changed from new to assigned

comment:2 follow-up: Changed 5 years ago by benl

  • Owner changed from benl to nobody
  • Status changed from assigned to new

This is actually a bug in the x86_64 native code generator:

Compiling libraries/base/GHC/Float.lhs..

-ddump-opt-cmm

GHC.Float.$wlogBase_entry()
    ...
    (_s4aK::F64,) = foreign "ccall"
                    MO_F64_Log((_c74u::F64,))[_unsafe_call_];
    D1 = %MO_F_Quot_W64(_s4aJ::F64, _s4aK::F64);
    jump I64[Sp] ();

-ddump-asm-liveness

GHC.Float.$wlogBase_entry()
    ...
    call log
    ...
    movss %xmm0,%vD_s4aK
        # born:    %vD_s4aK
        # r_dying: %r16

    movsd %vD_s4aJ,%xmm5
        # r_dying: %vD_s4aJ

    divsd %vD_s4aK,%xmm5
        # r_dying: %vD_s4aK

    jmp *(%rbp)

The result of the divsd instruction, %vD_s4aK hasn't been assigned anywhere particular. The linear allocator happens to put it in %xmm0, so it works. The graph allocator happens to put it in %xmm7, so it doesn't.

comment:3 Changed 5 years ago by benl

  • Summary changed from Bad code generated with -fregs-graph to Bad FP code generated by x86_64 native code generator.

comment:4 Changed 5 years ago by benl

  • Architecture changed from Unknown/Multiple to x86_64 (amd64)

comment:5 in reply to: ↑ 2 Changed 5 years ago by benl

  • Owner changed from nobody to benl
  • Status changed from new to assigned

Scratch that, I'm reading the instrs the wrong way around :P. It'll be because it's using movss instead of movsd. Patch pending.

comment:6 Changed 5 years ago by benl

  • Resolution set to fixed
  • Status changed from assigned to closed

Fri Apr 24 16:50:53 EST 2009 Ben.Lippmeier@…

  • Fix #3182: 64 bit FP value returned by C calls was getting trashed

movss instruction was being used to move the result into the
destination register instead of movsd

Note: See TracTickets for help on using tickets.