Commit 49406cee authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Initial algebraic simplification for x*1

Commit for the day, work in progress as I'm failing one of our unit tests outside of the change
parent 2783c649
......@@ -851,6 +851,31 @@ struct find_div_const
}
};
struct find_unit_mult_const
{
auto matcher() const
{
return match::name("mul")(
match::either_arg(0, 1)(match::has_value(1.0f), match::any().bind("x")));
}
void apply(module& m, const match::matcher_result& r) const
{
auto ins = r.result;
auto args = ins->inputs();
auto c_in = r.instructions["x"];
auto res = args.front();
if(args.front() != c_in)
{
res = args.back();
}
m.replace_instruction(ins, res);
}
};
struct find_sub_const
{
auto matcher() const
......@@ -1051,6 +1076,7 @@ void simplify_algebra::apply(module& m) const
find_div_const{},
find_sub_const{},
find_rsqrt{},
find_unit_mult_const{},
find_concat_op{},
find_split_concat{},
find_splits{},
......
......@@ -734,6 +734,33 @@ TEST_CASE(simplify_div_const)
EXPECT(m1 == m2);
}
TEST_CASE(simplify_unit_mult_const)
{
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto unit = m1.add_literal(1);
m1.add_instruction(migraphx::make_op("mul"), x, unit);
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
m2.add_instruction(migraphx::make_op("identity"), x);
}
migraphx::module m3;
{
auto unit = m3.add_literal(1);
auto x = m3.add_parameter("x", {migraphx::shape::int32_type, {1}});
m3.add_instruction(migraphx::make_op("mul"), unit, x);
}
run_pass(m3);
EXPECT((m1 == m3) && (m1 == m2));
}
TEST_CASE(simplify_sub_const)
{
migraphx::module m1;
......@@ -1782,6 +1809,7 @@ TEST_CASE(simplify_mul_slice_conv_horiz_fusion)
}
EXPECT(m1.sort() == m2.sort());
}
TEST_CASE(reorder_reshape_slice)
{
std::vector<int64_t> perm0 = {0, 2, 1, 3};
......
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