[Git][ghc/ghc][wip/romes/no-simple-joinpoints] uncondInline join points for trivial applications without free vars

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Wed Feb 5 11:55:08 UTC 2025



Rodrigo Mesquita pushed to branch wip/romes/no-simple-joinpoints at Glasgow Haskell Compiler / GHC


Commits:
bc892215 by Rodrigo Mesquita at 2025-02-05T11:54:43+00:00
uncondInline join points for trivial applications without free vars

TODO: Commit Message
TODO: Write Note
TODO: Update [Duplicating join points]

- - - - -


2 changed files:

- compiler/GHC/Core/Unfold.hs
- testsuite/tests/perf/compiler/all.T


Changes:

=====================================
compiler/GHC/Core/Unfold.hs
=====================================
@@ -434,7 +434,7 @@ uncondInline is_join rhs bndrs arity body size
 
 uncondInlineJoin :: [Var] -> CoreExpr -> Bool
 -- See Note [Duplicating join points] point (DJ3) in GHC.Core.Opt.Simplify.Iteration
-uncondInlineJoin _bndrs body
+uncondInlineJoin bndrs body
   | exprIsTrivial body
   = True   -- Nullary constructors, literals
 
@@ -443,9 +443,39 @@ uncondInlineJoin _bndrs body
   , isJoinId v   -- Indirection to another join point; always inline
   = True
 
+  | trivialAppWithoutFreeArgs
+  -- See Note [...]
+  = True
+
   | otherwise
   = False
 
+  where
+    -- Arguments cannot be free Vars!! See Note ...
+    trivialAppWithoutFreeArgs = go body
+    go (App f a)
+
+      -- Go over types
+      | Type _ <- a = go f
+
+      -- 1. If arg is a Var, it must be bound by bndrs
+      | Var v <- a
+      = if v `elem` bndrs {- not free -}
+           then go f
+           else False
+
+      -- 2. If arg is otherwise trivial, continue
+      | exprIsTrivial a = go f
+
+    -- Go over casts (and ticks?)
+    go (Cast e _) = go e
+    go (Tick _ e) = go e
+
+    go (Var _)    = True -- reached base case (function being applied, may be free var)
+
+    go _          = False -- any other case is not trivial app without free args
+
+
 
 sizeExpr :: UnfoldingOpts
          -> Int             -- Bomb out if it gets bigger than this


=====================================
testsuite/tests/perf/compiler/all.T
=====================================
@@ -612,6 +612,17 @@ test ('T16473',
       compile_and_run,
       ['-O2 -flate-specialise'])
 
+# Run this program. If inlining the join point fails, it'll start to allocate much more.
+# The join point is only created when -fno-local-float-out
+test ('T16473b',
+      [ collect_stats('bytes allocated',5)
+      , only_ways(['normal'])
+      , js_broken(22261)
+      ],
+      compile_and_run,
+      ['-O2 -fno-local-float-out'])
+
+
 test('T17516',
       [ collect_compiler_runtime(5),
       ],



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bc8922158b432ff5beda412f68c5a593c2c2bf9e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bc8922158b432ff5beda412f68c5a593c2c2bf9e
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/20250205/ea7c5b10/attachment-0001.html>


More information about the ghc-commits mailing list