Commit e080cf48 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Combine matchers for unit div and multiplcations

Simplfies our code for all operations and reusing original unit tests for overalpping matcher.
parent 37fe2f04
...@@ -851,38 +851,26 @@ struct find_div_const ...@@ -851,38 +851,26 @@ struct find_div_const
} }
}; };
struct find_unit_mult_const struct find_unit_ops
{ {
auto matcher() const auto matcher() const
{ {
return match::name("mul")( auto mul_1 = match::name("mul")(
match::either_arg(0, 1)(match::has_value(1.0f), match::any().bind("x"))); match::either_arg(0, 1)(match::has_value(1.0f), match::any().bind("x")));
auto div_1 =
match::name("div")(match::args(match::any().bind("x"), match::has_value(1.0f)));
return match::any_of(mul_1, div_1);
} }
void apply(module& m, const match::matcher_result& r) const void apply(module& m, const match::matcher_result& r) const
{ {
auto ins = r.result; auto ins = r.result;
auto args = ins->inputs();
auto c_in = r.instructions["x"]; auto c_in = r.instructions["x"];
m.replace_instruction(ins, c_in); m.replace_instruction(ins, c_in);
} }
}; };
struct find_unit_div_const
{
auto matcher() const { return match::name("div")(match::arg(1)(match::has_value(1.0f))); }
void apply(module& m, const match::matcher_result& r) const
{
auto ins = r.result;
auto args = ins->inputs();
m.replace_instruction(ins, args.front());
}
};
struct find_neg_unit_mult_const struct find_neg_unit_mult_const
{ {
auto matcher() const auto matcher() const
...@@ -1101,12 +1089,11 @@ void simplify_algebra::apply(module& m) const ...@@ -1101,12 +1089,11 @@ void simplify_algebra::apply(module& m) const
find_mul_conv{}, find_mul_conv{},
find_mul_slice_conv{}, find_mul_slice_conv{},
find_mul_add{}, find_mul_add{},
find_unit_div_const{}, find_unit_ops{},
find_div_const{}, find_div_const{},
find_sub_const{}, find_sub_const{},
find_rsqrt{}, find_rsqrt{},
find_neg_unit_mult_const{}, find_neg_unit_mult_const{},
find_unit_mult_const{},
find_concat_op{}, find_concat_op{},
find_split_concat{}, find_split_concat{},
find_splits{}, find_splits{},
......
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