Propagate ScalarPair for any type.
This commit is contained in:
parent
895e2159f8
commit
ccfa9af29d
5 changed files with 29 additions and 41 deletions
|
@ -581,40 +581,22 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
Some(self.operand_from_scalar(scalar, value.layout.ty))
|
Some(self.operand_from_scalar(scalar, value.layout.ty))
|
||||||
}
|
}
|
||||||
Immediate::ScalarPair(..) => {
|
Immediate::ScalarPair(..) => {
|
||||||
// Found a value represented as a pair. For now only do const-prop if the type
|
let alloc = self
|
||||||
// of `rvalue` is also a tuple with two scalars.
|
.ecx
|
||||||
// FIXME: enable the general case stated above ^.
|
|
||||||
let ty = value.layout.ty;
|
|
||||||
// Only do it for tuples
|
|
||||||
let ty::Tuple(types) = ty.kind() else { return None };
|
|
||||||
// Only do it if tuple is also a pair with two scalars
|
|
||||||
if let [ty1, ty2] = types[..] {
|
|
||||||
let ty_is_scalar = |ty| {
|
|
||||||
self.ecx.layout_of(ty).ok().map(|layout| layout.abi.is_scalar())
|
|
||||||
== Some(true)
|
|
||||||
};
|
|
||||||
let alloc = if ty_is_scalar(ty1) && ty_is_scalar(ty2) {
|
|
||||||
self.ecx
|
|
||||||
.intern_with_temp_alloc(value.layout, |ecx, dest| {
|
.intern_with_temp_alloc(value.layout, |ecx, dest| {
|
||||||
ecx.write_immediate(*imm, dest)
|
ecx.write_immediate(*imm, dest)
|
||||||
})
|
})
|
||||||
.unwrap()
|
.ok()?;
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Assign entire constant in a single statement.
|
let literal = ConstantKind::Val(
|
||||||
// We can't use aggregates, as we run after the aggregate-lowering `MirPhase`.
|
ConstValue::ByRef { alloc, offset: Size::ZERO },
|
||||||
let const_val = ConstValue::ByRef { alloc, offset: Size::ZERO };
|
value.layout.ty,
|
||||||
let literal = ConstantKind::Val(const_val, ty);
|
);
|
||||||
Some(Operand::Constant(Box::new(Constant {
|
Some(Operand::Constant(Box::new(Constant {
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
literal,
|
literal,
|
||||||
})))
|
})))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Scalars or scalar pairs that contain undef values are assumed to not have
|
// Scalars or scalar pairs that contain undef values are assumed to not have
|
||||||
// successfully evaluated and are thus not propagated.
|
// successfully evaluated and are thus not propagated.
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_2);
|
StorageLive(_2);
|
||||||
_2 = (const (), const 0_u8, const 0_u8);
|
- _2 = (const (), const 0_u8, const 0_u8);
|
||||||
_1 = encode(move _2) -> [return: bb1, unwind unreachable];
|
- _1 = encode(move _2) -> [return: bb1, unwind unreachable];
|
||||||
|
+ _2 = const ((), 0_u8, 0_u8);
|
||||||
|
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
StorageLive(_2);
|
StorageLive(_2);
|
||||||
_2 = (const (), const 0_u8, const 0_u8);
|
- _2 = (const (), const 0_u8, const 0_u8);
|
||||||
_1 = encode(move _2) -> [return: bb1, unwind continue];
|
- _1 = encode(move _2) -> [return: bb1, unwind continue];
|
||||||
|
+ _2 = const ((), 0_u8, 0_u8);
|
||||||
|
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
- _3 = (const 1_u8, const 2_u8);
|
- _3 = (const 1_u8, const 2_u8);
|
||||||
- _2 = (move _3,);
|
- _2 = (move _3,);
|
||||||
+ _3 = const (1_u8, 2_u8);
|
+ _3 = const (1_u8, 2_u8);
|
||||||
+ _2 = (const (1_u8, 2_u8),);
|
+ _2 = const ((1_u8, 2_u8),);
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
_1 = test(move _2) -> [return: bb1, unwind unreachable];
|
- _1 = test(move _2) -> [return: bb1, unwind unreachable];
|
||||||
|
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
- _3 = (const 1_u8, const 2_u8);
|
- _3 = (const 1_u8, const 2_u8);
|
||||||
- _2 = (move _3,);
|
- _2 = (move _3,);
|
||||||
+ _3 = const (1_u8, 2_u8);
|
+ _3 = const (1_u8, 2_u8);
|
||||||
+ _2 = (const (1_u8, 2_u8),);
|
+ _2 = const ((1_u8, 2_u8),);
|
||||||
StorageDead(_3);
|
StorageDead(_3);
|
||||||
_1 = test(move _2) -> [return: bb1, unwind continue];
|
- _1 = test(move _2) -> [return: bb1, unwind continue];
|
||||||
|
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue];
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue