Unverified Commit fc9ebb06 authored by kahmed10's avatar kahmed10 Committed by GitHub
Browse files

[quick fix] Change neg unit ops to use insert instruction (#1562)

Using add_instruction for the neg op was causing issues on replace_instruction. Changed to use insert_instruction.  Tests and added a new one that is failing without the change.
parent 2590502c
......@@ -982,7 +982,7 @@ struct find_neg_unit_ops
auto ins = r.result;
auto c_in = r.instructions["x"];
auto neg = m.add_instruction(make_op("neg"), c_in);
auto neg = m.insert_instruction(ins, make_op("neg"), c_in);
m.replace_instruction(ins, neg);
}
};
......
......@@ -1067,16 +1067,18 @@ TEST_CASE(simplify_neg_unit_mult_const)
{
migraphx::module m1;
{
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto unit = m1.add_literal(-1);
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {1, 6}});
auto unit = m1.add_literal(
migraphx::literal{{migraphx::shape::int32_type, {1, 6}}, std::vector<int>(6, -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("neg"), x);
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1, 6}});
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT((m1 == m2));
......@@ -1094,8 +1096,30 @@ TEST_CASE(simplify_neg_unit_mult_const2)
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT((m1 == m2));
}
TEST_CASE(simplify_neg_unit_mult_const_add)
{
migraphx::module m1;
{
auto unit = m1.add_literal(-1);
auto x = m1.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto x2 = m1.add_instruction(migraphx::make_op("mul"), unit, x);
m1.add_instruction(migraphx::make_op("add"), x2, x2);
}
run_pass(m1);
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("add"), x2, x2);
}
EXPECT((m1 == m2));
......@@ -1117,8 +1141,9 @@ TEST_CASE(simplify_neg_unit_mul_const_vec)
migraphx::module m2;
{
auto x = m2.add_parameter("x", x_shape);
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", x_shape);
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
......@@ -1140,8 +1165,9 @@ TEST_CASE(simplify_neg_unit_mul_const_vec2)
migraphx::module m2;
{
auto x = m2.add_parameter("x", x_shape);
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", x_shape);
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
......@@ -1159,8 +1185,9 @@ TEST_CASE(simplify_neg_unit_div_const)
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
......@@ -1182,8 +1209,9 @@ TEST_CASE(simplify_neg_unit_div_const_vec)
migraphx::module m2;
{
auto x = m2.add_parameter("x", x_shape);
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", x_shape);
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
......@@ -1242,8 +1270,9 @@ TEST_CASE(simplify_sub_neg_zero_const)
migraphx::module m2;
{
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", {migraphx::shape::int32_type, {1}});
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
}
......@@ -1264,8 +1293,9 @@ TEST_CASE(simplify_sub_neg_zero_const_vec)
migraphx::module m2;
{
auto x = m2.add_parameter("x", x_shape);
m2.add_instruction(migraphx::make_op("neg"), x);
auto x = m2.add_parameter("x", x_shape);
auto x2 = m2.add_instruction(migraphx::make_op("neg"), x);
m2.add_instruction(migraphx::make_op("identity"), x2);
}
EXPECT(m1 == m2);
......
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