Ticket #995 (closed bug: fixed)

Opened 2 years ago

Last modified 2 months ago

Needless call to fromInteger for literals

Reported by: wolfgang Assigned to:
Priority: normal Milestone: 6.8.1
Component: Compiler Version: 6.7
Severity: minor Keywords:
Cc: Difficulty: Unknown
Test Case: N/A Architecture: Unknown/Multiple
Operating System: Unknown/Multiple

Description

For the code below, ghc 6.7 puts the literal 65 in a static closure (S#) and calls fromInteger on it.

import Foreign.C ( CChar )

foreign import ccall putchar :: CChar -> IO ()

main = putchar 65

GHC 6.7 generates the following code; note the static closure Main.lvl and the call to fromInteger:

==================== STG syntax: ====================
Main.lvl = NO_CCS GHC.Num.S#! [65];
SRT(Main.lvl): []
Main.main =
    \u []
        case GHC.Int.fromInteger Main.lvl of ds_sSd {
          GHC.Int.I8# ds1_sS2 ->
              let {
                sat_sSf =
                    \r [ds2_sS3]
                        case __ccall_GC putchar [ds1_sS2 ds2_sS3] of wild_sSe {
                          (##) ds3_sS7 -> (#,#) [ds3_sS7 GHC.Base.()];
                        };
              } in  sat_sSf;
        };
SRT(Main.main): []
:Main.main =
    \r srt:(0,*bitmap*) [eta_sSc] GHC.TopHandler.runMainIO Main.main eta_sSc;
SRT(:Main.main): [GHC.TopHandler.runMainIO, Main.main]

GHC 6.6 just passes the 65 to putchar as an unboxed constant.

Change History

11/12/06 13:55:28 changed by igloo

  • testcase set to N/A.
  • milestone set to 6.8.

01/03/07 07:37:45 changed by simonpj

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

Good bug. Turns out that there was a mistake in the optimiser, where it dealt with cast expressions. Thanks!

Simon

11/05/07 07:03:54 changed by igloo

  • milestone changed from 6.8 branch to 6.8.1.

09/30/08 08:45:06 changed by simonmar

  • architecture changed from Multiple to Unknown/Multiple.

09/30/08 08:54:44 changed by simonmar

  • os changed from Multiple to Unknown/Multiple.