[commit: packages/hoopl] master: Fix dead code elimination used in tests (782ffec)

git at git.haskell.org git at git.haskell.org
Mon Dec 21 22:13:36 UTC 2015


Repository : ssh://git@git.haskell.org/hoopl

On branch  : master
Link       : http://git.haskell.org/packages/hoopl.git/commitdiff/782ffec38719d723be775eb00a5d527f81b75a7b

>---------------------------------------------------------------

commit 782ffec38719d723be775eb00a5d527f81b75a7b
Author: Michal Terepeta <michal.terepeta at gmail.com>
Date:   Sun Jun 28 17:03:45 2015 +0200

    Fix dead code elimination used in tests
    
    The helper functions to fold over instructions and expressions in
    test/OptSupport have a bug where they would not recurse for complex
    expressions. And since testing/Live module depends on it, complex
    expressions would not be fully analyzed, leading to removal of code
    that is *not* dead, e.g.,
      var1 = m[0]
      var1 = m[var1] + m[var1]
    would get rewritten to just
      var1 = m[var1] + m[var1]
    which is clearly wrong.
    
    Note that this bug affects only Hoopl's tests.


>---------------------------------------------------------------

782ffec38719d723be775eb00a5d527f81b75a7b
 testing/Main.hs              | 1 +
 testing/OptSupport.hs        | 7 +++++--
 testing/tests/test6          | 9 +++++++++
 testing/tests/test6.expected | 8 ++++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/testing/Main.hs b/testing/Main.hs
index 3728be6..000c7ac 100644
--- a/testing/Main.hs
+++ b/testing/Main.hs
@@ -31,6 +31,7 @@ goldensTests = Framework.testGroup "Goldens tests"
         , "test3"
         , "test4"
         , "test5"
+        , "test6"
         , "if-test"
         , "if-test2"
         , "if-test3"
diff --git a/testing/OptSupport.hs b/testing/OptSupport.hs
index 7d587cc..cb9826d 100644
--- a/testing/OptSupport.hs
+++ b/testing/OptSupport.hs
@@ -114,8 +114,11 @@ fold_EN :: (a -> Expr -> a) -> a -> Insn e x -> a
 
 fold_EE f z e@(Lit _)         = f z e
 fold_EE f z e@(Var _)         = f z e
-fold_EE f z e@(Load addr)     = f (f z addr) e
-fold_EE f z e@(Binop _ e1 e2) = f (f (f z e2) e1) e
+fold_EE f z e@(Load addr)     = f (fold_EE f z addr) e
+fold_EE f z e@(Binop _ e1 e2) =
+  let afterE1 = fold_EE f z e1
+      afterE2 = fold_EE f afterE1 e2
+  in f afterE2 e
 
 fold_EN _ z (Label _)       = z
 fold_EN f z (Assign _ e)    = f z e
diff --git a/testing/tests/test6 b/testing/tests/test6
new file mode 100644
index 0000000..b6fb8b8
--- /dev/null
+++ b/testing/tests/test6
@@ -0,0 +1,9 @@
+-- Tests that we don't remove any of var1 as dead code.
+procName(var1, var2) {
+L0:
+  var1 = m[var2]
+  var1 = m[m[var1]]
+  var1 = m[var1 + var1]
+  var1 = m[m[var1]] - m[var1 + var1]
+  ret(var1)
+}
diff --git a/testing/tests/test6.expected b/testing/tests/test6.expected
new file mode 100644
index 0000000..813cb9a
--- /dev/null
+++ b/testing/tests/test6.expected
@@ -0,0 +1,8 @@
+procName(var1, var2) {
+L0:
+  var1 = m[var2]
+  var1 = m[m[var1]]
+  var1 = m[var1 + var1]
+  var1 = m[m[var1]] - m[var1 + var1]
+  ret(var1)
+}



More information about the ghc-commits mailing list