[GHC] #8855: LLVM backend needs to use `-globalopt` explicitly
#8855: LLVM backend needs to use `-globalopt` explicitly ------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- While `-O1` and `-O2` includes a `-globalopt` pass, for reasons I don't entirely understand the location of the pass is such that not all aliases are eliminated. My `ghc-7.8` branch includes a patch fixing this (as well as removing ARM from the dynamic linking blacklist)[1]. [1] https://github.com/bgamari/ghc/commits/ghc-7.8 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by bgamari): * status: new => patch -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 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 scpmw): The issue here is that GHC code somewhat randomly refuses to compile with LLVM 3.4, with an error along the lines of: {{{ LLVM ERROR: .LnewCAF$alias: Target doesn't support aliases to declarations }}} These `$alias` definitions are forward references used by the LLVM backend where it can not derive the exact type of a symbol yet due to it either being a global symbol. That can happen because either the symbol is external, or because it is part of another `CmmGroup` (which we can't see due to streaming). In either case we rely on these aliases getting eliminated by the `-globalopt` optimisation pass, much in the same way we are relying on `-mem2reg` to remove `alloca`s. This is the reason we already pass `-globalopt` explicitly for `-O0`. For `-O1` and `-O2` the `-globalopt` pass is always active, so we don't run it twice. What seems to happen here that in spite of the `-globalopt` pass getting run, a few `$alias$` definitions survive: {{{ $ llvm-3.4-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias @"base_GHCziChar_chr2_info$alias" = alias private i8* @base_GHCziChar_chr2_info }}} Especially note that we only find a definition, but no usage site. So it might simply be dead code detection not doing its job to completion. Notably, this behaviour doesn't happen for any of the previous LLVM versions: {{{ $ llvm-3.3-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-3.2-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-3.1-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-3.0-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-2.9-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-2.8-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias $ llvm-2.7-build/bin/opt bgamari/History.ll -O1 -S -o - | grep \$alias }}} And it vanishes for both `-O1 -globalopt` as well as `-O2` for LLVM 3.4: {{{ $ llvm-3.4-build/bin/opt bgamari/History.ll -O1 -globalopt -S -o - | grep \$alias $ llvm-3.4-build/bin/opt bgamari/History.ll -O2 -S -o - | grep \$alias }}} Bottom line is that `-O1 -globalopt` is positively needed for LLVM 3.4. On the other hand, it's up for discussion whether we want it 1. for `-O2`. I would vote no, it probably does multiple passes already, at which point we should *really* except all remainders to be gone. 2. for other LLVM versions. Unsure about that one. It only started happening very recently, and that a lone definition survives with `-O1` smells like a bug. On the other hand, without having any numbers I would estimate that `-globalopt` is one of the cheaper optimization passes. In the end, I would favour doing: {{{ llvmOpts = ["-mem2reg -globalopt" , if ver >= 34 then "-O1 -globalopt" else "-O1" -- LLVM 3.4 -O1 doesn't eliminate aliases reliably , "-O2"] }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 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 bgamari): I'll update my patch accordingly. Thanks for the analysis! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 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 bgamari): How does this[1] look? https://github.com/bgamari/ghc/compare/ghc:ghc-7.8...fixes?expand=1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc1 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 scpmw): Yes, that's basically my suggestion. Can't say anything about the dynamic linking blacklist change though, that should probably be a different ticket? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by thoughtpolice): * version: 7.8.1-rc1 => 7.8.1-rc2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 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 Austin Seipp <austin@…>): In [changeset:"b84b5da4430aacd5bf8422b06a861cd0584f99cf/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="b84b5da4430aacd5bf8422b06a861cd0584f99cf" DriverPipeline: Ensure -globalopt is passed to LLVM opt While -O1 and -O2 both include -globalopt, the order in which the passes are run means that aliases aren't resolved which then causes llc to fall over. See GHC bug #8855. Signed-off-by: Austin Seipp <austin@well-typed.com> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: merge Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by thoughtpolice): * status: patch => merge -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Merged in 7.8. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8855: LLVM backend needs to use `-globalopt` explicitly -------------------------------------+------------------------------------ Reporter: bgamari | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: 7.8.1-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by bgamari): Could you possibly merge `config.mk.in: ARM now supports dynamic linking with the LLVM backend` (https://github.com/ghc/ghc/commit/d574fcbba09fd6c9d10a79e19daf5f15bb0a6cde) to `ghc-7.8` as well? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8855#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC