Skip to content

Commit b4f8373

Browse files
committed
librustc: Add a small vector optimization for GEPi. Shaves a second off trans, I think?
1 parent 09cddd8 commit b4f8373

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/librustc/middle/trans/build.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,21 @@ pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
605605

606606
// Simple wrapper around GEP that takes an array of ints and wraps them
607607
// in C_i32()
608-
//
609-
// FIXME #6571: Use a small-vector optimization to avoid allocations here.
608+
#[inline]
610609
pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
611-
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
612-
count_insn(cx, "gepi");
613-
return InBoundsGEP(cx, base, v);
610+
// Small vector optimization. This should catch 100% of the cases that
611+
// we care about.
612+
if ixs.len() < 16 {
613+
let mut small_vec = [ C_i32(0), ..16 ];
614+
for ixs.eachi |i, &ix| {
615+
small_vec[i] = C_i32(ix as i32)
616+
}
617+
InBoundsGEP(cx, base, small_vec.slice(0, ixs.len()))
618+
} else {
619+
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
620+
count_insn(cx, "gepi");
621+
InBoundsGEP(cx, base, v)
622+
}
614623
}
615624

616625
pub fn InBoundsGEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) ->

0 commit comments

Comments
 (0)