Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#7600 closed bug (fixed)

cgrun044 failing with LLVM backend

Reported by: dterei Owned by: dterei
Priority: normal Milestone:
Component: Compiler (LLVM) Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: 3676 Differential Rev(s):
Wiki Page:


test case cgrun044 fails currently with the LLVM backend. I believe this started with the switch to the new-code-generator.

LLVM fails to compile the file due to an invalid floating point constant:

/Users/davidt/bin/opt: Bug31.ll:23:155: error: floating point constant invalid for type
@Bug31_floatzunumber_closure =  global %Bug31_floatzunumber_closure_struct<{i64 ptrtoint ([0 x i64]* @ghczmprim_GHCziTypes_Fzh_static_info to i64), float 0x7F800000, i32 0}>

This is an old, annoying bug needing to be fixed for about the third time. Basically, LLVM requires all floating points (float, doubles...) be printed in IEEE 754 Double format, even single precision numbers (float). However, it expects types labeled float to be representable in IEEE 754 Single precision format...

So what we do is store all floating point numbers as Double and then narrow those that are Float by trying to do 'Double -> Float -> Double'. Then we can use the same machinery to produce the output for LLVM.

Annoying, GHC seems to like to optimize away these narrowing operations. If it should or shouldn't do that is questionable. I'd argue it shouldn't, but oh well.

The new-code-generator seems to have defeated existing techniques for stopping the optimizer firing.

Change History (6)

comment:1 Changed 4 years ago by dterei

Rather than use 'realToFrac', using the underlying operations from 'GHC.Float' of 'float2Double' and 'double2Float' seem to work and narrow as expected.

comment:2 Changed 4 years ago by dterei

Actually, this doesn't seem to be due to the narrowing become a null op. It is that 'realToFrac' behaves differently with optimisations turned on or off. double2Float and co, don't seem to suffer from this. Ticket #3676 is probably related.

comment:3 Changed 4 years ago by simonpj

difficulty: Unknown

I wonder if there is a rewrite RULE for realToFrac but not for double2Float?

comment:4 Changed 4 years ago by davidterei@…

commit 25f8d040a6e151237c84be380179b3c6ffb9a34c

Author: David Terei <>
Date:   Wed Jan 16 20:16:28 2013 -0800

    Fix floating point constants in LLVM backend (#7600).

 compiler/llvmGen/Llvm/Types.hs |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

comment:5 Changed 4 years ago by dterei

Resolution: fixed
Status: newclosed

comment:6 Changed 4 years ago by dterei

Simon, I thought there may be. I haven't bothered to look further at what exactly causes the difference between using 'realToFrac' Vs. 'double2Float' when optimizations are on Vs. off. FP is a scary and painful world that I don't have the courage for :).

Note: See TracTickets for help on using tickets.