Skip to content

Commit 5a76a60

Browse files
committed
add fast-path for wide pointers
1 parent 635bacf commit 5a76a60

File tree

1 file changed

+13
-4
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+13
-4
lines changed

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use either::{Either, Left, Right};
66
use rustc_abi::{BackendRepr, HasDataLayout, Size};
77
use rustc_data_structures::assert_matches;
8-
use rustc_middle::ty::Ty;
98
use rustc_middle::ty::layout::TyAndLayout;
9+
use rustc_middle::ty::{self, Ty};
1010
use rustc_middle::{bug, mir, span_bug};
1111
use tracing::field::Empty;
1212
use tracing::{instrument, trace};
@@ -884,18 +884,27 @@ where
884884
dest.layout().ty,
885885
);
886886
}
887-
// If the source has padding, we want to always do the mem-to-mem copy to ensure consistent
887+
// If the source has padding, we want to always do a mem-to-mem copy to ensure consistent
888888
// padding in the target independent of layout choices.
889889
let src_has_padding = match src.layout().backend_repr {
890890
BackendRepr::Scalar(_) => false,
891+
BackendRepr::ScalarPair(left, right)
892+
if matches!(src.layout().ty.kind(), ty::Ref(..) | ty::RawPtr(..)) =>
893+
{
894+
// Wide pointers never have padding, so we can avoid calling `size()`.
895+
debug_assert_eq!(left.size(self) + right.size(self), src.layout().size);
896+
false
897+
}
891898
BackendRepr::ScalarPair(left, right) => {
892899
let left_size = left.size(self);
893900
let right_size = right.size(self);
894901
// We have padding if the sizes don't add up to the total.
895902
left_size + right_size != src.layout().size
896903
}
897-
// Everything else can only exist in memory anyway.
898-
_ => true,
904+
// Everything else can only exist in memory anyway, so it doesn't matter.
905+
BackendRepr::SimdVector { .. }
906+
| BackendRepr::ScalableVector { .. }
907+
| BackendRepr::Memory { .. } => true,
899908
};
900909

901910
let src_val = if src_has_padding {

0 commit comments

Comments
 (0)