Skip to content

Commit

Permalink
auto merge of #10113 : thestinger/rust/expect, r=cmr
Browse files Browse the repository at this point in the history
LLVM is unable to determine this for most cases.

http://llvm-reviews.chandlerc.com/D2034 needs to land upstream before
this is going to have an effect. It's harmless to start generating the
expect hint now.
  • Loading branch information
bors committed Oct 28, 2013
2 parents cd6e9f4 + dde8be6 commit 8852cb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -2844,6 +2844,8 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
ifn!(intrinsics, "llvm.umul.with.overflow.i64",
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));

ifn!(intrinsics, "llvm.expect.i1", [Type::i1(), Type::i1()], Type::i1());

return intrinsics;
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/trans/expr.rs
Expand Up @@ -981,7 +981,9 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
debug!("trans_index: len {}", bcx.val_to_str(len));

let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len);
let bcx = do with_cond(bcx, bounds_check) |bcx| {
let expect = ccx.intrinsics.get_copy(&("llvm.expect.i1"));
let expected = Call(bcx, expect, [bounds_check, C_i1(false)], []);
let bcx = do with_cond(bcx, expected) |bcx| {
controlflow::trans_fail_bounds_check(bcx, index_expr.span, ix_val, len)
};
let elt = InBoundsGEP(bcx, base, [ix_val]);
Expand Down

0 comments on commit 8852cb7

Please sign in to comment.