[GHC] #8107: need types to express constant argument for primop correctness

#8107: need types to express constant argument for primop correctness ------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- (not sure if this is a bug or a feature request, or a task, or a dialogue, filing as a bug for now) a number of compiler intrinsics that GHC has started to support (prefetch) and will come to support (concurrent memory operations a la http://ghc.haskell.org/trac/ghc/ticket/7883), require certain arguments to be statically fixed at compile time {{{ primop PrefetchAddrOp "prefetchAddr#" GenPrimOp Addr# -> Int# -> Addr# with llvm_only = True }}} consider the specification on the llvm side for prefetch http://llvm.org/docs/LangRef.html#llvm-prefetch-intrinsic {{{ Syntax:¶ declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>) Overview: The ‘llvm.prefetch‘ intrinsic is a hint to the code generator to insert a prefetch instruction if supported; otherwise, it is a noop. Prefetches have no effect on the behavior of the program but can change its performance characteristics. Arguments: address is the address to be prefetched, rw is the specifier determining if the fetch should be for a read (0) or write (1), and locality is a temporal locality specifier ranging from (0) - no locality, to (3) - extremely local keep in cache. The cache type specifies whether the prefetch is performed on the data (1) or instruction (0) cache. The rw, locality and cache type arguments must be constant integers. }}} the punch line is that we're starting add primops that REALLY require certain arguments to be compile time constants to work correctly, otherwise there will by definition be compiler errors after the c-- phase when operations are passed along to the llvm backend and friends. (for the atomicity ops, i'll be looking into adding them to the native code gen, but the point being it will likely trigger an error at code gen time). a strawman approach would look like adding a type {{{ ReallyActuallyConstant :: * or unliftedtype -> * unliftedtype}}} roughly, then prefetch could have the type {{{ primop PrefetchAddrOp "prefetchAddr#" GenPrimOp Addr# ->ReallyActuallyConstant Int# -> Addr# with llvm_only = True }}} a way of emulating something like this functionality now, would be some template haskell that lets you lift a compile time constant of type t into the type ReallyActuallyConstant t, and is the only way to build a value of that type "ReallyActuallyConstant t". That said, that approach seems like a bad way of providing type safetype for making sure primops actually compile! Point being, some sort of way of nicely enforcing that a value needs to be available at compile time, that doesn't require doing abusing template haskell, is the idea i'm pointing at. Might also be useful for other things, but for now, i'm merely remarking on an invariant these primops have -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): Alternatively, maybe these operations need to be split and fixed on those constant args, so that theres no need for this sort of checking -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): eg prefetch0, prefetch1, prefetch2, and prefetch3, rather than a single prefetch operation -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): example code that would tickle this might be something like {-# NOINLINE f#-} f add# prior# = prefetch add# prior# -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): a better example motivating "reallyactually compile time constants" is supporting the various SIMD vector shuffling operations, i'll cook up an exposition of that if anyone would like that explained more -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by carter): * status: new => closed * resolution: => invalid Comment: after thinking about it more, and catching up on sleep, this seems to be "solved" mostly by the typed template haskell work that will be landing in 7.8. (not perfectly, be nicely enough for now I think) closing this accordingly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 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 carter): * status: closed => new * resolution: invalid => Comment: I'm going to reopen this, because I think its still something worth thinking about. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 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: -------------------------------------+------------------------------------ Changes (by carter): * version: 7.6.3 => 7.7 * type: bug => feature request * milestone: => 7.10.1 Comment: In some of the prior examples, I was misinterpreting that int parameter for prefetch to be related to the int parameter that is in the GCC/CLANG prefetch intrinsics, which it is not. That said: the notion of "static/compile time constant arguments" will be ESSENTIAL for correctly expressing/exposing fully general prefetch, as well as the general case of many of the SIMD instructions for AVX1, AVX2, as well as the much more interesting 32SIMD register, 512 bit, conditional mixing AVX512 instructions, etc. The richer AVX512 instructions will be in Intel's Knights Landing, which is going to be the first generation of Intel mainboard CPUs that will have ~ 40+ cores on a single die. And I believe we're quite keen on making sure GHC works amazing on such many core hardware. Its worth noting that Knight Landing will be the first generation of those many core CPU's to have support via an LLVM backend as well. I believe this is something worth taking the time to work out, and have ready by GHC 7.10. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 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: 8252 | Related Tickets: 8131 -------------------------------------+------------------------------------ Changes (by carter): * related: => 8131 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 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: 8252 | Related Tickets: #8131 -------------------------------------+------------------------------------ Changes (by carter): * related: 8131 => #8131 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------ Reporter: carter | Owner: carter Type: feature request | Status: new Priority: normal | Milestone: 7.10.1 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: 8252 | Related Tickets: #8131 -------------------------------------+------------------------------------ Changes (by carter): * owner: => carter -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8107: need types to express constant argument for primop correctness -------------------------------------+------------------------------------- Reporter: carter | Owner: carter Type: feature request | Status: new 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: 8252 Related Tickets: #8131 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * cc: Iceland_jack (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8107#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC