Opened 5 years ago

Last modified 4 months ago

#3831 new bug

SpecConstr should exploit cases where there is exactly one call pattern

Reported by: igloo Owned by: simonpj
Priority: normal Milestone: 7.12.1
Component: Compiler Version: 6.13
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case: simplCore/should_compile/T3831
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

On x86/Linux, with this mk/build.mk:

GhcLibWays = v p dyn
SRC_HC_OPTS     = -O -H64m -Rghc-timing
GhcStage1HcOpts = -O -fasm
GhcStage2HcOpts = -O2 -fasm
GhcHcOpts       = -Rghc-timing
GhcLibHcOpts    = -O2 -XGenerics

#SplitObjs          = YES
SplitObjs          = NO
HADDOCK_DOCS       = NO
BUILD_DOCBOOK_HTML = NO
BUILD_DOCBOOK_PS   = NO
BUILD_DOCBOOK_PDF  = NO

# -----------------------------------------------------------------------------
# Other settings that might be useful

# profiled RTS
#GhcRtsCcOpts =  -pg -g

# Optimised/profiled RTS
#GhcRtsCcOpts = -O2 -pg

#GhcRtsWithFrontPanel = YES
#SRC_HC_OPTS += `gtk-config --libs`

# NoFib settings
NoFibWays =
STRIP=:

and these commands:

$ sh boot
$ ./configure --prefix=/opt/ghc-6.13
$ make

and a 1GB memory limit (ulimit -v 1024000), the build fails with:

"inplace/bin/ghc-stage1"   -O -H64m -Rghc-timing    -package-name terminfo-0.3.1.1 -hide-all-packages -i -ilibraries/terminfo/. -ilibraries/terminfo/dist-install/build -ilibraries/terminfo/dist-install/build/autogen -Ilibraries/terminfo/dist-install/build -Ilibraries/terminfo/dist-install/build/autogen -Ilibraries/terminfo/.    -optP-include -optPlibraries/terminfo/dist-install/build/autogen/cabal_macros.h -package base-4.2.0.0 -package extensible-exceptions-0.1.1.1  -Wall -XForeignFunctionInterface -XDeriveDataTypeable -XEmptyDataDecls -XScopedTypeVariables -XFlexibleInstances -O2 -XGenerics -fno-warn-deprecated-flags     -odir libraries/terminfo/dist-install/build -hidir libraries/terminfo/dist-install/build -stubdir libraries/terminfo/dist-install/build -hisuf hi -osuf  o -hcsuf hc -c libraries/terminfo/./System/Console/Terminfo/Effects.hs -o libraries/terminfo/dist-install/build/System/Console/Terminfo/Effects.o
ghc-stage1: out of memory (requested 1048576 bytes)
make[1]: *** [libraries/terminfo/dist-install/build/System/Console/Terminfo/Effects.o] Error 1
make: *** [all] Error 2

With -v:

Glasgow Haskell Compiler, Version 6.13.20100120, for Haskell 98, stage 1 booted 
by GHC version 6.8.2
Using binary package database: /home/ian/qq/ghc/inplace/lib/package.conf.d/packa
ge.cache
wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-inplace
wired-in package integer-gmp mapped to integer-gmp-0.2.0.0-inplace
wired-in package base mapped to base-4.2.0.0-inplace
wired-in package rts mapped to builtin_rts
wired-in package haskell98 mapped to haskell98-1.0.1.1-inplace
wired-in package template-haskell mapped to template-haskell-2.4.0.0-inplace
wired-in package dph-seq mapped to dph-seq-0.4.0-inplace
wired-in package dph-par mapped to dph-par-0.4.0-inplace
Hsc static flags: -static
Created temporary directory: /tmp/ghc1791_0
*** Checking old interface for terminfo-0.3.1.1:System.Console.Terminfo.Effects:
*** Parser:
*** Renamer/typechecker:
*** Desugar:
    Result size = 1076
*** Simplifier gentle[rules,no inline] max-iterations=4:
    Result size = 802
    Result size = 758
    Result size = 758
*** Specialise:
    Result size = 758
*** Float out(not lambdas, constants):
    Result size = 826
*** Float inwards:
    Result size = 826
*** Simplifier Phase 2 [main] max-iterations=4:
    Result size = 1499
    Result size = 2190
    Result size = 2994
    Result size = 2380
    Result size = 2380
*** Simplifier Phase 1 [main] max-iterations=4:
    Result size = 2145
    Result size = 2115
*** Simplifier Phase 0 [main] max-iterations=4:
    Result size = 2115
*** Demand analysis:
    Result size = 2115
*** Worker Wrapper binds:
    Result size = 2115
*** Glom binds:
*** GlomBinds:
    Result size = 2115
*** Simplifier Phase 0 [post-worker-wrapper] max-iterations=4:
    Result size = 2115
*** Float out(not lambdas, constants):
    Result size = 2121
*** Common sub-expression:
    Result size = 2102
*** Float inwards:
    Result size = 2102
*** Liberate case:
    Result size = 2102
*** Simplifier Phase 0 [post-liberate-case] max-iterations=4:
    Result size = 2082
    Result size = 2082
*** SpecConstr:
ghc-stage1: out of memory (requested 1048576 bytes)

Change History (13)

comment:1 Changed 5 years ago by igloo

  • Version changed from 6.12.1 to 6.13

This was compiling the HEAD; 6.12 not tested.

comment:2 Changed 5 years ago by simonpj

  • Summary changed from GHC uses too much memory compiling terminfo to SpecConstr should exploit cases where there is exactly one call pattern
  • Test Case set to simplCore/should_compile/T3831

I've fixed the blowup with

Mon Feb  1 00:24:20 GMT Standard Time 2010  [email protected]
  * Fix Trac #3831: blowup in SpecConstr
  
  It turned out that there were two bugs.  First, we were getting an
  exponential number of specialisations when we had a deep nest of
  join points.  See Note [Avoiding exponential blowup]. I fixed this
  by dividing sc_count (in ScEnv) by the number of specialisations
  when recursing.  Crude but effective.
  
  Second, when making specialisations I was looking at the result of
  applying specExpr to the RHS of the function, whereas I should have
  been looking at the original RHS.  See Note [Specialise original
  body].
  
  
  There's a tantalising missed opportunity here, though.  In this
  example (recorded as a test simplCore/should_compile/T3831), each join
  point has *exactly one* call pattern, so we should really just
  specialise for that alone, in which case there's zero code-blow-up.
  In particular, we don't need the *original* RHS at all.  I need to think
  more about how to exploit this.
  
  But the blowup is now limited, so compiling terminfo with -O2 works again.

I'm going to leave the ticket open because of the "tantalising opportunity", but I'll retitle it.

Simon

comment:3 Changed 5 years ago by simonmar

Does the bug need fixing in the 6.12 branch, or should it be re-milestoned?

comment:4 Changed 5 years ago by simonmar

  • Milestone changed from 6.12.2 to 6.14 branch

Simon says it doesn't need fixing in 6.12, so moving the ticket to the 6.14 branch.

comment:5 Changed 5 years ago by igloo

  • Milestone changed from 6.14 branch to 6.14.1

comment:6 Changed 5 years ago by igloo

  • Owner set to simonpj

comment:7 Changed 5 years ago by simonpj

  • Milestone changed from 7.0.1 to 7.2.1

Bumping this to 7.2.

Simon

comment:8 Changed 3 years ago by simonpj

  • difficulty set to Unknown
  • Milestone changed from 7.4.1 to 7.6.1

Punting to 7.6

comment:9 Changed 3 years ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:10 Changed 2 years ago by igloo

  • Milestone changed from 7.6.2 to 7.8.1

comment:11 Changed 12 months ago by thoughtpolice

  • Milestone changed from 7.8.3 to 7.10.1

Bumping priority down (these tickets haven't been closely followed or fixed in 7.4), and moving out to 7.10 and out of 7.8.3.

comment:12 Changed 12 months ago by thoughtpolice

  • Priority changed from high to normal

Actually dropping priority. :)

comment:13 Changed 4 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

Note: See TracTickets for help on using tickets.