summaryrefslogtreecommitdiff
path: root/src/mir/from_hir.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-17 10:03:53 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-17 10:03:53 +0800
commite6116ce077b1f99fe3e510e23bdb5c4646adbcca (patch)
tree93b48a3b87740cb4bcc765d3e7a983519d0de2c0 /src/mir/from_hir.cpp
parent8062b43a179b645df1fc11d8b1b1112baa43d964 (diff)
downloadmrust-e6116ce077b1f99fe3e510e23bdb5c4646adbcca.tar.gz
MIR Optimisation and efficiency tweaks
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r--src/mir/from_hir.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 7d5853dd..9db4b115 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -551,13 +551,29 @@ namespace {
{
TRACE_FUNCTION_FR("_If", "_If");
- this->visit_node_ptr(node.m_cond);
+ bool reverse = false;
+ {
+ auto* cond_p = &node.m_cond;
+ while( auto* cond_uni = dynamic_cast<::HIR::ExprNode_UniOp*>(cond_p->get()) )
+ {
+ ASSERT_BUG(cond_uni->span(), cond_uni->m_op == ::HIR::ExprNode_UniOp::Op::Invert, "");
+ cond_p = &cond_uni->m_value;
+ reverse = !reverse;
+ }
+
+ this->visit_node_ptr(*cond_p);
+ }
auto decision_val = m_builder.get_result_in_lvalue(node.m_cond->span(), node.m_cond->m_res_type);
auto true_branch = m_builder.new_bb_unlinked();
auto false_branch = m_builder.new_bb_unlinked();
auto next_block = m_builder.new_bb_unlinked();
- m_builder.end_block( ::MIR::Terminator::make_If({ mv$(decision_val), true_branch, false_branch }) );
+ if( reverse ) {
+ m_builder.end_block( ::MIR::Terminator::make_If({ mv$(decision_val), false_branch, true_branch }) );
+ }
+ else {
+ m_builder.end_block( ::MIR::Terminator::make_If({ mv$(decision_val), true_branch, false_branch }) );
+ }
auto result_val = m_builder.new_temporary(node.m_res_type);