[GHC] #7571: LLVM codegen does not handle integer literals in branch conditionals.

#7571: LLVM codegen does not handle integer literals in branch conditionals. --------------------------------+------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: new Priority: normal | Component: Compiler (LLVM) Version: 7.6.1 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Building GHC failed | Blockedby: Blocking: | Related: --------------------------------+------------------------------------------- When compiling GHC HEAD on my ODROID-U2 ARM machine, running Ubuntu 12.10, with LLVM 3.3svn, I get this error while building part of the RTS: {{{ linaro@linaro-ubuntu-desktop ~/code/ghc % "inplace/bin/ghc-stage1" -static -prof -H32m -O -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist- ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS -package-name rts -dcmm-lint -i -irts -irts/dist/build -irts/dist/build/autogen -Irts/dist/build -Irts/dist/build/autogen -optc-O2 -O2 -c rts/StgStdThunks.cmm -o rts/dist/build/StgStdThunks.p_o You are using a new version of LLVM that hasn't been tested yet! We will try though... ghc-stage1: panic! (the 'impossible' happened) (GHC version 7.7.20130111 for arm-unknown-linux): LlvmCodeGen.CodeGen.genCondBranch: Cond expr not bool! (i32 1) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug linaro@linaro-ubuntu-desktop ~/code/ghc % }}} The reason is that StgStdThunks.cmm does something like: {{{ #ifdef FOO #define THING(x) 1 #else #define THING(x) do_something((x)) #endif ... if (THING(x)) { ... } }}} Depending on if FOO is defined, the conditional could have an expression or a literal in the branch head. This is directly fed into the backend from the compiler. LlvmCodeGen.CodeGen.genLit does not properly narrow the type of the literal from i32 to i1 when generating the code, causing a compiler panic. We would have likely never seen this outside hand-written Cmm, since the code generator would otherwise trivially eliminate such branches in the optimizers. Coincidentally, I would imagine this failure would mean that the compiler has not been able to bootstrap with LLVM for quite some time. I haven't bisected this, but I'd speculate it was some time around the switch to the NCG. I believe I have a fix for this that I am testing on my machine. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals.
--------------------------------+-------------------------------------------
Reporter: thoughtpolice | Owner: thoughtpolice
Type: bug | Status: patch
Priority: normal | Component: Compiler (LLVM)
Version: 7.6.1 | Keywords: llvm, codegen
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: Building GHC failed | Blockedby:
Blocking: | Related:
--------------------------------+-------------------------------------------
Changes (by thoughtpolice):
* status: new => patch
Comment:
I have verified my patch fixes the build of StdStgThunks.cmm on my ODROID.
More ARM build failures are still in my way, but nonetheless this patch
should be merged for everyone since it fixes compiler bootstrapping with
LLVM.
I also added a hefty note explaining the change.
{{{
commit 0de9754d06c8ca57e781bb829931ff7cdc861344
Author: Austin Seipp

#7571: LLVM codegen does not handle integer literals in branch conditionals. --------------------------------+------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Building GHC failed | Blockedby: Blocking: | Related: --------------------------------+------------------------------------------- Changes (by thoughtpolice): * cc: mad.one@… (added) * version: 7.6.1 => 7.7 -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. --------------------------------+------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Building GHC failed | Blockedby: Blocking: | Related: --------------------------------+------------------------------------------- Comment(by thoughtpolice): I will have a test for this shortly I hope. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals.
--------------------------------+-------------------------------------------
Reporter: thoughtpolice | Owner: thoughtpolice
Type: bug | Status: patch
Priority: normal | Component: Compiler (LLVM)
Version: 7.7 | Keywords: llvm, codegen
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: Building GHC failed | Blockedby: 7573
Blocking: | Related:
--------------------------------+-------------------------------------------
Changes (by thoughtpolice):
* blockedby: => 7573
Comment:
The attached patch for the testsuite correctly tickles this condition and
I've verified it independently on my Mac OS X machine.
{{{
commit 62067fcf7dd6b8da9fcc76677a1c1cb59e9eff1d
Author: Austin Seipp

#7571: LLVM codegen does not handle integer literals in branch conditionals. --------------------------------+------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Building GHC failed | Blockedby: 7573 Blocking: | Related: --------------------------------+------------------------------------------- Comment(by thoughtpolice): See also #7574. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by thoughtpolice): * failure: Building GHC failed => Compile-time crash -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: #7574 -------------------------------+-------------------------------------------- Changes (by thoughtpolice): * related: => #7574 -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: #7574 -------------------------------+-------------------------------------------- Comment(by altaic): Indeed, building HEAD on OS X x86_64 with llvm was broken before due to this bug. Thanks for the fix! -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: #7574, #7575 -------------------------------+-------------------------------------------- Changes (by thoughtpolice): * related: #7574 => #7574, #7575 -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: #7574, #7575 -------------------------------+-------------------------------------------- Comment(by dterei): Great! Thanks Austin. Yes the switch to the NCG and also LLVM 3.2 release both haven't been tested properly so those are the bugs you are running into, let alone 3.3. This bug seems a regression from memory. I'll try to look at these soon and merge. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. -------------------------------+-------------------------------------------- Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Component: Compiler (LLVM) Version: 7.7 | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Blockedby: 7573 Blocking: | Related: #7574, #7575 -------------------------------+-------------------------------------------- Comment(by thoughtpolice): Thanks David! I would like to get the ARM build shaped up before 7.8 (before, eventually, GHC > 7.8 requires > 7.4 to build, and ARM becomes drastically more difficult,) so I will probably be submitting more patches as I find problems. There are a few more beyond just ARM (you can look at the other tickets I've filed,) so any help is greatly appreciated. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573 | Blocking: Related: #7574, #7575 | ---------------------------------+------------------------------------------ Changes (by simonmar): * difficulty: => Unknown Comment: Ok by me. I think we should clarify that `CmmCondBranch` can have an arbitrary expression as the conditional, and it should be a word-sized integral with non-zero meaning true. The alternative is to declare that the argument to `CmmCondBranch` must be a conditional, but I think that would be worse: we wouldn't be able to unconditionally rewrite "1 == 2" to zero everywhere, we would probably need dummy "ALWAYS" and "NEVER" conditionals. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by dterei): Austin, can you explain your setup please? All these bugs you are filing and fixing are ones I fixed in some form 2 years ago. The existing llvm backend contains code to do exactly what the bug description describes, narrow arbritry expressions to a boolean when used as a conditional. I can also currently bootstrap GHC with LLVM fine on both OSX 10.8 and Linux. (Both 64 bit). Are you cross compiling? Or compiling on a 64bit OSX machine but producing a 32bit GHC? I think the backend may have bugs to do with this as it makes assumptions about word sizes... and so detection of various cases that need to be avoided aren't firing. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by thoughtpolice): David, I gave an extensive reply in #7580, please let me know what you think. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by simonmar): Replying to [comment:16 dterei]:
I think the backend may have bugs to do with this as it makes assumptions about word sizes... and so detection of various cases that need to be avoided aren't firing.
David, could you be more specific here? I'm not aware of any problems of this kind. If you have suspicions about lurking problems that might affect cross-compilation, let's get some tickets filed. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by dterei): Off the top of my head I think one issue will be that the LLVM backend has some code that is dependent on the endianness of the platform. It's just decided with an ifdef at compilation time... Right now I'm handling the existing LLVM issues that Austin is filing but will look into cross compilation after that. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by thoughtpolice): OK, with the latest copy of GHC HEAD, LLVM 3.2 and GHC 7.6.1 as the bootstrap compiler on my Mac OS X machine, I no longer hit this ''during the build''. (My build still fails later on - looks like it might be #7588 still.) However, I speculate this is still a bug, because if you compile the attached test case with the compiler using the LLVM backend, it still trips the build even though it looks like I built the RTS successfully. So I think this should still be fixed. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by dterei): OK Cool Austin! I'll run your test cases for each bug and see. I'm glad at least we seem to be more on the same page now. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Keywords: llvm, codegen | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Compile-time crash Difficulty: Unknown | Testcase: Blockedby: 7573, 7590 | Blocking: 7588, 7589 Related: #7574, #7575 | ---------------------------------+------------------------------------------ Comment(by dterei): OK yes, indeed the test fails and looking at the patch that is very expected. Applied patch works as expected. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals.
---------------------------------+------------------------------------------
Reporter: thoughtpolice | Owner: thoughtpolice
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler (LLVM) | Version: 7.7
Keywords: llvm, codegen | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: Compile-time crash
Difficulty: Unknown | Testcase:
Blockedby: 7573, 7590 | Blocking: 7588, 7589
Related: #7574, #7575 |
---------------------------------+------------------------------------------
Comment(by mad.one@…):
commit 14c01e0966da2edf9b770651ce1a4ca6a206eb20
{{{
Author: Austin Seipp

#7571: LLVM codegen does not handle integer literals in branch conditionals. ---------------------------------+------------------------------------------ Reporter: thoughtpolice | Owner: thoughtpolice Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (LLVM) | Version: 7.7 Resolution: fixed | Keywords: llvm, codegen Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Compile-time crash | Difficulty: Unknown Testcase: | Blockedby: 7573 Blocking: 7588, 7589, 7590 | Related: #7574, #7575 ---------------------------------+------------------------------------------ Changes (by dterei): * status: patch => closed * resolution: => fixed -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7571#comment:26 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7571: LLVM codegen does not handle integer literals in branch conditionals.
---------------------------------+------------------------------------------
Reporter: thoughtpolice | Owner: thoughtpolice
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler (LLVM) | Version: 7.7
Resolution: fixed | Keywords: llvm, codegen
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: Compile-time crash | Difficulty: Unknown
Testcase: | Blockedby: 7573
Blocking: 7588, 7590 | Related: #7574, #7575
---------------------------------+------------------------------------------
Comment(by davidterei@…):
commit 1a703068117255592fb8d9d8d47a5d54640208d0
{{{
Author: David Terei
participants (1)
-
GHC