]> git.lizzy.rs Git - rust.git/blobdiff - src/base.rs
Use don't unroll loop in Rvalue::Repeat
[rust.git] / src / base.rs
index 7aca709fba141ce3d5658410813cdc79030ad1ed..cae2115ab181b630f67b1e090df951313c953e0c 100644 (file)
@@ -105,7 +105,7 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
         );
     });
 
-    // If the return block is not reachable, then the SSA builder may have inserted a `iconst.i128`
+    // If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128`
     // instruction, which doesn't have an encoding.
     context.compute_cfg();
     context.compute_domtree();
@@ -693,10 +693,29 @@ fn is_fat_ptr<'tcx>(
                         .val
                         .try_to_bits(fx.tcx.data_layout.pointer_size)
                         .unwrap();
-                    for i in 0..times {
-                        let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
+                    if fx.clif_type(operand.layout().ty) == Some(types::I8) {
+                        let times = fx.bcx.ins().iconst(fx.pointer_type, times as i64);
+                        // FIXME use emit_small_memset where possible
+                        let addr = lval.to_ptr().get_addr(fx);
+                        let val = operand.load_scalar(fx);
+                        fx.bcx.call_memset(fx.cx.module.target_config(), addr, val, times);
+                    } else {
+                        let loop_block = fx.bcx.create_block();
+                        let done_block = fx.bcx.create_block();
+                        let index = fx.bcx.append_block_param(loop_block, fx.pointer_type);
+                        let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
+                        fx.bcx.ins().jump(loop_block, &[zero]);
+
+                        fx.bcx.switch_to_block(loop_block);
                         let to = lval.place_index(fx, index);
                         to.write_cvalue(fx, operand);
+
+                        let index = fx.bcx.ins().iadd_imm(index, 1);
+                        let done = fx.bcx.ins().icmp_imm(IntCC::Equal, index, times as i64);
+                        fx.bcx.ins().brz(done, loop_block, &[index]);
+                        fx.bcx.ins().jump(done_block, &[]);
+
+                        fx.bcx.switch_to_block(done_block);
                     }
                 }
                 Rvalue::Len(place) => {