Commit 013e18cf authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Simplify algebra of negative division operations

Part of changes that go wtih #1236. Reverts -1 divide operations to a simple negation of the parameter
parent 86c464ca
......@@ -895,6 +895,20 @@ struct find_neg_unit_mult_const
}
};
struct find_neg_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();
auto neg = m.add_instruction(make_op("neg"), args.front());
m.replace_instruction(ins, neg);
}
};
struct find_sub_const
{
auto matcher() const
......@@ -1093,6 +1107,7 @@ void simplify_algebra::apply(module& m) const
find_mul_slice_conv{},
find_mul_add{},
find_unit_ops{},
find_neg_unit_div_const{},
find_div_const{},
find_sub_const{},
find_rsqrt{},
......
......@@ -835,6 +835,25 @@ TEST_CASE(simplify_neg_unit_mult_const)
EXPECT((m1 == m3) && (m1 == m2));
}
TEST_CASE(simplify_neg_unit_div_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("div"), 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("neg"), x);
}
EXPECT(m1 == m2);
}
TEST_CASE(simplify_sub_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