Skip to content

Commit bb59d61

Browse files
committed
Use don't unroll loop in Rvalue::Repeat
Fixes #1081
1 parent 50e8f22 commit bb59d61

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

example/mini_core.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ unsafe impl Copy for char {}
5858
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
5959
unsafe impl<T: ?Sized> Copy for *const T {}
6060
unsafe impl<T: ?Sized> Copy for *mut T {}
61+
unsafe impl<T: Copy> Copy for Option<T> {}
6162

6263
#[lang = "sync"]
6364
pub unsafe trait Sync {}
@@ -336,6 +337,24 @@ impl<T: ?Sized> PartialEq for *const T {
336337
}
337338
}
338339

340+
impl <T: PartialEq> PartialEq for Option<T> {
341+
fn eq(&self, other: &Self) -> bool {
342+
match (self, other) {
343+
(Some(lhs), Some(rhs)) => *lhs == *rhs,
344+
(None, None) => true,
345+
_ => false,
346+
}
347+
}
348+
349+
fn ne(&self, other: &Self) -> bool {
350+
match (self, other) {
351+
(Some(lhs), Some(rhs)) => *lhs != *rhs,
352+
(None, None) => false,
353+
_ => true,
354+
}
355+
}
356+
}
357+
339358
#[lang = "neg"]
340359
pub trait Neg {
341360
type Output;

example/mini_core_hello_world.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ fn main() {
285285
let slice_ptr = &[] as *const [u8];
286286
slice_ptr as *const u8;
287287

288+
let repeat = [Some(42); 2];
289+
assert_eq!(repeat[0], Some(42));
290+
assert_eq!(repeat[1], Some(42));
291+
288292
#[cfg(not(jit))]
289293
test_tls();
290294

src/base.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,29 @@ fn trans_stmt<'tcx>(
693693
.val
694694
.try_to_bits(fx.tcx.data_layout.pointer_size)
695695
.unwrap();
696-
for i in 0..times {
697-
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
696+
if fx.clif_type(operand.layout().ty) == Some(types::I8) {
697+
let times = fx.bcx.ins().iconst(fx.pointer_type, times as i64);
698+
// FIXME use emit_small_memset where possible
699+
let addr = lval.to_ptr().get_addr(fx);
700+
let val = operand.load_scalar(fx);
701+
fx.bcx.call_memset(fx.cx.module.target_config(), addr, val, times);
702+
} else {
703+
let loop_block = fx.bcx.create_block();
704+
let done_block = fx.bcx.create_block();
705+
let index = fx.bcx.append_block_param(loop_block, fx.pointer_type);
706+
let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
707+
fx.bcx.ins().jump(loop_block, &[zero]);
708+
709+
fx.bcx.switch_to_block(loop_block);
698710
let to = lval.place_index(fx, index);
699711
to.write_cvalue(fx, operand);
712+
713+
let index = fx.bcx.ins().iadd_imm(index, 1);
714+
let done = fx.bcx.ins().icmp_imm(IntCC::Equal, index, times as i64);
715+
fx.bcx.ins().brz(done, loop_block, &[index]);
716+
fx.bcx.ins().jump(done_block, &[]);
717+
718+
fx.bcx.switch_to_block(done_block);
700719
}
701720
}
702721
Rvalue::Len(place) => {

0 commit comments

Comments
 (0)