Skip to content

Commit f463e69

Browse files
pcwaltonemberian
authored andcommitted
librustc: Add a small vector optimization for GEPi. Shaves a second off trans, I think?
1 parent 90ad444 commit f463e69

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/librustc/middle/trans/build.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,21 @@ pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
610610

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

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

0 commit comments

Comments
 (0)