[GHC] #13518: CMM compiles with 8.0.2, fails with git HEAD
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Other Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I'm trying to implement `Float` <-> `Word32` bit casts (`Double` <-> `Word64` works fine) in CMM using: {{{ stg_word32ToFloatzh(I32 w) { F_ f; P_ ptr; STK_CHK_GEN_N (FLOAT_STACK_WDS); reserve FLOAT_STACK_WDS = ptr { I32[ptr] = w; f = F_[ptr]; } return (f); } stg_floatToWord32zh(F_ f) { I32 w; P_ ptr; STK_CHK_GEN_N (FLOAT_STACK_WDS); reserve FLOAT_STACK_WDS = ptr { I32[ptr] = f; w = I32[ptr]; } return (w); } }}} This compiles correctly and passes all tests with ghc 8.0.2, but compiling the above CMM with git HEAD (currently 1e58efb16f7) results in: {{{ Cmm lint error: in basic block cq in assignment: _cj::I32 = R1; Reg ty: I32 Rhs ty: I64 Program was: {offset cq: // global _cj::I32 = R1; //tick src<rts/CastFloatWord.cmm:(49,1)-(61,1)> goto cm; cm: // global if ((old + 0) - 8 / 8 < SpLim) (likely: False) goto co; else goto cp; co: // global I64[(young<cn> + 8)] = cn; call stg_gc_noregs() returns to cn, args: 8, res: 8, upd: 8; cn: // global goto cm; cp: // global _cl::P64 = (old + 16); //tick src<rts/CastFloatWord.cmm:(55,29)-(58,5)> I32[_cl::P64] = _cj::I32; _ck::F32 = F32[_cl::P64]; F1 = _ck::F32; call (P64[(old + 8)])(F1) args: 8, res: 0, upd: 8; } }}} ghc 8.0.2 is accepts this code and gives the correct results, so I can only assume that git HEAD is incorrect. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by erikd): * failure: Other => Incorrect error/warning at compile-time -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Assuming that this is on a 64-bit machine it seems to me that the Cmm lint error here is absolutely correct. You are assigning a 64-bit value to a 32-bit register. You would need to use one of the narrowing operations to do this correctly. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): To clarify, I think this would need to look something like, {{{ reserve FLOAT_STACK_WDS = ptr { I32[ptr] = %sx32(w); f = F_[ptr]; } -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): I tried the `%sx32` but get the same error. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by slyfox): * cc: slyfox (added) Comment: I've found a few issues: - the implementations are slightly nonsymmetric (floatToWord# lacked F_ cast) - i suspect cmm won't allow you to have non-Word sized integrals (the first error you get) - integral return type should also be Word-sized That compiles for me on both 32/64 targets: {{{ #include "Cmm.h" stg_word32ToFloatzh(W_ w) { F_ f; P_ ptr; STK_CHK_GEN_N (1); reserve 1 = ptr { I32[ptr] = W_TO_INT(w); f = F_[ptr]; } return (f); } stg_floatToWord32zh(F_ f) { W_ w; P_ ptr; STK_CHK_GEN_N (1); reserve 1 = ptr { F_[ptr] = f; w = TO_W_(I32[ptr]); } return (w); } }}} {{{ $ m68k-unknown-linux-gnu-ghc -c a.cmm -dcmm-lint -O2 $ powerpc64le-unknown-linux-gnu-ghc -c a.cmm -dcmm-lint -O2 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd):
That compiles for me on both 32/64 targets:
With GHC git HEAD? I've got something that with with ghc 8.0.2, but I can't get it to work with HEAD. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by slyfox): The snippet from #comment:5 compiles on: powerpc64le-unknown-linux-gnu-ghc-8.3.20170402 changeset:852a43f360af09416d15777c8f10d704b5423a96 m68k-unknown-linux-gnu-ghc-8.3.20170403 changeset:1e58efb16f76b52c059d5e5d6c4c5d91c2abaad2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): Wow, something really subtle is going on. Pasting your exact code made it work. Using `FLOAT_STACK_WDS` set to `2` to get stack alignment correct didn't. It even passes the test! Just need to clean it up and get it up on Phab. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by erikd): * status: new => closed * resolution: => invalid Comment: Closing this. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Replying to [comment:8 erikd]:
Using `FLOAT_STACK_WDS` set to `2` to get stack alignment correct didn't.
I don't understand this comment: the Haskell stack is only word-aligned and the argument to `reserve` is in words, so it cannot unalign the stack. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): Cmm lint could still do a better job with the original program, as slyfox pointed out. * I believe `I32 w` in the formal argument list is meaningless, or misleading. I don't think `I32` is a possible type for a function argument. (Here it is wrong anyways since on the Haskell side you presumably intend to give the function the type `Word# -> Float#`.) * `I32[ptr] = f;` should be an error because `f` is a `F32` not `I32`. * Returning `I32` seems dubious for the same reason that accepting `I32` as an argument does. I think Cmm lint ought to catch all of these. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd):
I don't understand this comment: the Haskell stack is only word-aligned and the argument to reserve is in words, so it cannot unalign the stack.
On 32 but systems, `Double` is two words and on 64 bit systems, `Float` is half a word. I did have some CPP which tried to account for this and that is what was breaking when I first tries @slyfox's `TO_W_` technique.
I believe I32 w in the formal argument list is meaningless
So how does one express a `Word32` in a portable way in CMM? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13518: CMM compiles with 8.0.2, fails with git HEAD -------------------------------------+------------------------------------- Reporter: erikd | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton):
So how does one express a `Word32` in a portable way in CMM?
There is no 32-bit integral primitive Haskell type anyways, so the problem never arises. The definition of the Haskell type `Word32` is {{{#!hs data Word32 = W32# Word# }}} where all but the low 32 bits of the `Word#` are expected to be zero. So that's the interface you have to program to, in Cmm. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13518#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC