summaryrefslogtreecommitdiff
path: root/compiler/cmm/CmmOpt.hs
diff options
context:
space:
mode:
authorJohan Tibell <johan.tibell@gmail.com>2011-05-06 17:10:15 +0200
committerSimon Marlow <marlowsd@gmail.com>2011-06-01 10:56:05 +0100
commite97f29804abdbf9b374aeb3661af340714ea1b60 (patch)
treeee1e4d0ba253d58b0d0386013ae21fc0eb4bd6ed /compiler/cmm/CmmOpt.hs
parentea44eadfb9d269d06b889fbfe41286bf0c7a730d (diff)
downloadhaskell-e97f29804abdbf9b374aeb3661af340714ea1b60.tar.gz
Fold constants during forward substitution in the Cmm mini-inliner
This exposes new constants that can be propagated.
Diffstat (limited to 'compiler/cmm/CmmOpt.hs')
-rw-r--r--compiler/cmm/CmmOpt.hs25
1 files changed, 17 insertions, 8 deletions
diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs
index 1355cd23ea..69df4fbff1 100644
--- a/compiler/cmm/CmmOpt.hs
+++ b/compiler/cmm/CmmOpt.hs
@@ -160,13 +160,13 @@ cmmMiniInline blocks = map do_inline blocks
cmmMiniInlineStmts :: UniqFM Int -> [CmmStmt] -> [CmmStmt]
cmmMiniInlineStmts uses [] = []
-cmmMiniInlineStmts uses (stmt@(CmmAssign (CmmLocal (LocalReg u _)) expr@(CmmLit _)) : stmts)
+cmmMiniInlineStmts uses (stmt@(CmmAssign (CmmLocal (LocalReg u _)) expr) : stmts)
-- not used: just discard this assignment
| Nothing <- lookupUFM uses u
= cmmMiniInlineStmts uses stmts
- -- used: try to inline at all the use sites
- | Just n <- lookupUFM uses u
+ -- used (literal): try to inline at all the use sites
+ | Just n <- lookupUFM uses u, isLit expr
=
#ifdef NCG_DEBUG
trace ("nativeGen: inlining " ++ showSDoc (pprStmt stmt)) $
@@ -177,12 +177,21 @@ cmmMiniInlineStmts uses (stmt@(CmmAssign (CmmLocal (LocalReg u _)) expr@(CmmLit
| otherwise ->
stmt : cmmMiniInlineStmts (adjustUFM (\x -> x - m) uses u) stmts'
-cmmMiniInlineStmts uses (stmt@(CmmAssign (CmmLocal (LocalReg u _)) expr : stmts))
- -- not used at all: just discard this assignment
- | Nothing <- lookupUFM uses u
- = cmmMiniInlineStmts uses stmts
+ -- used (foldable to literal): try to inline at all the use sites
+ | Just n <- lookupUFM uses u,
+ CmmMachOp op es <- expr,
+ e@(CmmLit _) <- cmmMachOpFold op es
+ =
+#ifdef NCG_DEBUG
+ trace ("nativeGen: inlining " ++ showSDoc (pprStmt stmt)) $
+#endif
+ case lookForInlineLit u e stmts of
+ (m, stmts')
+ | n == m -> cmmMiniInlineStmts (delFromUFM uses u) stmts'
+ | otherwise ->
+ stmt : cmmMiniInlineStmts (adjustUFM (\x -> x - m) uses u) stmts'
- -- used once: try to inline at the use site
+ -- used once (non-literal): try to inline at the use site
| Just 1 <- lookupUFM uses u,
Just stmts' <- lookForInline u expr stmts
=