summaryrefslogtreecommitdiff
path: root/compiler/GHC/CoreToStg/Prep.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-08-12 17:44:15 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-09-11 08:54:29 -0400
commit089de88ef5215de0f2db4c4babc556ac43f8232e (patch)
treec036813b9625dbb45b4577b09ec6ad31c45c1bce /compiler/GHC/CoreToStg/Prep.hs
parent74a87aa3046f3eb871e5442579e9a2945ef691d4 (diff)
downloadhaskell-089de88ef5215de0f2db4c4babc556ac43f8232e.tar.gz
Canonicalize bignum literals
Before this patch Integer and Natural literals were desugared into "real" Core in Core prep. Now we desugar them directly into their final ConApp form in HsToCore. We only keep the double representation for BigNat# (literals larger than a machine Word/Int) which are still desugared in Core prep. Using the final form directly allows case-of-known-constructor to fire for bignum literals, fixing #20245. Slight increase (+2.3) in T4801 which is a pathological case with Integer literals. Metric Increase: T4801 T11545
Diffstat (limited to 'compiler/GHC/CoreToStg/Prep.hs')
-rw-r--r--compiler/GHC/CoreToStg/Prep.hs33
1 files changed, 2 insertions, 31 deletions
diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs
index 30c28a6db2..675ef7776c 100644
--- a/compiler/GHC/CoreToStg/Prep.hs
+++ b/compiler/GHC/CoreToStg/Prep.hs
@@ -131,8 +131,7 @@ The goal of this pass is to prepare for code generation.
9. Replace (lazy e) by e. See Note [lazyId magic] in GHC.Types.Id.Make
Also replace (noinline e) by e.
-10. Convert bignum literals (LitNatural and LitInteger) into their
- core representation.
+10. Convert bignum literals into their core representation.
11. Uphold tick consistency while doing this: We move ticks out of
(non-type) applications where we can, and make sure that we
@@ -2146,37 +2145,9 @@ mkConvertNumLiteral hsc_env = do
let
convertNumLit nt i = case nt of
- LitNumInteger -> Just (convertInteger i)
- LitNumNatural -> Just (convertNatural i)
+ LitNumBigNat -> Just (convertBignatPrim i)
_ -> Nothing
- convertInteger i
- | platformInIntRange platform i -- fit in a Int#
- = mkConApp integerISDataCon [Lit (mkLitInt platform i)]
-
- | otherwise -- build a BigNat and embed into IN or IP
- = let con = if i > 0 then integerIPDataCon else integerINDataCon
- in mkBigNum con (convertBignatPrim (abs i))
-
- convertNatural i
- | platformInWordRange platform i -- fit in a Word#
- = mkConApp naturalNSDataCon [Lit (mkLitWord platform i)]
-
- | otherwise --build a BigNat and embed into NB
- = mkBigNum naturalNBDataCon (convertBignatPrim i)
-
- -- we can't simply generate:
- --
- -- NB (bigNatFromWordList# [W# 10, W# 20])
- --
- -- using `mkConApp` because it isn't in ANF form. Instead we generate:
- --
- -- case bigNatFromWordList# [W# 10, W# 20] of ba { DEFAULT -> NB ba }
- --
- -- via `mkCoreApps`
-
- mkBigNum con ba = mkCoreApps (Var (dataConWorkId con)) [ba]
-
convertBignatPrim i =
let
target = targetPlatform dflags