11
11
use llvm:: { self , ValueRef } ;
12
12
use rustc:: ty:: { self , Ty } ;
13
13
use rustc:: ty:: cast:: { CastTy , IntTy } ;
14
- use rustc:: ty:: layout:: { self , Layout , LayoutTyper , Primitive } ;
14
+ use rustc:: ty:: layout:: { Layout , LayoutTyper } ;
15
15
use rustc:: mir:: tcx:: LvalueTy ;
16
16
use rustc:: mir;
17
17
use rustc:: middle:: lang_items:: ExchangeMallocFnLangItem ;
@@ -107,6 +107,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
107
107
let align = dest. alignment . to_align ( ) ;
108
108
109
109
if let OperandValue :: Immediate ( v) = tr_elem. val {
110
+ // Use llvm.memset.p0i8.* to initialize all zero arrays
110
111
if common:: is_const_integral ( v) && common:: const_to_uint ( v) == 0 {
111
112
let align = align. unwrap_or_else ( || bcx. ccx . align_of ( tr_elem. ty ) ) ;
112
113
let align = C_i32 ( bcx. ccx , align as i32 ) ;
@@ -116,20 +117,15 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
116
117
base:: call_memset ( & bcx, base, fill, size, align, false ) ;
117
118
return bcx;
118
119
}
119
- }
120
120
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 ) {
126
123
let align = align. unwrap_or_else ( || bcx. ccx . align_of ( tr_elem. ty ) ) ;
127
124
let align = C_i32 ( bcx. ccx , align as i32 ) ;
128
125
let fill = tr_elem. immediate ( ) ;
129
126
base:: call_memset ( & bcx, base, fill, size, align, false ) ;
130
127
return bcx;
131
128
}
132
- _ => ( )
133
129
}
134
130
135
131
tvec:: slice_for_each ( & bcx, base, tr_elem. ty , size, |bcx, llslot, loop_bb| {
0 commit comments