Skip to content
Snippets Groups Projects

More rodinia optimization

Merged rarbore2 requested to merge rodinia_opt2 into main
Files
2
+ 71
0
@@ -136,6 +136,77 @@ pub fn predication(editor: &mut FunctionEditor, typing: &Vec<TypeID>) {
bad_branches.insert(branch);
}
}
// Do a quick and dirty rewrite to convert select(a, b, false) to a && b and
// select(a, b, true) to a || b.
for id in editor.node_ids() {
let nodes = &editor.func().nodes;
if let Node::Ternary {
op: TernaryOperator::Select,
first,
second,
third,
} = nodes[id.idx()]
{
if let Some(cons) = nodes[second.idx()].try_constant()
&& editor.get_constant(cons).is_false()
{
editor.edit(|mut edit| {
let inv = edit.add_node(Node::Unary {
op: UnaryOperator::Not,
input: first,
});
let node = edit.add_node(Node::Binary {
op: BinaryOperator::And,
left: inv,
right: third,
});
edit = edit.replace_all_uses(id, node)?;
edit.delete_node(id)
});
} else if let Some(cons) = nodes[third.idx()].try_constant()
&& editor.get_constant(cons).is_false()
{
editor.edit(|mut edit| {
let node = edit.add_node(Node::Binary {
op: BinaryOperator::And,
left: first,
right: second,
});
edit = edit.replace_all_uses(id, node)?;
edit.delete_node(id)
});
} else if let Some(cons) = nodes[second.idx()].try_constant()
&& editor.get_constant(cons).is_true()
{
editor.edit(|mut edit| {
let node = edit.add_node(Node::Binary {
op: BinaryOperator::Or,
left: first,
right: third,
});
edit = edit.replace_all_uses(id, node)?;
edit.delete_node(id)
});
} else if let Some(cons) = nodes[third.idx()].try_constant()
&& editor.get_constant(cons).is_true()
{
editor.edit(|mut edit| {
let inv = edit.add_node(Node::Unary {
op: UnaryOperator::Not,
input: first,
});
let node = edit.add_node(Node::Binary {
op: BinaryOperator::Or,
left: inv,
right: second,
});
edit = edit.replace_all_uses(id, node)?;
edit.delete_node(id)
});
}
}
}
}
/*
Loading