"vscode:/vscode.git/clone" did not exist on "5f0ac59981554b96dee90393ffebcd30d4cf4053"
Commit 37fe2f04 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Simplify algebra for x / 1 operations

Done to satisfy simplifications specified by #1236 .  Just replace every  parameter divided by 1 with itself. It's assumed that the eliminate_identity() pass will handle generated identity operators in our run_pass()
parent 61ef5263
......@@ -870,6 +870,19 @@ struct find_unit_mult_const
}
};
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
{
auto matcher() const
......@@ -887,6 +900,7 @@ struct find_neg_unit_mult_const
auto neg = m.add_instruction(make_op("neg"), c_in);
m.replace_instruction(ins, neg);
m.replace_instruction(ins, args.front());
}
};
......@@ -1087,6 +1101,7 @@ void simplify_algebra::apply(module& m) const
find_mul_conv{},
find_mul_slice_conv{},
find_mul_add{},
find_unit_div_const{},
find_div_const{},
find_sub_const{},
find_rsqrt{},
......
......@@ -761,6 +761,26 @@ TEST_CASE(simplify_unit_mult_const)
EXPECT((m1 == m3) && (m1 == m2));
}
TEST_CASE(simplify_unit_div_const)
{
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto unit = m1.add_literal(1);
auto div = m1.add_instruction(migraphx::make_op("div"), x, unit);
m1.add_return({div});
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
m2.add_return({x});
}
EXPECT(m1 == m2);
}
TEST_CASE(simplify_neg_unit_mult_const)
{
migraphx::module m1;
......
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