[GHC] #8901: (very) bad inline heuristics

#8901: (very) bad inline heuristics ------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- I observe a bad case for inlining blowup for the time library. Observed for 7.7, just checked in 7.9. The problem is so bad that the PowerPC32 assembler cannot resolve cross- routine references. (I have no error message at hand, but could try to get one.) Instead here are the stats for x86, with inlining and certain inlining suppressed. The architecture seems irrelevant. {{{ $ file ./libraries/time/dist-install/build/Data/Time/Format.o ./libraries/time/dist-install/build/Data/Time/Format.o: Mach-O object i386 $ ls -l ./libraries/time/dist-install/build/Data/Time/Format.* -rw-r--r-- 1 ggreif staff 61875 Mar 15 16:48 ./libraries/time/dist- install/build/Data/Time/Format.dyn_hi -rw-r--r-- 1 ggreif staff 450864 Mar 15 16:48 ./libraries/time/dist- install/build/Data/Time/Format.dyn_o -rw-r--r-- 1 ggreif staff 61863 Mar 15 16:48 ./libraries/time/dist- install/build/Data/Time/Format.hi -rw-r--r-- 1 ggreif staff 332216 Mar 15 16:48 ./libraries/time/dist- install/build/Data/Time/Format.o }}} With following patch applied: <https://github.com/ggreif/packages- time/commit/83f08b8896b950707a910fed4e30bddb7ee7f52f> I get: {{{ $ ls -l ./libraries/time/dist-install/build/Data/Time/Format.* -rw-r--r-- 1 ggreif staff 10554 Mar 16 00:08 ./libraries/time/dist- install/build/Data/Time/Format.dyn_hi -rw-r--r-- 1 ggreif staff 106832 Mar 16 00:08 ./libraries/time/dist- install/build/Data/Time/Format.dyn_o -rw-r--r-- 1 ggreif staff 10542 Mar 16 00:08 ./libraries/time/dist- install/build/Data/Time/Format.hi -rw-r--r-- 1 ggreif staff 78864 Mar 16 00:08 ./libraries/time/dist- install/build/Data/Time/Format.o }}} The factor is 4.2 for Format.o, Format.dyn_o and 5.8 for the .hi files. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by Ashley Yakeley): It's not clear to me whether this should be considered a bug in the time library or a bug in GHC. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by trommler): Replying to [ticket:8901 heisenbug]:
The problem is so bad that the PowerPC32 assembler cannot resolve cross- routine references. (I have no error message at hand, but could try to get one.) FWIW The powerpc issue in the time library (#7830) was fixed by @erikd.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Can you explain what the bug in GHC is? And (as Ashley asks) why you believe it's a bug in GHC and not the library? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by heisenbug): Replying to [comment:3 simonpj]:
Can you explain what the bug in GHC is? And (as Ashley asks) why you believe it's a bug in GHC and not the library?
It is hard to pinpoint. There has been some rope-pulling between me and Ashley (on the dev list/in private) as he has not been keen of accepting my patch (so far) asking whether it could be a GHC bug. I tend to agree, as a quality inliner should not attempt to inline (e.g.) `formatTime` which has 8 alternatives and is called from 10+ sites. It would be interesting to see whether any bloat-controlling measures failed detecting this case, esp. as `Format.hs` appears to be a relatively benign source file. Some lessons might be learnt from this. OTOH, a library author should keep in eye how popular compilers digest the lib. I am ending up stuck between a rock and a hard place. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by Ashley Yakeley):
The problem is so bad that the PowerPC32 assembler cannot resolve cross- routine references. (I have no error message at hand, but could try to get one.)
This might be helpful. If GHC cannot compile a correct program with a correct time library to PowerPC32, that would surely be a bug in GHC, would it not? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------ Reporter: heisenbug | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): Not necessarily. It's not hard to give GHC a heart attack by inlining too aggressively. If you can exhibit a case where you think GHC is inlining where it shouldn't I'll gladly look at it. For example you mention `formatTime`; can you give a test case? Eg a test file with 10+ calls, that all inline when they shouldn't? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => infoneeded -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by heisenbug): Replying to [comment:2 trommler]:
Replying to [ticket:8901 heisenbug]:
The problem is so bad that the PowerPC32 assembler cannot resolve cross-routine references. (I have no error message at hand, but could try to get one.) FWIW The powerpc issue in the time library (#7830) was fixed by @erikd.
But that bug (#7830) is not closed yet! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by erikd): * cc: erikd (added) Comment: #7830 was closed for some time, but was re-opened just recently. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * status: infoneeded => closed * resolution: => invalid Comment: Please reopen if you plan on reinvestigating, it doesn't seem like any more progress is going to be made. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by heisenbug): Here come the latest stats (with today's GHC HEAD) : {{{ $ ls -l ./libraries/time/dist-install/build/Data/Time/Format.*o -rw-r--r-- 1 ggreif lb40 482568 Jan 12 16:24 ./libraries/time/dist- install/build/Data/Time/Format.dyn_o -rw-r--r-- 1 ggreif lb40 514776 Jan 12 16:24 ./libraries/time/dist- install/build/Data/Time/Format.o $ wc -l ./libraries/time/lib/Data/Time/Format.hs 254 ./libraries/time/lib/Data/Time/Format.hs $ strip ./libraries/time/dist-install/build/Data/Time/Format.*o $ ls -l ./libraries/time/dist-install/build/Data/Time/Format.*o -rw-r--r-- 1 ggreif lb40 201512 Jan 12 17:26 ./libraries/time/dist- install/build/Data/Time/Format.dyn_o -rw-r--r-- 1 ggreif lb40 187712 Jan 12 17:26 ./libraries/time/dist- install/build/Data/Time/Format.o $ ghc -e "187712/254" 739.0236220472441 }}} As you can see a single line of Format.hs gets compiled to 739 stripped bytes. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8901: (very) bad inline heuristics -------------------------------------+------------------------------------- Reporter: heisenbug | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: invalid | Keywords: Inlining Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by heisenbug): * keywords: => Inlining -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8901#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC