[commit: ghc] ghc-7.10: Fix treatment of -0.0 (ba46270)

git at git.haskell.org git at git.haskell.org
Thu Oct 22 15:08:46 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/ba46270dec398ae8aebb5f55755be112fe3c417b/ghc

>---------------------------------------------------------------

commit ba46270dec398ae8aebb5f55755be112fe3c417b
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Fri Oct 2 15:40:43 2015 +0200

    Fix treatment of -0.0
    
    Here we fix a few mis-optimizations that could occur in code with
    floating point comparisons with -0.0. These issues arose from our
    insistence on rewriting equalities into case analyses and the
    simplifier's ignorance of floating-point semantics.
    
    For instance, in Trac #10215 (and the similar issue Trac #9238) we
    turned `ds == 0.0` into a case analysis,
    
    ```
    case ds of
        __DEFAULT -> ...
        0.0 -> ...
    ```
    
    Where the second alternative matches where `ds` is +0.0 and *also* -0.0.
    However, the simplifier doesn't realize this and will introduce a local
    inlining of `ds = -- +0.0` as it believes this is the only
    value that matches this pattern.
    
    Instead of teaching the simplifier about floating-point semantics
    we simply prohibit case analysis on floating-point scrutinees and keep
    this logic in the comparison primops, where it belongs.
    
    We do several things here,
    
     - Add test cases from relevant tickets
     - Clean up a bit of documentation
     - Desugar literal matches against floats into applications of the
       appropriate equality primitive instead of case analysis
     - Add a CoreLint to ensure we don't pattern match on floats in Core
    
    Test Plan: validate with included testcases
    
    Reviewers: goldfire, simonpj, austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1061
    
    GHC Trac Issues: #10215, #9238


>---------------------------------------------------------------

ba46270dec398ae8aebb5f55755be112fe3c417b
 compiler/coreSyn/CoreLint.hs                       |  30 +++++
 compiler/coreSyn/CoreSyn.hs                        |   7 ++
 compiler/deSugar/MatchLit.hs                       |  15 +--
 compiler/prelude/PrelRules.hs                      | 125 ++++++++++++---------
 compiler/typecheck/TcType.hs                       |   7 +-
 testsuite/tests/deSugar/should_run/T10215.hs       |   9 ++
 .../should_run/T10215.stdout}                      |   1 +
 testsuite/tests/deSugar/should_run/T9238.hs        |  16 +++
 testsuite/tests/deSugar/should_run/T9238.stdout    |   2 +
 testsuite/tests/deSugar/should_run/all.T           |   2 +
 10 files changed, 151 insertions(+), 63 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc ba46270dec398ae8aebb5f55755be112fe3c417b


More information about the ghc-commits mailing list