Set signext
or zeroext
for integer arguments on LoongArch64
This commit is contained in:
parent
6b65524620
commit
57bffe1d59
@ -1,6 +1,7 @@
|
|||||||
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
|
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
|
||||||
use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
|
use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
|
||||||
use crate::spec::HasTargetSpec;
|
use crate::spec::HasTargetSpec;
|
||||||
|
use crate::spec::abi::Abi as SpecAbi;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
enum RegPassKind {
|
enum RegPassKind {
|
||||||
@ -359,3 +360,30 @@ pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compute_rust_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, abi: SpecAbi)
|
||||||
|
where
|
||||||
|
Ty: TyAbiInterface<'a, C> + Copy,
|
||||||
|
C: HasDataLayout + HasTargetSpec,
|
||||||
|
{
|
||||||
|
if abi == SpecAbi::RustIntrinsic {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let grlen = cx.data_layout().pointer_size.bits();
|
||||||
|
|
||||||
|
for arg in fn_abi.args.iter_mut() {
|
||||||
|
if arg.is_ignore() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LLVM integers types do not differentiate between signed or unsigned integers.
|
||||||
|
// Some LoongArch instructions do not have a `.w` suffix version, they use all the
|
||||||
|
// GRLEN bits. By explicitly setting the `signext` or `zeroext` attribute
|
||||||
|
// according to signedness to avoid unnecessary integer extending instructions.
|
||||||
|
//
|
||||||
|
// This is similar to the RISC-V case, see
|
||||||
|
// https://github.com/rust-lang/rust/issues/114508 for details.
|
||||||
|
extend_integer_width(arg, grlen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -733,6 +733,7 @@ pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: SpecAbi)
|
|||||||
match &spec.arch[..] {
|
match &spec.arch[..] {
|
||||||
"x86" => x86::compute_rust_abi_info(cx, self, abi),
|
"x86" => x86::compute_rust_abi_info(cx, self, abi),
|
||||||
"riscv32" | "riscv64" => riscv::compute_rust_abi_info(cx, self, abi),
|
"riscv32" | "riscv64" => riscv::compute_rust_abi_info(cx, self, abi),
|
||||||
|
"loongarch64" => loongarch::compute_rust_abi_info(cx, self, abi),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
//@ assembly-output: emit-asm
|
//@ assembly-output: emit-asm
|
||||||
//@ revisions: riscv64 riscv64-zbb
|
//@ revisions: riscv64 riscv64-zbb loongarch64
|
||||||
//@ compile-flags: -C opt-level=3
|
//@ compile-flags: -C opt-level=3
|
||||||
//@ [riscv64] compile-flags: --target riscv64gc-unknown-linux-gnu
|
//@ [riscv64] compile-flags: --target riscv64gc-unknown-linux-gnu
|
||||||
//@ [riscv64] needs-llvm-components: riscv
|
//@ [riscv64] needs-llvm-components: riscv
|
||||||
//@ [riscv64-zbb] compile-flags: --target riscv64gc-unknown-linux-gnu
|
//@ [riscv64-zbb] compile-flags: --target riscv64gc-unknown-linux-gnu
|
||||||
//@ [riscv64-zbb] compile-flags: -C target-feature=+zbb
|
//@ [riscv64-zbb] compile-flags: -C target-feature=+zbb
|
||||||
//@ [riscv64-zbb] needs-llvm-components: riscv
|
//@ [riscv64-zbb] needs-llvm-components: riscv
|
||||||
|
//@ [loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu
|
||||||
|
//@ [loongarch64] needs-llvm-components: loongarch
|
||||||
|
|
||||||
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
|
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
@ -76,6 +78,11 @@ pub fn issue_114508_u32(a: u32, b: u32) -> u32 {
|
|||||||
|
|
||||||
// riscv64-zbb-NEXT: maxu a0, a0, a1
|
// riscv64-zbb-NEXT: maxu a0, a0, a1
|
||||||
|
|
||||||
|
// loongarch64-NEXT: sltu $a2, $a1, $a0
|
||||||
|
// loongarch64-NEXT: masknez $a1, $a1, $a2
|
||||||
|
// loongarch64-NEXT: maskeqz $a0, $a0, $a2
|
||||||
|
// loongarch64-NEXT: or $a0, $a0, $a1
|
||||||
|
|
||||||
// CHECK-NEXT: ret
|
// CHECK-NEXT: ret
|
||||||
max!(a, b)
|
max!(a, b)
|
||||||
}
|
}
|
||||||
@ -91,6 +98,11 @@ pub fn issue_114508_i32(a: i32, b: i32) -> i32 {
|
|||||||
|
|
||||||
// riscv64-zbb-NEXT: max a0, a0, a1
|
// riscv64-zbb-NEXT: max a0, a0, a1
|
||||||
|
|
||||||
|
// loongarch64-NEXT: slt $a2, $a1, $a0
|
||||||
|
// loongarch64-NEXT: masknez $a1, $a1, $a2
|
||||||
|
// loongarch64-NEXT: maskeqz $a0, $a0, $a2
|
||||||
|
// loongarch64-NEXT: or $a0, $a0, $a1
|
||||||
|
|
||||||
// CHECK-NEXT: ret
|
// CHECK-NEXT: ret
|
||||||
max!(a, b)
|
max!(a, b)
|
||||||
}
|
}
|
||||||
|
@ -1,93 +1,111 @@
|
|||||||
//@ compile-flags: -O -C no-prepopulate-passes
|
//@ compile-flags: -O -C no-prepopulate-passes
|
||||||
//@ revisions: riscv64
|
//@ revisions: riscv64 loongarch64
|
||||||
|
|
||||||
//@[riscv64] only-riscv64
|
//@[riscv64] only-riscv64
|
||||||
//@[riscv64] compile-flags: --target riscv64gc-unknown-linux-gnu
|
//@[riscv64] compile-flags: --target riscv64gc-unknown-linux-gnu
|
||||||
//@[riscv64] needs-llvm-components: riscv
|
//@[riscv64] needs-llvm-components: riscv
|
||||||
|
|
||||||
|
//@[loongarch64] only-loongarch64
|
||||||
|
//@[loongarch64] compile-flags: --target loongarch64-unknown-linux-gnu
|
||||||
|
//@[loongarch64] needs-llvm-components: loongarch
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i8 @arg_attr_u8(i8 noundef zeroext %x)
|
// riscv64: define noundef i8 @arg_attr_u8(i8 noundef zeroext %x)
|
||||||
|
// loongarch64: define noundef i8 @arg_attr_u8(i8 noundef zeroext %x)
|
||||||
pub fn arg_attr_u8(x: u8) -> u8 {
|
pub fn arg_attr_u8(x: u8) -> u8 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i16 @arg_attr_u16(i16 noundef zeroext %x)
|
// riscv64: define noundef i16 @arg_attr_u16(i16 noundef zeroext %x)
|
||||||
|
// loongarch64: define noundef i16 @arg_attr_u16(i16 noundef zeroext %x)
|
||||||
pub fn arg_attr_u16(x: u16) -> u16 {
|
pub fn arg_attr_u16(x: u16) -> u16 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i32 @arg_attr_u32(i32 noundef signext %x)
|
// riscv64: define noundef i32 @arg_attr_u32(i32 noundef signext %x)
|
||||||
|
// loongarch64: define noundef i32 @arg_attr_u32(i32 noundef signext %x)
|
||||||
pub fn arg_attr_u32(x: u32) -> u32 {
|
pub fn arg_attr_u32(x: u32) -> u32 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i64 @arg_attr_u64(i64 noundef %x)
|
// riscv64: define noundef i64 @arg_attr_u64(i64 noundef %x)
|
||||||
|
// loongarch64: define noundef i64 @arg_attr_u64(i64 noundef %x)
|
||||||
pub fn arg_attr_u64(x: u64) -> u64 {
|
pub fn arg_attr_u64(x: u64) -> u64 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i128 @arg_attr_u128(i128 noundef %x)
|
// riscv64: define noundef i128 @arg_attr_u128(i128 noundef %x)
|
||||||
|
// loongarch64: define noundef i128 @arg_attr_u128(i128 noundef %x)
|
||||||
pub fn arg_attr_u128(x: u128) -> u128 {
|
pub fn arg_attr_u128(x: u128) -> u128 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i8 @arg_attr_i8(i8 noundef signext %x)
|
// riscv64: define noundef i8 @arg_attr_i8(i8 noundef signext %x)
|
||||||
|
// loongarch64: define noundef i8 @arg_attr_i8(i8 noundef signext %x)
|
||||||
pub fn arg_attr_i8(x: i8) -> i8 {
|
pub fn arg_attr_i8(x: i8) -> i8 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i16 @arg_attr_i16(i16 noundef signext %x)
|
// riscv64: define noundef i16 @arg_attr_i16(i16 noundef signext %x)
|
||||||
|
// loongarch64: define noundef i16 @arg_attr_i16(i16 noundef signext %x)
|
||||||
pub fn arg_attr_i16(x: i16) -> i16 {
|
pub fn arg_attr_i16(x: i16) -> i16 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i32 @arg_attr_i32(i32 noundef signext %x)
|
// riscv64: define noundef i32 @arg_attr_i32(i32 noundef signext %x)
|
||||||
|
// loongarch64: define noundef i32 @arg_attr_i32(i32 noundef signext %x)
|
||||||
pub fn arg_attr_i32(x: i32) -> i32 {
|
pub fn arg_attr_i32(x: i32) -> i32 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i64 @arg_attr_i64(i64 noundef %x)
|
// riscv64: define noundef i64 @arg_attr_i64(i64 noundef %x)
|
||||||
|
// loongarch64: define noundef i64 @arg_attr_i64(i64 noundef %x)
|
||||||
pub fn arg_attr_i64(x: i64) -> i64 {
|
pub fn arg_attr_i64(x: i64) -> i64 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef i128 @arg_attr_i128(i128 noundef %x)
|
// riscv64: define noundef i128 @arg_attr_i128(i128 noundef %x)
|
||||||
|
// loongarch64: define noundef i128 @arg_attr_i128(i128 noundef %x)
|
||||||
pub fn arg_attr_i128(x: i128) -> i128 {
|
pub fn arg_attr_i128(x: i128) -> i128 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef zeroext i1 @arg_attr_bool(i1 noundef zeroext %x)
|
// riscv64: define noundef zeroext i1 @arg_attr_bool(i1 noundef zeroext %x)
|
||||||
|
// loongarch64: define noundef zeroext i1 @arg_attr_bool(i1 noundef zeroext %x)
|
||||||
pub fn arg_attr_bool(x: bool) -> bool {
|
pub fn arg_attr_bool(x: bool) -> bool {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// ignore-tidy-linelength
|
// ignore-tidy-linelength
|
||||||
// riscv64: define noundef{{( range\(i32 0, 1114112\))?}} i32 @arg_attr_char(i32 noundef signext{{( range\(i32 0, 1114112\))?}} %x)
|
// riscv64: define noundef{{( range\(i32 0, 1114112\))?}} i32 @arg_attr_char(i32 noundef signext{{( range\(i32 0, 1114112\))?}} %x)
|
||||||
|
// loongarch64: define noundef{{( range\(i32 0, 1114112\))?}} i32 @arg_attr_char(i32 noundef signext{{( range\(i32 0, 1114112\))?}} %x)
|
||||||
pub fn arg_attr_char(x: char) -> char {
|
pub fn arg_attr_char(x: char) -> char {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef float @arg_attr_f32(float noundef %x)
|
// riscv64: define noundef float @arg_attr_f32(float noundef %x)
|
||||||
|
// loongarch64: define noundef float @arg_attr_f32(float noundef %x)
|
||||||
pub fn arg_attr_f32(x: f32) -> f32 {
|
pub fn arg_attr_f32(x: f32) -> f32 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
// riscv64: define noundef double @arg_attr_f64(double noundef %x)
|
// riscv64: define noundef double @arg_attr_f64(double noundef %x)
|
||||||
|
// loongarch64: define noundef double @arg_attr_f64(double noundef %x)
|
||||||
pub fn arg_attr_f64(x: f64) -> f64 {
|
pub fn arg_attr_f64(x: f64) -> f64 {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {
|
|||||||
// CHECK: Function Attrs: {{.*}}
|
// CHECK: Function Attrs: {{.*}}
|
||||||
// CHECK-LABEL: define{{.*}}foo{{.*}}!type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
|
// CHECK-LABEL: define{{.*}}foo{{.*}}!type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
|
||||||
// CHECK: start:
|
// CHECK: start:
|
||||||
// CHECK-NEXT: {{%.+}} = call i32 %f(i32 %arg)
|
// CHECK-NEXT: {{%.+}} = call i32 %f(i32{{.*}} %arg)
|
||||||
// CHECK-NEXT: ret i32 {{%.+}}
|
// CHECK-NEXT: ret i32 {{%.+}}
|
||||||
f(arg)
|
f(arg)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {
|
|||||||
// CHECK: [[TT:%.+]] = call i1 @llvm.type.test(ptr {{%f|%0}}, metadata !"{{[[:print:]]+}}")
|
// CHECK: [[TT:%.+]] = call i1 @llvm.type.test(ptr {{%f|%0}}, metadata !"{{[[:print:]]+}}")
|
||||||
// CHECK-NEXT: br i1 [[TT]], label %type_test.pass, label %type_test.fail
|
// CHECK-NEXT: br i1 [[TT]], label %type_test.pass, label %type_test.fail
|
||||||
// CHECK: type_test.pass:
|
// CHECK: type_test.pass:
|
||||||
// CHECK-NEXT: {{%.+}} = call i32 %f(i32 %arg)
|
// CHECK-NEXT: {{%.+}} = call i32 %f(i32{{.*}} %arg)
|
||||||
// CHECK: type_test.fail:
|
// CHECK: type_test.fail:
|
||||||
// CHECK-NEXT: call void @llvm.trap()
|
// CHECK-NEXT: call void @llvm.trap()
|
||||||
// CHECK-NEXT: unreachable
|
// CHECK-NEXT: unreachable
|
||||||
|
Loading…
Reference in New Issue
Block a user