Skip to content
Snippets Groups Projects
Unverified Commit ea49ede5 authored by thorstenhater's avatar thorstenhater Committed by GitHub
Browse files

Modcc/optimise divide by const (#1043)

Add a simple re-write to eliminate division by a known constant.
parent dbea3c0a
No related branches found
No related tags found
No related merge requests found
......@@ -430,6 +430,9 @@ public:
else if (expr_value(rhs)==1) {
result_ = e->lhs()->clone();
}
else if (is_number(rhs)) {
result_ = make_expression<MulBinaryExpression>(loc, std::move(lhs), make_expression<NumberExpression>(loc, 1.0/expr_value(rhs)));
}
else {
result_ = make_expression<DivBinaryExpression>(loc, std::move(lhs), std::move(rhs));
}
......
......@@ -200,7 +200,7 @@ TEST(CPrinter, proc_body_const) {
TEST(CPrinter, proc_body_inlined) {
const char* expected =
"r_9_=s2[i_]/3;\n"
"r_9_=s2[i_]*0.33333333333333331;\n"
"r_8_=s1[i_]+2;\n"
"if(s1[i_]==3){\n"
" r_7_=2*r_8_;\n"
......
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