aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-10-12 03:16:37 +0800
committerchriseth <chris@ethereum.org>2018-10-16 22:18:39 +0800
commitffe44536fe30381f8365b7ce9276660be5a6656b (patch)
treee64f5582273d8a7124dbecb107b2ba38e8001658
parenta320eec7d38f98a1fbb9f6267e5e30cfae5c59cf (diff)
downloaddexon-solidity-ffe44536fe30381f8365b7ce9276660be5a6656b.tar.gz
dexon-solidity-ffe44536fe30381f8365b7ce9276660be5a6656b.tar.zst
dexon-solidity-ffe44536fe30381f8365b7ce9276660be5a6656b.zip
Add a "full simplify" test that applies multiple elementary transforms.
-rw-r--r--test/libyul/YulOptimizerTest.cpp12
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/constant_propagation.yul10
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/constants.yul9
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/identity_rules_complex.yul9
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/identity_rules_negative.yul10
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/identity_rules_simple.yul11
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/including_function_calls.yul13
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul17
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/invariant.yul17
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/mod_and_1.yul9
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/mod_and_2.yul9
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_arguments.yul14
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_names.yul17
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_equality_not_movable.yul14
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/not_applied_removes_non_constant_and_not_movable.yul12
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/reversed.yul10
-rw-r--r--test/libyul/yulOptimizerTests/fullSimplify/smoke.yul5
17 files changed, 198 insertions, 0 deletions
diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp
index bbae9bb4..d1990edb 100644
--- a/test/libyul/YulOptimizerTest.cpp
+++ b/test/libyul/YulOptimizerTest.cpp
@@ -148,6 +148,18 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
disambiguate();
ExpressionSimplifier::run(*m_ast);
}
+ else if (m_optimizerStep == "fullSimplify")
+ {
+ disambiguate();
+ NameDispenser nameDispenser;
+ nameDispenser.m_usedNames = NameCollector(*m_ast).names();
+ ExpressionSplitter{nameDispenser}(*m_ast);
+ CommonSubexpressionEliminator{}(*m_ast);
+ ExpressionSimplifier::run(*m_ast);
+ UnusedPruner::runUntilStabilised(*m_ast);
+ ExpressionJoiner::run(*m_ast);
+ ExpressionJoiner::run(*m_ast);
+ }
else if (m_optimizerStep == "unusedPruner")
{
disambiguate();
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/constant_propagation.yul b/test/libyul/yulOptimizerTests/fullSimplify/constant_propagation.yul
new file mode 100644
index 00000000..90a3e16d
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/constant_propagation.yul
@@ -0,0 +1,10 @@
+{
+ let a := add(7, sub(mload(0), 7))
+ mstore(a, 0)
+}
+// ----
+// fullSimplify
+// {
+// let _2 := 0
+// mstore(mload(_2), _2)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/constants.yul b/test/libyul/yulOptimizerTests/fullSimplify/constants.yul
new file mode 100644
index 00000000..b9c7c1fc
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/constants.yul
@@ -0,0 +1,9 @@
+{
+ let a := add(1, mul(3, 4))
+ mstore(0, a)
+}
+// ----
+// fullSimplify
+// {
+// mstore(0, 13)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_complex.yul b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_complex.yul
new file mode 100644
index 00000000..4b17d7ea
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_complex.yul
@@ -0,0 +1,9 @@
+{
+ let a := sub(calldataload(0), calldataload(0))
+ mstore(a, 0)
+}
+// ----
+// fullSimplify
+// {
+// mstore(0, 0)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_negative.yul b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_negative.yul
new file mode 100644
index 00000000..a1737efa
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_negative.yul
@@ -0,0 +1,10 @@
+{
+ let a := sub(calldataload(1), calldataload(0))
+ mstore(0, a)
+}
+// ----
+// fullSimplify
+// {
+// let _1 := 0
+// mstore(_1, sub(calldataload(1), calldataload(_1)))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_simple.yul b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_simple.yul
new file mode 100644
index 00000000..22a358fd
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/identity_rules_simple.yul
@@ -0,0 +1,11 @@
+{
+ let a := mload(0)
+ mstore(0, sub(a, a))
+}
+// ----
+// fullSimplify
+// {
+// let _1 := 0
+// pop(mload(_1))
+// mstore(_1, 0)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/including_function_calls.yul b/test/libyul/yulOptimizerTests/fullSimplify/including_function_calls.yul
new file mode 100644
index 00000000..fa3ff07c
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/including_function_calls.yul
@@ -0,0 +1,13 @@
+{
+ function f() -> a {}
+ let b := add(7, sub(f(), 7))
+ mstore(b, 0)
+}
+// ----
+// fullSimplify
+// {
+// function f() -> a
+// {
+// }
+// mstore(f(), 0)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul b/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul
new file mode 100644
index 00000000..f1b40301
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul
@@ -0,0 +1,17 @@
+{
+ let x := calldataload(3)
+ for { let a := 10 } iszero(eq(a, sub(x, calldataload(3)))) { a := add(a, 1) } {}
+}
+// ----
+// fullSimplify
+// {
+// for {
+// let a := 10
+// }
+// iszero(iszero(a))
+// {
+// a := add(a, 1)
+// }
+// {
+// }
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/invariant.yul b/test/libyul/yulOptimizerTests/fullSimplify/invariant.yul
new file mode 100644
index 00000000..a8eedef1
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/invariant.yul
@@ -0,0 +1,17 @@
+{
+ let a := calldataload(sub(7, 7))
+ let b := sub(a, 0)
+ // Below, `b` is not eliminated, because
+ // we run CSE and then Simplify.
+ // Elimination of `b` would require another
+ // run of CSE afterwards.
+ mstore(b, eq(calldataload(0), a))
+}
+// ----
+// fullSimplify
+// {
+// let a := calldataload(0)
+// let _4 := 0
+// let b := a
+// mstore(b, eq(calldataload(_4), a))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/mod_and_1.yul b/test/libyul/yulOptimizerTests/fullSimplify/mod_and_1.yul
new file mode 100644
index 00000000..bba16a94
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/mod_and_1.yul
@@ -0,0 +1,9 @@
+{
+ mstore(0, mod(calldataload(0), exp(2, 8)))
+}
+// ----
+// fullSimplify
+// {
+// let _4 := 0
+// mstore(_4, and(calldataload(_4), 255))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/mod_and_2.yul b/test/libyul/yulOptimizerTests/fullSimplify/mod_and_2.yul
new file mode 100644
index 00000000..4a6eaa52
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/mod_and_2.yul
@@ -0,0 +1,9 @@
+{
+ mstore(0, mod(calldataload(0), exp(2, 255)))
+}
+// ----
+// fullSimplify
+// {
+// let _4 := 0
+// mstore(_4, and(calldataload(_4), 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_arguments.yul b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_arguments.yul
new file mode 100644
index 00000000..0c5e3ed9
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_arguments.yul
@@ -0,0 +1,14 @@
+{
+ function f(a) -> b { }
+ mstore(0, sub(f(0), f(1)))
+}
+// ----
+// fullSimplify
+// {
+// function f(a) -> b
+// {
+// }
+// let _2 := f(1)
+// let _3 := 0
+// mstore(_3, sub(f(_3), _2))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_names.yul b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_names.yul
new file mode 100644
index 00000000..90e89fe1
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_different_names.yul
@@ -0,0 +1,17 @@
+{
+ function f1() -> a { }
+ function f2() -> b { }
+ let c := sub(f1(), f2())
+ mstore(0, c)
+}
+// ----
+// fullSimplify
+// {
+// function f1() -> a
+// {
+// }
+// function f2() -> b
+// {
+// }
+// mstore(0, sub(f1(), f2()))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_equality_not_movable.yul b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_equality_not_movable.yul
new file mode 100644
index 00000000..92e50ebe
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_function_call_equality_not_movable.yul
@@ -0,0 +1,14 @@
+// Even if the functions pass the equality check, they are not movable.
+{
+ function f() -> a { }
+ let b := sub(f(), f())
+ mstore(0, b)
+}
+// ----
+// fullSimplify
+// {
+// function f() -> a
+// {
+// }
+// mstore(0, sub(f(), f()))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/not_applied_removes_non_constant_and_not_movable.yul b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_removes_non_constant_and_not_movable.yul
new file mode 100644
index 00000000..7dcdc280
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/not_applied_removes_non_constant_and_not_movable.yul
@@ -0,0 +1,12 @@
+// div is eliminated, but keccak256 has side-effects.
+{
+ let a := div(keccak256(0, 0), 0)
+ mstore(0, a)
+}
+// ----
+// fullSimplify
+// {
+// let _1 := 0
+// pop(keccak256(_1, _1))
+// mstore(_1, 0)
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/reversed.yul b/test/libyul/yulOptimizerTests/fullSimplify/reversed.yul
new file mode 100644
index 00000000..fb916e6a
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/reversed.yul
@@ -0,0 +1,10 @@
+{
+ let a := add(0, mload(0))
+ mstore(0, a)
+}
+// ----
+// fullSimplify
+// {
+// let _1 := 0
+// mstore(_1, mload(_1))
+// }
diff --git a/test/libyul/yulOptimizerTests/fullSimplify/smoke.yul b/test/libyul/yulOptimizerTests/fullSimplify/smoke.yul
new file mode 100644
index 00000000..a4fbb899
--- /dev/null
+++ b/test/libyul/yulOptimizerTests/fullSimplify/smoke.yul
@@ -0,0 +1,5 @@
+{ }
+// ----
+// fullSimplify
+// {
+// }