about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorErik Desjardins <erikdesjardins@users.noreply.github.com>2021-12-05 15:55:50 -0500
committerErik Desjardins <erikdesjardins@users.noreply.github.com>2021-12-05 16:07:27 -0500
commit2ff5a3e38b59dc8dc443c7459d2825130ffed4bc (patch)
treec1dcbe6f4c6c35292571a25abfee182a5f3b4217 /compiler/rustc_codegen_ssa/src
parent772d51f887fa407216860bf8ecf3f1a32fb795b4 (diff)
downloadrust-2ff5a3e38b59dc8dc443c7459d2825130ffed4bc.tar.gz
rust-2ff5a3e38b59dc8dc443c7459d2825130ffed4bc.zip
Attach range metadata to alignment loads from vtables
...because alignment is always nonzero.

This helps eliminate redundant runtime alignment checks, when a DST
is a field of a struct whose remaining fields have alignment 1.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/glue.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/compiler/rustc_codegen_ssa/src/glue.rs b/compiler/rustc_codegen_ssa/src/glue.rs
index cf217b52c86..2c4e6bbe9a5 100644
--- a/compiler/rustc_codegen_ssa/src/glue.rs
+++ b/compiler/rustc_codegen_ssa/src/glue.rs
@@ -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);