From dd57fdccbde03ccb78289fdba045f2df03073193 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 15 Jan 2009 22:18:27 +0000 Subject: [PATCH] Made a small change to sort multiplied expressions into order during flattening in the usage checking This makes sure that y*x and x*y are both flattened into x*y, but doesn't yet solve the problem of (x*y)*z vs (y*z)*x --- checks/ArrayUsageCheck.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/checks/ArrayUsageCheck.hs b/checks/ArrayUsageCheck.hs index 1b43229..7ef466f 100644 --- a/checks/ArrayUsageCheck.hs +++ b/checks/ArrayUsageCheck.hs @@ -496,9 +496,11 @@ flatten e@(A.Dyadic m op lhs rhs) mult :: FlattenedExp -> FlattenedExp -> Either String FlattenedExp mult (Const x) e = scale x e mult e (Const x) = scale x e - mult lhs rhs = do lhs' <- backToEq lhs - rhs' <- backToEq rhs - return $ (Scale 1 (A.Dyadic emptyMeta A.Mul lhs' rhs', 0)) + mult lhs rhs + = do lhs' <- backToEq lhs + rhs' <- backToEq rhs + let (onLeft, onRight) = if lhs' <= rhs' then (lhs', rhs') else (rhs', lhs') + return $ (Scale 1 (A.Dyadic emptyMeta A.Mul onLeft onRight, 0)) backScale :: Integer -> A.Expression -> A.Expression backScale 1 = id