X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmOpt.hs;h=9a5121541a824a677c9863b5083b4ff66181a72a;hb=d5c0de4518422315f0179121b222b0e3c7d82d86;hp=f279b84b6f1c98b98f1b14446ce9355ca7a13f63;hpb=49c98d143c382a1341e1046f5ca00819a25691ba;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs index f279b84..9a51215 100644 --- a/compiler/cmm/CmmOpt.hs +++ b/compiler/cmm/CmmOpt.hs @@ -19,6 +19,7 @@ import CmmUtils import CLabel import MachOp import SMRep +import StaticFlags import UniqFM import Unique @@ -311,8 +312,12 @@ cmmMachOpFold op [x@(CmmLit _), y] -- put arg1 on the left of the rearranged expression, we'll get into a -- loop: (x1+x2)+x3 => x1+(x2+x3) => (x2+x3)+x1 => x2+(x3+x1) ... -- +-- Also don't do it if arg1 is PicBaseReg, so that we don't separate the +-- PicBaseReg from the corresponding label (or label difference). +-- cmmMachOpFold mop1 [CmmMachOp mop2 [arg1,arg2], arg3] - | mop1 == mop2 && isAssociativeMachOp mop1 && not (isLit arg1) + | mop1 == mop2 && isAssociativeMachOp mop1 + && not (isLit arg1) && not (isPicReg arg1) = cmmMachOpFold mop1 [arg1, cmmMachOpFold mop2 [arg2,arg3]] -- Make a RegOff if we can @@ -334,6 +339,38 @@ cmmMachOpFold (MO_Add _) [CmmLit (CmmInt i rep), CmmLit (CmmLabel lbl)] cmmMachOpFold (MO_Sub _) [CmmLit (CmmLabel lbl), CmmLit (CmmInt i rep)] = CmmLit (CmmLabelOff lbl (fromIntegral (negate (narrowU rep i)))) + +-- Comparison of literal with narrowed/widened operand: perform +-- the comparison at a different width, as long as the literal is +-- within range. + +#if i386_TARGET_ARCH || x86_64_TARGET_ARCH +-- powerPC NCG has a TODO for I8/I16 comparisons, so don't try + +cmmMachOpFold cmp [CmmMachOp conv [x], CmmLit (CmmInt i _)] + | Just (rep, narrow) <- maybe_conversion conv, + Just narrow_cmp <- maybe_comparison cmp rep, + let narrow_i = narrow rep i, + narrow_i == i + = cmmMachOpFold narrow_cmp [x, CmmLit (CmmInt narrow_i rep)] + where + maybe_conversion (MO_U_Conv from _) = Just (from, narrowU) + maybe_conversion (MO_S_Conv from _) = Just (from, narrowS) + maybe_conversion _ = Nothing + + maybe_comparison (MO_U_Gt _) rep = Just (MO_U_Gt rep) + maybe_comparison (MO_U_Ge _) rep = Just (MO_U_Ge rep) + maybe_comparison (MO_U_Lt _) rep = Just (MO_U_Lt rep) + maybe_comparison (MO_U_Le _) rep = Just (MO_U_Le rep) + maybe_comparison (MO_S_Gt _) rep = Just (MO_S_Gt rep) + maybe_comparison (MO_S_Ge _) rep = Just (MO_S_Ge rep) + maybe_comparison (MO_S_Lt _) rep = Just (MO_S_Lt rep) + maybe_comparison (MO_S_Le _) rep = Just (MO_S_Le rep) + maybe_comparison (MO_Eq _) rep = Just (MO_Eq rep) + maybe_comparison _ _ = Nothing + +#endif + -- We can often do something with constants of 0 and 1 ... cmmMachOpFold mop args@[x, y@(CmmLit (CmmInt 0 _))] @@ -526,3 +563,6 @@ maybeInvertConditionalExpr :: CmmExpr -> Maybe CmmExpr maybeInvertConditionalExpr (CmmMachOp op args) | Just op' <- maybeInvertComparison op = Just (CmmMachOp op' args) maybeInvertConditionalExpr _ = Nothing + +isPicReg (CmmReg (CmmGlobal PicBaseReg)) = True +isPicReg _ = False