Auto merge of #91569 - erikdesjardins:vt-align, r=nikic
Attach range metadata to alignment loads from vtables ...because alignment is always nonzero[0]. This helps eliminate redundant runtime alignment checks, when a DST is a field of a struct whose remaining fields have alignment 1. Fixes #91438. --- [0]: The [reference](https://doc.rust-lang.org/reference/type-layout.html) says that alignment must be at least 1. And in practice, the alignment field for all vtables is generated here:772d51f887/compiler/rustc_middle/src/ty/vtable.rs (L68-L90)
and is nonzero because [`Align::bytes()`](772d51f887/compiler/rustc_target/src/abi/mod.rs (L547-L549)
) is always nonzero.
This commit is contained in:
commit
4a7fb971c9
2 changed files with 56 additions and 7 deletions
|
@ -6,6 +6,7 @@ use crate::common::IntPredicate;
|
|||
use crate::meth;
|
||||
use crate::traits::*;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_target::abi::WrappingRange;
|
||||
|
||||
pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
|
@ -21,14 +22,17 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
}
|
||||
match t.kind() {
|
||||
ty::Dynamic(..) => {
|
||||
// load size/align from vtable
|
||||
// Load size/align from vtable.
|
||||
let vtable = info.unwrap();
|
||||
(
|
||||
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_SIZE)
|
||||
.get_usize(bx, vtable),
|
||||
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_ALIGN)
|
||||
.get_usize(bx, vtable),
|
||||
)
|
||||
let size = meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_SIZE)
|
||||
.get_usize(bx, vtable);
|
||||
let align = meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_ALIGN)
|
||||
.get_usize(bx, vtable);
|
||||
|
||||
// Alignment is always nonzero.
|
||||
bx.range_metadata(align, WrappingRange { start: 1, end: !0 });
|
||||
|
||||
(size, align)
|
||||
}
|
||||
ty::Slice(_) | ty::Str => {
|
||||
let unit = layout.field(bx, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue