Skip to content

Commit

Permalink
librustc: Add a small vector optimization for GEPi. Shaves a second o…
Browse files Browse the repository at this point in the history
…ff trans, I think?
  • Loading branch information
pcwalton authored and emberian committed Jun 28, 2013
1 parent 90ad444 commit f463e69
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,21 @@ pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {

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

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

0 comments on commit f463e69

Please sign in to comment.