Skip to content

Commit

Permalink
Implement common subexpression elimination
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Steuernagel <[email protected]>
  • Loading branch information
LucasSte committed Nov 4, 2021
1 parent 7c05cb1 commit c74fec1
Show file tree
Hide file tree
Showing 16 changed files with 2,107 additions and 826 deletions.
42 changes: 42 additions & 0 deletions examples/test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
contract foo {

struct stTest {
int a;
uint b;
}

function test6(int a, int b) public view returns (int ret) {
stTest instance = stTest(2, 3);
int x = a + b + instance.a;
if(x + int(instance.b) < 0) {
// Erro aqui?
uint p = uint(a+b+instance.a);
bool e = p > 50;
}

int8 trunc = int8(x);
bool e2 = trunc > 2;
int8 trunc2 = 8 + int8(x);
bool e3 = trunc2 < trunc;
bool e4 = e2 || e3;

if (trunc2 < trunc && trunc > 2) {
int p2 = a+b;
int p3 = p2 - x + a + b;
int p4 = p2-x;
int p5 = p3 + a*b+45;

if (p5 !=0) {
uint16 t1 = uint16(p3 + a*b +45);
uint32 t2 = uint32(a*b);
bool e5 = t2 < t1;
}

ret = p3 + a*b + 45;
}

ret = a*b;
}


}
7 changes: 7 additions & 0 deletions src/bin/solang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ fn main() {
.long("math-overflow")
.display_order(5),
)
.arg(
Arg::with_name("COMMONEXPRESSIONELIMINATION")
.help("Disable common subexpression elimination")
.long("common-elimination")
.display_order(6),
)
.arg(
Arg::with_name("LANGUAGESERVER")
.help("Start language server on stdin/stdout")
Expand Down Expand Up @@ -307,6 +313,7 @@ fn main() {
strength_reduce: !matches.is_present("STRENGTHREDUCE"),
constant_folding: !matches.is_present("CONSTANTFOLDING"),
vector_to_slice: !matches.is_present("VECTORTOSLICE"),
common_subexpression_elimination: !matches.is_present("COMMONEXPRESSIONELIMINATION"),
math_overflow_check,
opt_level,
};
Expand Down
Loading

0 comments on commit c74fec1

Please sign in to comment.