[project @ 2005-01-28 12:55:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / cmm / MachOp.hs
index 55aaa3e..5bbff6d 100644 (file)
@@ -18,6 +18,7 @@ module MachOp         (
        MachOp(..), 
        pprMachOp,
        isCommutableMachOp,
+       isAssociativeMachOp,
        isComparisonMachOp,
        resultRepOfMachOp,
        machOpArgReps,
@@ -79,7 +80,6 @@ module MachOp         (
   ) where
 
 #include "HsVersions.h"
-#include "../includes/ghcconfig.h"
 
 import Constants
 import Outputable
@@ -492,6 +492,26 @@ isCommutableMachOp mop =
        _other                  -> False
 
 -- ----------------------------------------------------------------------------
+-- isAssociativeMachOp
+
+{- |
+Returns 'True' if the MachOp is associative (i.e. @(x+y)+z == x+(y+z)@)
+This is used in the platform-independent Cmm optimisations.
+
+If in doubt, return 'False'.  This generates worse code on the
+native routes, but is otherwise harmless.
+-}
+isAssociativeMachOp :: MachOp -> Bool
+isAssociativeMachOp mop = 
+  case mop of
+       MO_Add r        -> not (isFloatingRep r)
+       MO_Mul r        -> not (isFloatingRep r)
+       MO_And _        -> True
+       MO_Or _         -> True
+       MO_Xor _        -> True
+       _other          -> False
+
+-- ----------------------------------------------------------------------------
 -- isComparisonMachOp
 
 {- |