about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-02-06 05:37:49 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-02-06 16:21:08 +0530
commitcfae247ce0423d3b6a0114b8b64826cdec461edc (patch)
tree8fe5c5ce3c04af18678ef14eaa9e454c8f990418 /src
parentd1a1d339ef3fb89599f74c0cbae2183c7cf2ee25 (diff)
parentdb8f2d590385786c176b5f7d9e887814d31db9ad (diff)
downloadrust-cfae247ce0423d3b6a0114b8b64826cdec461edc.tar.gz
rust-cfae247ce0423d3b6a0114b8b64826cdec461edc.zip
Rollup merge of #21941 - dotdash:with_cond_false, r=Aatch
 Currently \"k / 2\" generates one (k: uint) or two (k: int) \"br false,
...\" instructions and the corresponding basic blocks, producing quite
some noise and making the code unnecessarily hard to read.

Additionally we can skip translation if the code would end up
unreachable anyway.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/trans/_match.rs6
-rw-r--r--src/librustc_trans/trans/base.rs6
2 files changed, 10 insertions, 2 deletions
diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs
index 1fea8f6aa3b..1d7358b11c1 100644
--- a/src/librustc_trans/trans/_match.rs
+++ b/src/librustc_trans/trans/_match.rs
@@ -889,11 +889,13 @@ fn compile_guard<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         }
     }
 
+    for (_, &binding_info) in &data.bindings_map {
+        bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
+    }
+
     with_cond(bcx, Not(bcx, val, guard_expr.debug_loc()), |bcx| {
-        // Guard does not match: remove all bindings from the lllocals table
         for (_, &binding_info) in &data.bindings_map {
             call_lifetime_end(bcx, binding_info.llmatch);
-            bcx.fcx.lllocals.borrow_mut().remove(&binding_info.id);
         }
         match chk {
             // If the default arm is the only one left, move on to the next
diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs
index 38051a647ca..58c7a979c3d 100644
--- a/src/librustc_trans/trans/base.rs
+++ b/src/librustc_trans/trans/base.rs
@@ -1081,6 +1081,12 @@ pub fn with_cond<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
     F: FnOnce(Block<'blk, 'tcx>) -> Block<'blk, 'tcx>,
 {
     let _icx = push_ctxt("with_cond");
+
+    if bcx.unreachable.get() ||
+            (common::is_const(val) && common::const_to_uint(val) == 0) {
+        return bcx;
+    }
+
     let fcx = bcx.fcx;
     let next_cx = fcx.new_temp_block("next");
     let cond_cx = fcx.new_temp_block("cond");