From: Simon Marlow Date: Thu, 22 Apr 2010 21:34:43 +0000 (+0000) Subject: Add missing constant folding and optimisation for unsigned division X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=591e1dc91ab7bb1f91b516d1b1ea59c3a8809955 Add missing constant folding and optimisation for unsigned division Noticed by Denys Rtveliashvili , see #4004 --- diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs index 8163073..1125ac1 100644 --- a/compiler/cmm/CmmOpt.hs +++ b/compiler/cmm/CmmOpt.hs @@ -259,6 +259,8 @@ cmmMachOpFold mop args@[CmmLit (CmmInt x xrep), CmmLit (CmmInt y _)] MO_Add r -> CmmLit (CmmInt (x + y) r) MO_Sub r -> CmmLit (CmmInt (x - y) r) MO_Mul r -> CmmLit (CmmInt (x * y) r) + MO_U_Quot r | y /= 0 -> CmmLit (CmmInt (x_u `quot` y_u) r) + MO_U_Rem r | y /= 0 -> CmmLit (CmmInt (x_u `rem` y_u) r) MO_S_Quot r | y /= 0 -> CmmLit (CmmInt (x `quot` y) r) MO_S_Rem r | y /= 0 -> CmmLit (CmmInt (x `rem` y) r) @@ -431,6 +433,9 @@ cmmMachOpFold mop args@[x, y@(CmmLit (CmmInt n _))] MO_Mul rep | Just p <- exactLog2 n -> CmmMachOp (MO_Shl rep) [x, CmmLit (CmmInt p rep)] + MO_U_Quot rep + | Just p <- exactLog2 n -> + CmmMachOp (MO_U_Shr rep) [x, CmmLit (CmmInt p rep)] MO_S_Quot rep | Just p <- exactLog2 n, CmmReg _ <- x -> -- We duplicate x below, hence require