summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-30 20:26:06 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-30 20:26:06 +0800
commit9d6e35aea551d291a3b687908de35045e572c0a1 (patch)
tree1087b68c15deb05b09f668bce395c38dadf2d07d /src
parent64dffed7a9142eb68fce878984f3572d1231d6f5 (diff)
downloadmrust-9d6e35aea551d291a3b687908de35045e572c0a1.tar.gz
MIR Gen - Don't emit `If` terminator if known true/false
Diffstat (limited to 'src')
-rw-r--r--src/mir/from_hir.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 3aedd680..5a0efc29 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -675,6 +675,18 @@ namespace {
}
}
+ if( auto* cond_lit = dynamic_cast<::HIR::ExprNode_Literal*>(cond_p->get()) )
+ {
+ DEBUG("- constant condition");
+ if( cond_lit->m_data.as_Boolean() ) {
+ m_builder.end_block( ::MIR::Terminator::make_Goto({ true_branch }) );
+ }
+ else {
+ m_builder.end_block( ::MIR::Terminator::make_Goto({ false_branch }) );
+ }
+ return ;
+ }
+
// If short-circuiting didn't apply, emit condition
::MIR::LValue decision_val;
{