diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2018-04-13 13:23:13 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-04-13 14:17:14 -0400 |
commit | 3c7f9e74ca858de17bc63b862c77cbb3f8b0ee51 (patch) | |
tree | af721ec9e3cca9630d331be2843606aa51963529 | |
parent | 00b8ecb78624511a045120673b01fafe5794ecdc (diff) | |
download | haskell-3c7f9e74ca858de17bc63b862c77cbb3f8b0ee51.tar.gz |
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
-rw-r--r-- | compiler/main/DynFlags.hs | 4 | ||||
-rw-r--r-- | compiler/nativeGen/AsmCodeGen.hs | 6 | ||||
-rw-r--r-- | 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 7c27e52a6b..6bfa8f2955 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 6b20a12016..5d290858b8 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 84664062dc..59edcdc320 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 |