diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-10-02 16:41:40 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-10-09 08:47:00 -0400 |
commit | 12191a99d3b978b697ec0fb4412276fbea5dce8f (patch) | |
tree | f4c60bed13d6141e817bda264b24a4a3ab9ae0b6 /compiler/GHC/Core/SimpleOpt.hs | |
parent | e691a5a04692beb601d480ccf9f283199a70ed62 (diff) | |
download | haskell-12191a99d3b978b697ec0fb4412276fbea5dce8f.tar.gz |
Bignum: match on small Integer/Natural
Previously we only matched on *variables* whose unfoldings were a ConApp
of the form `IS lit#` or `NS lit##`. But we forgot to match on the
ConApp directly... As a consequence, constant folding only worked after
the FloatOut pass which creates bindings for most sub-expressions. With
this patch, matching on bignums works even with -O0 (see bignumMatch
test).
Diffstat (limited to 'compiler/GHC/Core/SimpleOpt.hs')
-rw-r--r-- | compiler/GHC/Core/SimpleOpt.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/GHC/Core/SimpleOpt.hs b/compiler/GHC/Core/SimpleOpt.hs index d066535e30..4467648fed 100644 --- a/compiler/GHC/Core/SimpleOpt.hs +++ b/compiler/GHC/Core/SimpleOpt.hs @@ -1279,13 +1279,24 @@ exprIsLiteral_maybe env@(_, id_unf) e -> Just l Var v | Just rhs <- expandUnfolding_maybe (id_unf v) - , Just (_env,_fb,dc,_tys,[arg]) <- exprIsConApp_maybe env rhs + , Just b <- matchBignum env rhs + -> Just b + e + | Just b <- matchBignum env e + -> Just b + + | otherwise + -> Nothing + where + matchBignum env e + | Just (_env,_fb,dc,_tys,[arg]) <- exprIsConApp_maybe env e , Just (LitNumber _ i) <- exprIsLiteral_maybe env arg - -> if + = if | dc == naturalNSDataCon -> Just (mkLitNatural i) | dc == integerISDataCon -> Just (mkLitInteger i) | otherwise -> Nothing - _ -> Nothing + | otherwise + = Nothing {- Note [exprIsLambda_maybe] |