[Git][ghc/ghc][wip/andreask/inline_div] Always inline divInt and modInt in phase zero.
Andreas Klebinger
gitlab at gitlab.haskell.org
Fri Apr 17 10:56:48 UTC 2020
Andreas Klebinger pushed to branch wip/andreask/inline_div at Glasgow Haskell Compiler / GHC
Commits:
062201da by Andreas Klebinger at 2020-04-17T12:56:35+02:00
Always inline divInt and modInt in phase zero.
This prevents the overhead of a function call for
operations which really only need to be a few instructions.
By always inlining them in phase zero we can:
* Match on them via rules in earlier phases.
* Can constant fold on them in phase zero by
rules on their underlying primitives.
This fixes #18067
- - - - -
2 changed files:
- libraries/base/GHC/Base.hs
- libraries/ghc-prim/GHC/Classes.hs
Changes:
=====================================
libraries/base/GHC/Base.hs
=====================================
@@ -1545,9 +1545,34 @@ getTag x = dataToTag# x
-- Definitions of the boxed PrimOps; these will be
-- used in the case of partial applications, etc.
+{- Note [Inlining divInt, modInt]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ divInt and modInt are implemented in terms of
+ the quotInt#/remInt# primOps.
+
+ My marking them as INLINE[0] we achieve two things:
+
+ * We can match on them in the early phases via rules.
+ * We can constant fold via rules on quotInt#/remInt# in
+ phase zero if they are applied to constants.
+
+ This solves #18067 where we observed divInt ending up
+ as a uninlined call at times.
+
+ TODO: It might be good to apply the same pattern to
+ quotRemInt and divModInt. But I have not looked at this
+ yet.
+
+-}
+
{-# INLINE quotInt #-}
{-# INLINE remInt #-}
+-- See Note [Inlining divInt, modInt]
+{-# INLINE[0] divInt #-}
+{-# INLINE[0] modInt #-}
+
quotInt, remInt, divInt, modInt :: Int -> Int -> Int
(I# x) `quotInt` (I# y) = I# (x `quotInt#` y)
(I# x) `remInt` (I# y) = I# (x `remInt#` y)
=====================================
libraries/ghc-prim/GHC/Classes.hs
=====================================
@@ -545,8 +545,8 @@ not False = True
-- put them
-- These functions have built-in rules.
-{-# NOINLINE [0] divInt# #-}
-{-# NOINLINE [0] modInt# #-}
+{-# INLINE [0] divInt# #-}
+{-# INLINE [0] modInt# #-}
divInt# :: Int# -> Int# -> Int#
x# `divInt#` y#
-- Be careful NOT to overflow if we do any additional arithmetic
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/062201daeadfd2c273ab256be70a22114be3a7e3
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/062201daeadfd2c273ab256be70a22114be3a7e3
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200417/e8876bce/attachment-0001.html>
More information about the ghc-commits
mailing list