Commit 782ffec3 authored by Michal Terepeta's avatar Michal Terepeta

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.
parent 19526cc2
......@@ -31,6 +31,7 @@ goldensTests = Framework.testGroup "Goldens tests"
, "test3"
, "test4"
, "test5"
, "test6"
, "if-test"
, "if-test2"
, "if-test3"
......
......@@ -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
......
-- 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)
}
procName(var1, var2) {
L0:
var1 = m[var2]
var1 = m[m[var1]]
var1 = m[var1 + var1]
var1 = m[m[var1]] - m[var1 + var1]
ret(var1)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment