X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmOpt.hs;h=aa5a788d5e4872007e9e37c1e28588777865c703;hb=bd3a364da7956c269d31645995d0d775c52f6a84;hp=eba96531f3253131c153ee468b0c8baa7324f14f;hpb=d5c5c4eb1d9f6d382d3ef1a12be284a411451788;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs index eba9653..aa5a788 100644 --- a/compiler/cmm/CmmOpt.hs +++ b/compiler/cmm/CmmOpt.hs @@ -140,7 +140,7 @@ lookForInline u expr (stmt:stmts) getStmtUses :: CmmStmt -> UniqFM Int getStmtUses (CmmAssign _ e) = getExprUses e getStmtUses (CmmStore e1 e2) = plusUFM_C (+) (getExprUses e1) (getExprUses e2) -getStmtUses (CmmCall target _ es _) +getStmtUses (CmmCall target _ es) = plusUFM_C (+) (uses target) (getExprsUses (map fst es)) where uses (CmmForeignCall e _) = getExprUses e uses _ = emptyUFM @@ -161,8 +161,8 @@ getExprsUses es = foldr (plusUFM_C (+)) emptyUFM (map getExprUses es) inlineStmt :: Unique -> CmmExpr -> CmmStmt -> CmmStmt inlineStmt u a (CmmAssign r e) = CmmAssign r (inlineExpr u a e) inlineStmt u a (CmmStore e1 e2) = CmmStore (inlineExpr u a e1) (inlineExpr u a e2) -inlineStmt u a (CmmCall target regs es vols) - = CmmCall (infn target) regs es' vols +inlineStmt u a (CmmCall target regs es) + = CmmCall (infn target) regs es' where infn (CmmForeignCall fn cconv) = CmmForeignCall fn cconv infn (CmmPrim p) = CmmPrim p es' = [ (inlineExpr u a e, hint) | (e,hint) <- es ] @@ -339,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 _))]