Skip to content

Commit 3f3fc0c

Browse files
committed
rollup merge of #18615 : huonw/simd
2 parents b747f70 + 071c411 commit 3f3fc0c

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,14 +1461,35 @@ pub fn trans_adt<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
14611461
None => {}
14621462
};
14631463

1464-
// Now, we just overwrite the fields we've explicitly specified
1465-
for &(i, ref e) in fields.iter() {
1466-
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
1467-
let e_ty = expr_ty_adjusted(bcx, &**e);
1468-
bcx = trans_into(bcx, &**e, SaveIn(dest));
1469-
let scope = cleanup::CustomScope(custom_cleanup_scope);
1470-
fcx.schedule_lifetime_end(scope, dest);
1471-
fcx.schedule_drop_mem(scope, dest, e_ty);
1464+
if ty::type_is_simd(bcx.tcx(), ty) {
1465+
// This is the constructor of a SIMD type, such types are
1466+
// always primitive machine types and so do not have a
1467+
// destructor or require any clean-up.
1468+
let llty = type_of::type_of(bcx.ccx(), ty);
1469+
1470+
// keep a vector as a register, and running through the field
1471+
// `insertelement`ing them directly into that register
1472+
// (i.e. avoid GEPi and `store`s to an alloca) .
1473+
let mut vec_val = C_undef(llty);
1474+
1475+
for &(i, ref e) in fields.iter() {
1476+
let block_datum = trans(bcx, &**e);
1477+
bcx = block_datum.bcx;
1478+
let position = C_uint(bcx.ccx(), i);
1479+
let value = block_datum.datum.to_llscalarish(bcx);
1480+
vec_val = InsertElement(bcx, vec_val, value, position);
1481+
}
1482+
Store(bcx, vec_val, addr);
1483+
} else {
1484+
// Now, we just overwrite the fields we've explicitly specified
1485+
for &(i, ref e) in fields.iter() {
1486+
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
1487+
let e_ty = expr_ty_adjusted(bcx, &**e);
1488+
bcx = trans_into(bcx, &**e, SaveIn(dest));
1489+
let scope = cleanup::CustomScope(custom_cleanup_scope);
1490+
fcx.schedule_lifetime_end(scope, dest);
1491+
fcx.schedule_drop_mem(scope, dest, e_ty);
1492+
}
14721493
}
14731494

14741495
adt::trans_set_discr(bcx, &*repr, addr, discr);

0 commit comments

Comments
 (0)