diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2020-09-29 17:38:26 +0200 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2020-10-02 11:53:51 +0200 |
commit | 5cfe4d6bbe12a4c7d560fc19e76d781907bf7bda (patch) | |
tree | 731f24cfb241793d084c01c6a59e887ec7dd9a72 /compiler/GHC/Core/Opt | |
parent | 1edd6d21c0abea34b498a627234a97df21648024 (diff) | |
download | haskell-wip/T18765.tar.gz |
s/NOINLINE/NOINLINE[0]/g in GHC.Num.Integer (#18765)wip/T18765
This defeats constant-folding in the final phases of the Simplifier, but
enables us to get rid of allocations by inlining calls that can't be
constant-folded.
`NOINLINE[0]` is a better choice than `NOINLINE`, because
1. We still delay inlining long enough for the constant-folding RULEs
to fire
2. The compiler has the option to inlining them late, possibly
cancelling away boxes in the process.
`NOINLINE[0]` is a better choice than `INLINE[0]`, because
3. We don't unconditionally inline huge definitions such as
`integerDiv`, which would lead to code bloat at pretty much no
gain.
4. Since RULEs are unlikely to fire on the inlined RHS of e.g.
`integerDiv`, there is no gain in inlining the unoptimised
unfoldings.
We also have to mark all callers that want to participate in constant
folding as `INLINE`. See the new `Note [Integer constant folding]` for
details.
I had to change the `Num.fromInteger` and `Integral.toInteger`
implementations of `Int*` and `Word*` variants to call the constant
folded `integerToInt*#` and `integerToWord*#` variants directly to
ensure constant folding.
Fixes #18765.
Metric Decrease:
T10359
Diffstat (limited to 'compiler/GHC/Core/Opt')
-rw-r--r-- | compiler/GHC/Core/Opt/ConstantFold.hs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/GHC/Core/Opt/ConstantFold.hs b/compiler/GHC/Core/Opt/ConstantFold.hs index 892dd445f9..d5095d6999 100644 --- a/compiler/GHC/Core/Opt/ConstantFold.hs +++ b/compiler/GHC/Core/Opt/ConstantFold.hs @@ -1312,7 +1312,8 @@ builtinRules enableBignumRules builtinBignumRules :: EnableBignumRules -> [CoreRule] builtinBignumRules (EnableBignumRules False) = [] builtinBignumRules _ = - [ rule_IntegerFromLitNum "Word# -> Integer" integerFromWordName + [ rule_IntegerFromLitNum "Int# -> Integer" integerFromIntName + , rule_IntegerFromLitNum "Word# -> Integer" integerFromWordName , rule_IntegerFromLitNum "Int64# -> Integer" integerFromInt64Name , rule_IntegerFromLitNum "Word64# -> Integer" integerFromWord64Name , rule_IntegerFromLitNum "Natural -> Integer" integerFromNaturalName @@ -1347,7 +1348,7 @@ builtinBignumRules _ = , rule_shift_op "integerShiftL" integerShiftLName shiftL , rule_shift_op "integerShiftR" integerShiftRName shiftR , rule_integerBit "integerBit" integerBitName - -- See Note [Integer division constant folding] in libraries/base/GHC/Real.hs + -- See Note [Integer constant folding] in "GHC.Num.Integer" , rule_divop_one "integerQuot" integerQuotName quot , rule_divop_one "integerRem" integerRemName rem , rule_divop_one "integerDiv" integerDivName div |