[commit: ghc] master: Optimise stack checks that are always false (1cf0c8a)

git at git.haskell.org git at git.haskell.org
Fri Oct 18 07:54:45 UTC 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/1cf0c8ad321d1d358cbec46d35be02566faf2d00/ghc

>---------------------------------------------------------------

commit 1cf0c8ad321d1d358cbec46d35be02566faf2d00
Author: Jan Stolarek <jan.stolarek at p.lodz.pl>
Date:   Thu Oct 17 23:17:06 2013 +0200

    Optimise stack checks that are always false
    
    Fix a bug introduced in 94125c97e49987e91fa54da6c86bc6d17417f5cf.
    See Note [Always false stack check]


>---------------------------------------------------------------

1cf0c8ad321d1d358cbec46d35be02566faf2d00
 compiler/cmm/CmmLayoutStack.hs |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/compiler/cmm/CmmLayoutStack.hs b/compiler/cmm/CmmLayoutStack.hs
index 4ac5725..2efb806 100644
--- a/compiler/cmm/CmmLayoutStack.hs
+++ b/compiler/cmm/CmmLayoutStack.hs
@@ -773,24 +773,24 @@ areaToSp :: DynFlags -> ByteOff -> ByteOff -> (Area -> StackLoc) -> CmmExpr -> C
 areaToSp dflags sp_old _sp_hwm area_off (CmmStackSlot area n) =
   cmmOffset dflags (CmmReg spReg) (sp_old - area_off area - n)
 areaToSp dflags _ sp_hwm _ (CmmLit CmmHighStackMark) = mkIntExpr dflags sp_hwm
-areaToSp dflags _ _ _ (CmmMachOp (MO_U_Lt _)  -- Note [null stack check]
+areaToSp dflags _ _ _ (CmmMachOp (MO_U_Lt _)  -- Note [Always false stack check]
                           [CmmMachOp (MO_Sub _)
-                                  [ CmmReg (CmmGlobal Sp)
-                                  , CmmLit (CmmInt 0 _)],
-                           CmmReg (CmmGlobal SpLim)]) = zeroExpr dflags
+                                  [ CmmRegOff (CmmGlobal Sp) off
+                                  , CmmLit (CmmInt lit _)],
+                           CmmReg (CmmGlobal SpLim)])
+                              | fromIntegral off == lit = zeroExpr dflags
 areaToSp _ _ _ _ other = other
 
--- -----------------------------------------------------------------------------
--- Note [null stack check]
+-- Note [Always false stack check]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 --
--- If the high-water Sp is zero, then we end up with
+-- We can optimise stack checks of the form
 --
---   if (Sp - 0 < SpLim) then .. else ..
+--   if ((Sp + x) - x < SpLim) then .. else ..
 --
--- and possibly some dead code for the failure case.  Optimising this
--- away depends on knowing that SpLim <= Sp, so it is really the job
--- of the stack layout algorithm, hence we do it now.  This is also
--- convenient because control-flow optimisation later will drop the
+-- where x is an integer offset. Optimising this away depends on knowing that
+-- SpLim <= Sp, so it is really the job of the stack layout algorithm, hence we
+-- do it now.  This is also convenient because sinking pass will later drop the
 -- dead code.
 
 optStackCheck :: CmmNode O C -> CmmNode O C



More information about the ghc-commits mailing list