"example/vscode:/vscode.git/clone" did not exist on "f56cef53b91240f6790eea413ca22e0b3e50f678"
Commit 4e960940 authored by Paul's avatar Paul
Browse files

Eliminate undefined operator

parent c180f601
...@@ -41,8 +41,8 @@ void dead_code_elimination::apply(program& p) const ...@@ -41,8 +41,8 @@ void dead_code_elimination::apply(program& p) const
// Skip the last instruction // Skip the last instruction
if(i == last) if(i == last)
break; break;
// Skip instruction with empty shape as output unless its a builtin // Skip instruction with empty shape as output unless its a builtin or undefined
if(i->get_shape().elements() == 0 and not(i->name().front() == '@')) if(i->get_shape().elements() == 0 and not(i->name().front() == '@') and not(i->name() == "undefined"))
continue; continue;
assert(bidistance(p, i, last) > 0); assert(bidistance(p, i, last) > 0);
fix([&](auto self, auto leaf) { fix([&](auto self, auto leaf) {
......
#include <migraphx/dead_code_elimination.hpp> #include <migraphx/dead_code_elimination.hpp>
#include <basic_ops.hpp> #include <basic_ops.hpp>
#include <migraphx/operators.hpp>
#include <test.hpp> #include <test.hpp>
struct dce_target struct dce_target
...@@ -111,4 +112,21 @@ TEST_CASE(depth_test) ...@@ -111,4 +112,21 @@ TEST_CASE(depth_test)
EXPECT(result != migraphx::literal{4}); EXPECT(result != migraphx::literal{4});
} }
TEST_CASE(undefined_test)
{
migraphx::program p;
auto one = p.add_literal(1);
auto two = p.add_literal(2);
auto undef = p.add_instruction(migraphx::op::undefined{});
p.add_instruction(sum_op{}, one, two);
auto count = std::distance(p.begin(), p.end());
p.compile(dce_target{});
EXPECT(std::distance(p.begin(), p.end()) == count - 1);
EXPECT(not p.has_instruction(undef));
auto result = p.eval({});
EXPECT(result == migraphx::literal{3});
EXPECT(result != migraphx::literal{4});
}
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
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