[commit: ghc] master: Make shortcutting at the asm stage toggleable and default for O2. (3c7f9e7)
git at git.haskell.org
git at git.haskell.org
Fri Apr 13 18:17:43 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/3c7f9e74ca858de17bc63b862c77cbb3f8b0ee51/ghc
>---------------------------------------------------------------
commit 3c7f9e74ca858de17bc63b862c77cbb3f8b0ee51
Author: Andreas Klebinger <klebinger.andreas at gmx.at>
Date: Fri Apr 13 13:23:13 2018 -0400
Make shortcutting at the asm stage toggleable and default for O2.
Shortcutting during the asm stage of codegen is often redundant as most
cases get caught during the Cmm passes. For example during compilation
of all of nofib only 508 jumps are eleminated.
For this reason I moved the pass from -O1 to -O2. I also made it
toggleable with -fasm-shortcutting.
Test Plan: ci
Reviewers: bgamari
Reviewed By: bgamari
Subscribers: thomie, carter
Differential Revision: https://phabricator.haskell.org/D4555
>---------------------------------------------------------------
3c7f9e74ca858de17bc63b862c77cbb3f8b0ee51
compiler/main/DynFlags.hs | 4 ++++
compiler/nativeGen/AsmCodeGen.hs | 6 ++++--
docs/users_guide/using-optimisation.rst | 17 +++++++++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 7c27e52..6bfa8f2 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -480,6 +480,7 @@ data GeneralFlag
| Opt_IrrefutableTuples
| Opt_CmmSink
| Opt_CmmElimCommonBlocks
+ | Opt_AsmShortcutting
| Opt_OmitYields
| Opt_FunToThunk -- allow WwLib.mkWorkerArgs to remove all value lambdas
| Opt_DictsStrict -- be strict in argument dictionaries
@@ -664,6 +665,7 @@ optimisationFlags = EnumSet.fromList
, Opt_IrrefutableTuples
, Opt_CmmSink
, Opt_CmmElimCommonBlocks
+ , Opt_AsmShortcutting
, Opt_OmitYields
, Opt_FunToThunk
, Opt_DictsStrict
@@ -3893,6 +3895,7 @@ fFlagsDeps = [
-- See Note [Updating flag description in the User's Guide]
-- See Note [Supporting CLI completion]
-- Please keep the list of flags below sorted alphabetically
+ flagSpec "asm-shortcutting" Opt_AsmShortcutting,
flagGhciSpec "break-on-error" Opt_BreakOnError,
flagGhciSpec "break-on-exception" Opt_BreakOnException,
flagSpec "building-cabal-package" Opt_BuildingCabalPackage,
@@ -4370,6 +4373,7 @@ optLevelFlags -- see Note [Documenting optimisation flags]
, ([1,2], Opt_CaseMerge)
, ([1,2], Opt_CaseFolding)
, ([1,2], Opt_CmmElimCommonBlocks)
+ , ([2], Opt_AsmShortcutting)
, ([1,2], Opt_CmmSink)
, ([1,2], Opt_CSE)
, ([1,2], Opt_StgCSE)
diff --git a/compiler/nativeGen/AsmCodeGen.hs b/compiler/nativeGen/AsmCodeGen.hs
index 6b20a12..5d29085 100644
--- a/compiler/nativeGen/AsmCodeGen.hs
+++ b/compiler/nativeGen/AsmCodeGen.hs
@@ -934,8 +934,10 @@ shortcutBranches
-> [NatCmmDecl statics instr]
shortcutBranches dflags ncgImpl tops
- | optLevel dflags < 1 = tops -- only with -O or higher
- | otherwise = map (apply_mapping ncgImpl mapping) tops'
+ | gopt Opt_AsmShortcutting dflags
+ = map (apply_mapping ncgImpl mapping) tops'
+ | otherwise
+ = tops
where
(tops', mappings) = mapAndUnzip (build_mapping ncgImpl) tops
mapping = plusUFMList mappings
diff --git a/docs/users_guide/using-optimisation.rst b/docs/users_guide/using-optimisation.rst
index 8466406..59edcdc 100644
--- a/docs/users_guide/using-optimisation.rst
+++ b/docs/users_guide/using-optimisation.rst
@@ -217,6 +217,23 @@ by saying ``-fno-wombat``.
to their usage sites. It also inlines simple expressions like
literals or registers.
+.. ghc-flag:: -fasm-shortcutting
+ :shortdesc: Enable shortcutting on assembly. Implied by :ghc-flag:`-O2`.
+ :type: dynamic
+ :reverse: -fno-asm-shortcutting
+ :category:
+
+ :default: off
+
+ This enables shortcutting at the assembly stage of the code generator.
+ In simpler terms shortcutting means if a block of instructions A only consists
+ of a unconditionally jump, we replace all jumps to A by jumps to the successor
+ of A.
+
+ This is mostly done during Cmm passes. However this can miss corner cases. So at -O2
+ we run the pass again at the asm stage to catch these.
+
+
.. ghc-flag:: -fcpr-anal
:shortdesc: Turn on CPR analysis in the demand analyser. Implied by :ghc-flag:`-O`.
:type: dynamic
More information about the ghc-commits
mailing list