[GHC] #9736: Constant folding rules are wrong for GHCJS

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- GHCJS currently has a complete copy of PrelRules to work around some issues where the rules depend on the build environment instead of the target. - shiftRightLogical - removeOp32 I'd like to get rid of the copy for 7.10 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 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: | -------------------------------------+------------------------------------- Comment (by simonpj): Can you be more specific? Why are these "optimisations" wrong for GHCJS? Could they be wrong for other architectures? Concretely, what change do you propose? Built-in rules (like those in `PrelRules` have access to `DynFlags`. If necessary you could make the rule conditional on the `GHCJS` flag (whatever that is). Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 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: | -------------------------------------+------------------------------------- Comment (by luite): Ah my intention was just to verify that the changes in GHCJS, which are based on 7.8, are still correct in the latest HEAD and then attach the patch here. One issue likely affects other cross compilers: `shiftRightLogical` truncates the value to `Word`size, which is wrong if the host word size is different from the target. https://github.com/ghc/ghc/blob/f1090855d9b8d33b3194364dcca0683d89049f03/com... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 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: | -------------------------------------+------------------------------------- Comment (by luite): I've made the `removeOp32` operation target word size dependent (from `DynFlags`) and `rightShiftLogical` use a correctly sized word for the target. I'm not 100% sure what's the best way to do `removeOp32` for GHCJS, since `ArchJavaScript` has to be treated as 32 bit (that's the only word size available for bitwise operations), but numbers can have a bigger range. In most cases, the primops already handle truncation, and the dataflow analysis in the optimizer removes the superfluous narrowing operations. In some situations, narrowing is still needed, for example when a value is obtained from a foreign operation. Since most `NarrowInt32` operations are actually unnecessary for GHCJS, and I'm not sure how well the optimizer will be able to strip the `NarrowInt32Op` from for example `Int32` operations, I'm not adding an exception for `ArchJavaScript` in `removeOp32` and deal with exceptional situations like foreign return values individually in the desugarer. If it turns out that there are situations that can't be handled this way, I'll send another change request for that, like below: {{{#!hs removeOp32 :: RuleM CoreExpr removeOp32 = do dflags <- getDynFlags if wordSizeInBits dflags == 32 && -- JavaScript has 32 bit bitwise operations -- but numbers have a greater range platformArch (targetPlatform dflags) /= ArchJavaScript then do [e] <- getArgs return e else mzero }}} (and unfortunately I'd have to copy/paste the whole PrelRules module into GHCJS again if I'm too late) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 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: Phab:D502 | -------------------------------------+------------------------------------- Changes (by luite): * differential: => Phab:D502 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9736: Constant folding rules are wrong for GHCJS
-------------------------------------+-------------------------------------
Reporter: luite | Owner: luite
Type: bug | Status: new
Priority: normal | Milestone: 7.10.1
Component: Compiler | Version: 7.8.3
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: Phab:D502 |
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#9736: Constant folding rules are wrong for GHCJS -------------------------------------+------------------------------------- Reporter: luite | Owner: luite Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.3 Resolution: fixed | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D502 | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => fixed Comment: Please re-open if the work here is not done yet; I can't tell with certainty. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9736#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC