diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2014-05-23 18:25:53 +0200 |
---|---|---|
committer | Joachim Breitner <mail@joachim-breitner.de> | 2014-05-23 18:26:00 +0200 |
commit | cc2e4e2db6eba4d05317ad71b2c691826ad435c5 (patch) | |
tree | 36d226a694215200704ea3a709927dac6359b573 | |
parent | 8a8e10be0b3c60cfbafce34036b70e2659487904 (diff) | |
download | haskell-cc2e4e2db6eba4d05317ad71b2c691826ad435c5.tar.gz |
Also perform reassociation for Word
-rw-r--r-- | compiler/prelude/PrelRules.lhs | 11 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T9136.hs | 14 |
2 files changed, 22 insertions, 3 deletions
diff --git a/compiler/prelude/PrelRules.lhs b/compiler/prelude/PrelRules.lhs index 77e5671ffb..8a0569aee7 100644 --- a/compiler/prelude/PrelRules.lhs +++ b/compiler/prelude/PrelRules.lhs @@ -130,9 +130,14 @@ primOpRules nm ISrlOp = mkPrimOpRule nm 2 [ binaryLit (intOp2 shiftRightLog -- Word operations primOpRules nm WordAddOp = mkPrimOpRule nm 2 [ binaryLit (wordOp2 (+)) - , identityDynFlags zerow ] + , identityDynFlags zerow + , assocBinaryLit WordAddOp (wordOp2 (+)) + , litsToRight WordAddOp + , treesToLeft WordAddOp + , litsGoUp WordAddOp ] primOpRules nm WordSubOp = mkPrimOpRule nm 2 [ binaryLit (wordOp2 (-)) , rightIdentityDynFlags zerow + , minusToPlus WordSubOp , equalArgs >> retLit zerow ] primOpRules nm WordMulOp = mkPrimOpRule nm 2 [ binaryLit (wordOp2 (*)) , identityDynFlags onew ] @@ -841,8 +846,8 @@ strengthReduction two_lit add_op = do -- Note [Strength reduction] -- = ((x + y) + 2) + 3 -- using litsGoUp -- = (x + y) + 5 -- using assocBinaryLit -- --- An expression like "x -# 2" is turned into "x +# (-2)" (minusToPlus) and --- then also takes part in this scheme. +-- For Ints, an expression like "x -# 2" is turned into "x +# (-2)" +-- (minusToPlus) and then also takes part in this scheme. -- Note [What's true and false] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/testsuite/tests/simplCore/should_compile/T9136.hs b/testsuite/tests/simplCore/should_compile/T9136.hs index 4b6aed7409..37ad1ae24b 100644 --- a/testsuite/tests/simplCore/should_compile/T9136.hs +++ b/testsuite/tests/simplCore/should_compile/T9136.hs @@ -1,5 +1,7 @@ module T9136 where +import Data.Word + -- In all these example, no 8 should be found in the final code foo1 :: Int -> Int foo1 x = (x + 8) - 1 @@ -12,3 +14,15 @@ foo3 x y = ((8 + x) + y) - 2 foo4 :: Int -> Int -> Int foo4 x y = (8 + x) + (y - 3) + +word1 :: Word -> Word +word1 x = (x + 8) + 1 + +word2 :: Word -> Word +word2 x = (8 + x) + 2 + +word3 :: Word -> Word -> Word +word3 x y = ((8 + x) + y) + 2 + +word4 :: Word -> Word -> Word +word4 x y = (8 + x) + (y + 3) |