Skip to content

Commit 8852cb7

Browse files
committed
auto merge of #10113 : thestinger/rust/expect, r=cmr
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.
2 parents cd6e9f4 + dde8be6 commit 8852cb7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/librustc/middle/trans/base.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2844,6 +2844,8 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
28442844
ifn!(intrinsics, "llvm.umul.with.overflow.i64",
28452845
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
28462846

2847+
ifn!(intrinsics, "llvm.expect.i1", [Type::i1(), Type::i1()], Type::i1());
2848+
28472849
return intrinsics;
28482850
}
28492851

src/librustc/middle/trans/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,9 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
981981
debug!("trans_index: len {}", bcx.val_to_str(len));
982982

983983
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len);
984-
let bcx = do with_cond(bcx, bounds_check) |bcx| {
984+
let expect = ccx.intrinsics.get_copy(&("llvm.expect.i1"));
985+
let expected = Call(bcx, expect, [bounds_check, C_i1(false)], []);
986+
let bcx = do with_cond(bcx, expected) |bcx| {
985987
controlflow::trans_fail_bounds_check(bcx, index_expr.span, ix_val, len)
986988
};
987989
let elt = InBoundsGEP(bcx, base, [ix_val]);

0 commit comments

Comments
 (0)