Skip to content

Commit 2a79a4c

Browse files
authored
Unrolled build for #150420
Rollup merge of #150420 - h3fang:sve-debuginfo-fix, r=workingjubilee Do not spill operand debuginfo to stack for AArch64 SVE predicates `<vscale x N x i1>` where `N != 16` This pull request tries to fix #150419. The debuginfo for AArch64 SVE predicates `<vscale x N x i1>` where `N != 16` should be ignored by this [commit](89eea57). https://github.com/rust-lang/rust/blob/89eea57594e3e1d8e618dd530ea1c8e7c9b4c7a4/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs#L438-L452 But in line 446, the `marker_type.kind()` is `ty::Bool` instead of `ty::Slice`, so the code doesn't work as intended. This pull request uses the [`Ty::scalable_vector_element_count_and_type`](https://github.com/rust-lang/rust/blob/main/compiler/rustc_middle/src/ty/sty.rs#L1272) method to fix the condition checks for `<vscale x N x i1>` where `N != 16` and add a compiletest for this case.
2 parents 0e89999 + 4c485a4 commit 2a79a4c

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::hash_map::Entry;
22
use std::marker::PhantomData;
33
use std::ops::Range;
44

5-
use rustc_abi::{BackendRepr, FieldIdx, FieldsShape, ScalableElt, Size, VariantIdx};
5+
use rustc_abi::{BackendRepr, FieldIdx, FieldsShape, Size, VariantIdx};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_index::IndexVec;
88
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -431,22 +431,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
431431
// Internally, with an intrinsic operating on a `svint32_t`/`<vscale x 4 x i32>`
432432
// (for example), the intrinsic takes the `svbool_t`/`<vscale x 16 x i1>` predicate
433433
// and casts it to a `svbool4_t`/`<vscale x 4 x i1>`. Therefore, it's important that
434-
// the `<vscale x 4 x i32>` never spills because that'll cause errors during
434+
// the `<vscale x 4 x i1>` never spills because that'll cause errors during
435435
// instruction selection. Spilling to the stack to create debuginfo for these
436-
// intermediate values must be avoided and won't degrade the debugging experience
437-
// anyway.
436+
// intermediate values must be avoided and doing so won't affect the
437+
// debugging experience anyway.
438438
if operand.layout.ty.is_scalable_vector()
439439
&& bx.sess().target.arch == rustc_target::spec::Arch::AArch64
440-
&& let ty::Adt(adt, args) = &operand.layout.ty.kind()
441-
&& let Some(marker_type_field) =
442-
adt.non_enum_variant().fields.get(FieldIdx::from_u32(0))
443440
{
444-
let marker_type = marker_type_field.ty(bx.tcx(), args);
441+
let (count, element_ty) =
442+
operand.layout.ty.scalable_vector_element_count_and_type(bx.tcx());
445443
// i.e. `<vscale x N x i1>` when `N != 16`
446-
if let ty::Slice(element_ty) = marker_type.kind()
447-
&& element_ty.is_bool()
448-
&& adt.repr().scalable != Some(ScalableElt::ElementCount(16))
449-
{
444+
if element_ty.is_bool() && count != 16 {
450445
return;
451446
}
452447
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Compiletest for rust-lang/rust#150419: Do not spill operands to the stack when
2+
// creating debuginfo for AArch64 SVE predicates `<vscale x N x i1>` where `N != 16`
3+
//@ edition: 2021
4+
//@ only-aarch64
5+
//@ build-pass
6+
//@ compile-flags: -C debuginfo=2 -C target-feature=+sve
7+
8+
#![crate_type = "lib"]
9+
#![allow(internal_features)]
10+
#![feature(rustc_attrs, link_llvm_intrinsics)]
11+
12+
#[rustc_scalable_vector(16)]
13+
#[allow(non_camel_case_types)]
14+
#[repr(transparent)]
15+
pub struct svbool_t(bool);
16+
17+
#[rustc_scalable_vector(4)]
18+
#[allow(non_camel_case_types)]
19+
#[repr(transparent)]
20+
pub struct svbool4_t(bool);
21+
22+
impl std::convert::Into<svbool_t> for svbool4_t {
23+
#[inline(always)]
24+
fn into(self) -> svbool_t {
25+
unsafe extern "C" {
26+
#[link_name = "llvm.aarch64.sve.convert.to.svbool.nxv4i1"]
27+
fn convert_to_svbool(b: svbool4_t) -> svbool_t;
28+
}
29+
unsafe { convert_to_svbool(self) }
30+
}
31+
}
32+
33+
pub fn svwhilelt_b32_u64(op1: u64, op2: u64) -> svbool_t {
34+
unsafe extern "C" {
35+
#[link_name = "llvm.aarch64.sve.whilelo.nxv4i1.u64"]
36+
fn _svwhilelt_b32_u64(op1: u64, op2: u64) -> svbool4_t;
37+
}
38+
unsafe { _svwhilelt_b32_u64(op1, op2) }.into()
39+
}

0 commit comments

Comments
 (0)