Auto merge of #123185 - scottmcm:more-typed-copy, r=compiler-errors
Remove my `scalar_copy_backend_type` optimization attempt I added this back in https://github.com/rust-lang/rust/pull/111999 , but I no longer think it's a good idea - It had to get scaled back to only power-of-two things to not break a bunch of targets - LLVM seems to be getting better at memcpy removal anyway - Introducing vector instructions has seemed to sometimes (https://github.com/rust-lang/rust/pull/115515#issuecomment-1750069529) make autovectorization worse So this removes it from the codegen crates entirely, and instead just tries to use <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/traits/builder/trait.BuilderMethods.html#method.typed_place_copy> instead of direct `memcpy` so things will still use load/store when a type isn't `OperandValue::Ref`.
This commit is contained in:
commit
c2239bca5b
11 changed files with 91 additions and 165 deletions
|
@ -281,9 +281,6 @@ impl<'ll, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
fn reg_backend_type(&self, ty: &Reg) -> &'ll Type {
|
||||
ty.llvm_type(self)
|
||||
}
|
||||
fn scalar_copy_backend_type(&self, layout: TyAndLayout<'tcx>) -> Option<Self::Type> {
|
||||
layout.scalar_copy_llvm_type(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
|
|
|
@ -5,7 +5,6 @@ use rustc_middle::bug;
|
|||
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||
use rustc_target::abi::HasDataLayout;
|
||||
use rustc_target::abi::{Abi, Align, FieldsShape};
|
||||
use rustc_target::abi::{Int, Pointer, F128, F16, F32, F64};
|
||||
use rustc_target::abi::{Scalar, Size, Variants};
|
||||
|
@ -166,7 +165,6 @@ pub trait LayoutLlvmExt<'tcx> {
|
|||
index: usize,
|
||||
immediate: bool,
|
||||
) -> &'a Type;
|
||||
fn scalar_copy_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> Option<&'a Type>;
|
||||
}
|
||||
|
||||
impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
||||
|
@ -308,44 +306,4 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
|||
|
||||
self.scalar_llvm_type_at(cx, scalar)
|
||||
}
|
||||
|
||||
fn scalar_copy_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> Option<&'a Type> {
|
||||
debug_assert!(self.is_sized());
|
||||
|
||||
// FIXME: this is a fairly arbitrary choice, but 128 bits on WASM
|
||||
// (matching the 128-bit SIMD types proposal) and 256 bits on x64
|
||||
// (like AVX2 registers) seems at least like a tolerable starting point.
|
||||
let threshold = cx.data_layout().pointer_size * 4;
|
||||
if self.layout.size() > threshold {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Vectors, even for non-power-of-two sizes, have the same layout as
|
||||
// arrays but don't count as aggregate types
|
||||
// While LLVM theoretically supports non-power-of-two sizes, and they
|
||||
// often work fine, sometimes x86-isel deals with them horribly
|
||||
// (see #115212) so for now only use power-of-two ones.
|
||||
if let FieldsShape::Array { count, .. } = self.layout.fields()
|
||||
&& count.is_power_of_two()
|
||||
&& let element = self.field(cx, 0)
|
||||
&& element.ty.is_integral()
|
||||
{
|
||||
// `cx.type_ix(bits)` is tempting here, but while that works great
|
||||
// for things that *stay* as memory-to-memory copies, it also ends
|
||||
// up suppressing vectorization as it introduces shifts when it
|
||||
// extracts all the individual values.
|
||||
|
||||
let ety = element.llvm_type(cx);
|
||||
if *count == 1 {
|
||||
// Emitting `<1 x T>` would be silly; just use the scalar.
|
||||
return Some(ety);
|
||||
} else {
|
||||
return Some(cx.type_vector(ety, *count));
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: The above only handled integer arrays; surely more things
|
||||
// would also be possible. Be careful about provenance, though!
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue