1111use llvm:: { self , ValueRef } ;
1212use rustc:: ty:: { self , Ty } ;
1313use rustc:: ty:: cast:: { CastTy , IntTy } ;
14- use rustc:: ty:: layout:: { self , Layout , LayoutTyper , Primitive } ;
14+ use rustc:: ty:: layout:: { Layout , LayoutTyper } ;
1515use rustc:: mir:: tcx:: LvalueTy ;
1616use rustc:: mir;
1717use rustc:: middle:: lang_items:: ExchangeMallocFnLangItem ;
@@ -107,6 +107,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
107107 let align = dest. alignment . to_align ( ) ;
108108
109109 if let OperandValue :: Immediate ( v) = tr_elem. val {
110+ // Use llvm.memset.p0i8.* to initialize all zero arrays
110111 if common:: is_const_integral ( v) && common:: const_to_uint ( v) == 0 {
111112 let align = align. unwrap_or_else ( || bcx. ccx . align_of ( tr_elem. ty ) ) ;
112113 let align = C_i32 ( bcx. ccx , align as i32 ) ;
@@ -116,20 +117,15 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
116117 base:: call_memset ( & bcx, base, fill, size, align, false ) ;
117118 return bcx;
118119 }
119- }
120120
121- // Use llvm.memset.p0i8.* to initialize byte arrays
122- let elem_layout = bcx. ccx . layout_of ( tr_elem. ty ) . layout ;
123- match * elem_layout {
124- Layout :: Scalar { value : Primitive :: Int ( layout:: I8 ) , .. } |
125- Layout :: CEnum { discr : layout:: I8 , .. } => {
121+ // Use llvm.memset.p0i8.* to initialize byte arrays
122+ if common:: val_ty ( v) == Type :: i8 ( bcx. ccx ) {
126123 let align = align. unwrap_or_else ( || bcx. ccx . align_of ( tr_elem. ty ) ) ;
127124 let align = C_i32 ( bcx. ccx , align as i32 ) ;
128125 let fill = tr_elem. immediate ( ) ;
129126 base:: call_memset ( & bcx, base, fill, size, align, false ) ;
130127 return bcx;
131128 }
132- _ => ( )
133129 }
134130
135131 tvec:: slice_for_each ( & bcx, base, tr_elem. ty , size, |bcx, llslot, loop_bb| {
0 commit comments