Ticket #1916 (closed merge: fixed)

Opened 5 years ago

Last modified 4 years ago

compiling truncate :: Float -> Int with -O2 panics ghc

Reported by: conal Owned by: igloo
Priority: normal Milestone: 6.8.2
Component: Compiler Version: 6.8.1
Keywords: Cc: conal@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Easy (less than 1 hour)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

bash-3.2$ cat Bug.hs
{-# OPTIONS -fglasgow-exts -O2 #-}
module Bug (tst) where
tst :: Float -> Bool
tst x = truncate x > (0::Int)

bash-3.2$ ghc Bug.hs
ghc.exe: panic! (the 'impossible' happened)
  (GHC version 6.8.1.20071102 for i386-unknown-mingw32):
	narrowTo
Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Same results reported on linux.

Attachments

ghc-6.9-narrowS.patch Download (18.0 KB) - added by int-e 5 years ago.
proposed patch

Change History

Changed 5 years ago by int-e

proposed patch

Changed 5 years ago by int-e

  • difficulty set to Easy (1 hr)

The code contains an expression of the form (comparison (conversion expr) int-literal). In cmmMachOpFold, the CMM optimizer tries to narrow the literal down to the type of expr, to see if it fits and the conversion can be eliminated. However this narrowing fails if expr has a floating point type. And that's good, because the optimization is not valid in that case.

The patch changes cmmMachOpFold to not even attempt narrowing to floating point types.

It fixes the example above.

Affected architectures are x86 and x86_64 as it seems.

Changed 5 years ago by igloo

  • milestone set to 6.8.2

Thanks for the report, and for the patch! Let's try to look at this for 6.8.2.

Changed 5 years ago by simonmar

  • owner set to simonmar

mine

Changed 5 years ago by simonmar

  • owner changed from simonmar to igloo
  • type changed from bug to merge

applied.

Thu Nov 22 09:55:13 GMT 2007  Bertram Felgenhauer <int-e@gmx.de>
  * FIX #1916: don't try to convert float constants to int in CMM optimizer

Changed 5 years ago by igloo

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

Merged

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 4 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)
Note: See TracTickets for help on using tickets.