Skip to content

Commit 1d8dcc7

Browse files
committed
ignore simd temps
1 parent 4f98e94 commit 1d8dcc7

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

compiler/rustc_mir_transform/src/promote_consts_local_arrays.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> MirPass<'tcx> for PromoteArraysOpt<'tcx> {
7676
if let Some(ctx) = tcx.hir().body_const_context(body.source.def_id()) {
7777
use hir::ConstContext::*;
7878
match ctx {
79-
Static(_) | Const {inline: _ } => return,
79+
Static(_) | Const { inline: _ } => return,
8080
_ => {}
8181
}
8282
}
@@ -178,16 +178,29 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
178178

179179
#[instrument(level = "debug", skip(self, rvalue))]
180180
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
181-
if !rvalue.ty(&self.ccx.body.local_decls, self.ccx.tcx).is_array() {
181+
self.super_rvalue(rvalue, location);
182+
183+
let rvalue_ty = rvalue.ty(&self.ccx.body.local_decls, self.ccx.tcx);
184+
if !rvalue_ty.is_array() {
182185
debug!(?rvalue);
183186
}
184187

185-
self.super_rvalue(rvalue, location);
186-
187-
let Rvalue::Aggregate(kind, _ops) = rvalue else {
188+
let Rvalue::Aggregate(kind, operands) = rvalue else {
188189
return;
189190
};
190191

192+
if let ty::Adt(adt, _) = rvalue_ty.kind()
193+
&& adt.repr().simd()
194+
{
195+
debug!("ignore #[repr(simd)]");
196+
if let Some(first) = operands.iter().next()
197+
&& let Operand::Copy(place) | Operand::Move(place) = first
198+
{
199+
self.temps[place.local] = TempState::Unpromotable;
200+
}
201+
return;
202+
}
203+
191204
debug!("pushing a candidate of type {:?} @ {:?}", kind, location);
192205
self.candidates.push(Candidate { location });
193206
}

tests/mir-opt/const_array_locals.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ test-mir-pass: PromoteArraysOpt
2+
#![feature(repr_simd)]
3+
4+
#[repr(simd)]
5+
struct F32x8([f32; 8]);
26

37
// EMIT_MIR const_array_locals.main.PromoteArraysOpt.diff
48
// CHECK-LABEL: fn main() -> () {
@@ -28,6 +32,8 @@ pub fn main() {
2832
consume([255, 105, 15, 39, 62, 251, 191, 178, 9, 4, 56, 221,
2933
193, 164, 194, 197, 6, 243, 218, 171, 87, 247, 104,
3034
159, 22, 157, 105, 31, 96, 173, 50, 1,]);
35+
36+
let _f = F32x8([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
3137
}
3238

3339
fn consume(_arr: [u16; 32]) {

0 commit comments

Comments
 (0)