From 41212fd652b59d949a993225e90cb202f2a33087 Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones Date: Fri, 18 Oct 2013 14:35:07 +0100 Subject: Clarify comments and liberalise stack-check optimisation slightly The only substantive change here is to change "==" into ">=" in the Note [Always false stack check] code. This is semantically correct, but won't have any practical impact. --- compiler/cmm/CmmLayoutStack.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'compiler/cmm/CmmLayoutStack.hs') diff --git a/compiler/cmm/CmmLayoutStack.hs b/compiler/cmm/CmmLayoutStack.hs index 2efb806a1e..23da5d02cd 100644 --- a/compiler/cmm/CmmLayoutStack.hs +++ b/compiler/cmm/CmmLayoutStack.hs @@ -775,23 +775,24 @@ areaToSp dflags sp_old _sp_hwm area_off (CmmStackSlot area n) = areaToSp dflags _ sp_hwm _ (CmmLit CmmHighStackMark) = mkIntExpr dflags sp_hwm areaToSp dflags _ _ _ (CmmMachOp (MO_U_Lt _) -- Note [Always false stack check] [CmmMachOp (MO_Sub _) - [ CmmRegOff (CmmGlobal Sp) off - , CmmLit (CmmInt lit _)], + [ CmmRegOff (CmmGlobal Sp) x_off + , CmmLit (CmmInt y_lit _)], CmmReg (CmmGlobal SpLim)]) - | fromIntegral off == lit = zeroExpr dflags + | fromIntegral x_off >= y_lit = zeroExpr dflags areaToSp _ _ _ _ other = other -- Note [Always false stack check] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- -- We can optimise stack checks of the form -- --- if ((Sp + x) - x < SpLim) then .. else .. +-- if ((Sp + x) - y < SpLim) then .. else .. -- --- 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. +-- where are non-negative integer byte offsets. Since we know that +-- SpLim <= Sp (remember the stack grows downwards), this test must +-- yield False if (x >= y), so we can rewrite the comparison to False. +-- A subsequent sinking pass will later drop the dead code. +-- 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. optStackCheck :: CmmNode O C -> CmmNode O C optStackCheck n = -- Note [null stack check] -- cgit v1.2.1