Skip to content

Commit 33b71f4

Browse files
committed
Auto merge of #159353 - workingjubilee:perf-test-for-x86-argext-rust-abi, r=<try>
Perf test extending int args in x86 Rust ABI
2 parents 2118366 + fec6880 commit 33b71f4

17 files changed

Lines changed: 109 additions & 39 deletions

‎compiler/rustc_target/src/callconv/x86.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ where
205205
Ty: TyAbiInterface<'a, C> + Copy,
206206
C: HasDataLayout + HasTargetSpec,
207207
{
208+
// Perform some sign/arg extension on integers to mirror our C ABI
209+
for arg in fn_abi.args.iter_mut() {
210+
arg.extend_integer_width_to(32);
211+
}
212+
fn_abi.ret.extend_integer_width_to(32);
213+
208214
// Avoid returning floats in x87 registers on x86 as loading and storing from x87
209215
// registers will quiet signalling NaNs. Also avoid using SSE registers since they
210216
// are not always available (depending on target features).

‎compiler/rustc_ty_utils/src/abi.rs‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rustc_middle::ty::layout::{
1313
use rustc_middle::ty::{self, InstanceKind, ShimKind, Ty, TyCtxt, Unnormalized};
1414
use rustc_span::DUMMY_SP;
1515
use rustc_span::def_id::DefId;
16-
use rustc_target::callconv::{
17-
AbiMap, ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, FnAbi, PassMode,
18-
};
16+
use rustc_target::callconv::{AbiMap, ArgAbi, ArgAttribute, ArgAttributes, FnAbi, PassMode};
1917
use tracing::debug;
2018

2119
pub(crate) fn provide(providers: &mut Providers) {
@@ -331,13 +329,6 @@ fn arg_attrs_for_rust_scalar<'tcx>(
331329
) -> ArgAttributes {
332330
let mut attrs = ArgAttributes::new();
333331

334-
// Booleans are always a noundef i1 that needs to be zero-extended.
335-
if scalar.is_bool() {
336-
attrs.ext(ArgExtension::Zext);
337-
attrs.set(ArgAttribute::NoUndef);
338-
return attrs;
339-
}
340-
341332
if !scalar.is_uninit_valid() {
342333
attrs.set(ArgAttribute::NoUndef);
343334
}

‎tests/auxiliary/rust_test_helpers.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Helper functions used only in tests
22

33
#include <stdint.h>
4+
#include <stdbool.h>
45
#include <stdlib.h>
56
#include <assert.h>
67
#include <stdarg.h>
@@ -455,3 +456,14 @@ uint16_t issue_97463_leak_uninit_data(uint32_t a, uint32_t b, uint32_t c) {
455456

456457
return data->b; /* leak data */
457458
}
459+
460+
typedef struct Bools {
461+
bool a;
462+
bool b;
463+
bool c;
464+
bool d;
465+
} Bools;
466+
467+
bool bools_get_first_bool(struct Bools bools) {
468+
return bools.a;
469+
}

‎tests/codegen-llvm/enum/enum-aggregate.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ptr::NonNull;
1010

1111
#[no_mangle]
1212
fn make_some_bool(x: bool) -> Option<bool> {
13-
// CHECK-LABEL: i8 @make_some_bool(i1 zeroext %x)
13+
// CHECK-LABEL: i8 @make_some_bool(i1{{( zeroext)?}} %x)
1414
// CHECK-NEXT: start:
1515
// CHECK-NEXT: %[[WIDER:.+]] = zext i1 %x to i8
1616
// CHECK-NEXT: ret i8 %[[WIDER]]

‎tests/codegen-llvm/function-arguments-noopt.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct S {
1010
_field: [i32; 8],
1111
}
1212

13-
// CHECK: zeroext i1 @boolean(i1 zeroext %x)
13+
// CHECK: {{(zeroext|signext)?}} i1 @boolean(i1{{( zeroext)?}} %x)
1414
#[no_mangle]
1515
pub fn boolean(x: bool) -> bool {
1616
x
@@ -19,7 +19,7 @@ pub fn boolean(x: bool) -> bool {
1919
// CHECK-LABEL: @boolean_call
2020
#[no_mangle]
2121
pub fn boolean_call(x: bool, f: fn(bool) -> bool) -> bool {
22-
// CHECK: call zeroext i1 %f(i1 zeroext %x)
22+
// CHECK: call{{( zeroext)?}} i1 %f(i1{{( zeroext| signext)?}} %x)
2323
f(x)
2424
}
2525

@@ -55,7 +55,7 @@ pub fn struct_call(x: S, f: fn(S) -> S) -> S {
5555
f(x)
5656
}
5757

58-
// CHECK: { i1, i8 } @enum_(i1 zeroext %x.0, i8 %x.1)
58+
// CHECK: { i1, i8 } @enum_(i1{{( zeroext)?}} %x.0, i8 %x.1)
5959
#[no_mangle]
6060
pub fn enum_(x: Option<u8>) -> Option<u8> {
6161
x
@@ -64,6 +64,6 @@ pub fn enum_(x: Option<u8>) -> Option<u8> {
6464
// CHECK-LABEL: @enum_call
6565
#[no_mangle]
6666
pub fn enum_call(x: Option<u8>, f: fn(Option<u8>) -> Option<u8>) -> Option<u8> {
67-
// CHECK: call { i1, i8 } %f(i1 zeroext %x.0, i8 %x.1)
67+
// CHECK: call { i1, i8 } %f(i1{{( zeroext)?}} %x.0, i8 %x.1)
6868
f(x)
6969
}

‎tests/codegen-llvm/function-arguments.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub enum MyBool {
2626
False,
2727
}
2828

29-
// CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x)
29+
// CHECK: noundef{{( zeroext)?}} i1 @boolean(i1 noundef{{( zeroext)?}} %x)
3030
#[no_mangle]
3131
pub fn boolean(x: bool) -> bool {
3232
x
@@ -38,7 +38,7 @@ pub fn maybeuninit_boolean(x: MaybeUninit<bool>) -> MaybeUninit<bool> {
3838
x
3939
}
4040

41-
// CHECK: noundef zeroext i1 @enum_bool(i1 noundef zeroext %x)
41+
// CHECK: noundef{{( zeroext)?}} i1 @enum_bool(i1 noundef{{( zeroext)?}} %x)
4242
#[no_mangle]
4343
pub fn enum_bool(x: MyBool) -> MyBool {
4444
x
@@ -271,7 +271,7 @@ pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
271271
x
272272
}
273273

274-
// CHECK: { i1, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1)
274+
// CHECK: { i1, i8 } @enum_id_2(i1 noundef{{( zeroext)?}} %x.0, i8 %x.1)
275275
#[no_mangle]
276276
pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
277277
x

‎tests/codegen-llvm/mir-aggregate-no-alloca.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ pub fn make_2_tuple(x: u32) -> (u32, u32) {
5151
pair
5252
}
5353

54-
// CHECK-LABEL: i8 @make_cell_of_bool(i1 noundef zeroext %b)
54+
// CHECK-LABEL: i8 @make_cell_of_bool(i1 noundef{{( zeroext)?}} %b)
5555
#[no_mangle]
5656
pub fn make_cell_of_bool(b: bool) -> std::cell::Cell<bool> {
5757
// CHECK: %[[BYTE:.+]] = zext i1 %b to i8
5858
// CHECK: ret i8 %[[BYTE]]
5959
std::cell::Cell::new(b)
6060
}
6161

62-
// CHECK-LABEL: { i8, i16 } @make_cell_of_bool_and_short(i1 noundef zeroext %b, i16{{.*}} %s)
62+
// CHECK-LABEL: { i8, i16 } @make_cell_of_bool_and_short(i1 noundef{{( zeroext)?}} %b, i16{{.*}} %s)
6363
#[no_mangle]
6464
pub fn make_cell_of_bool_and_short(b: bool, s: u16) -> std::cell::Cell<(bool, u16)> {
6565
// CHECK-NOT: alloca
@@ -70,7 +70,7 @@ pub fn make_cell_of_bool_and_short(b: bool, s: u16) -> std::cell::Cell<(bool, u1
7070
std::cell::Cell::new((b, s))
7171
}
7272

73-
// CHECK-LABEL: { i1, i1 } @make_tuple_of_bools(i1 noundef zeroext %a, i1 noundef zeroext %b)
73+
// CHECK-LABEL: { i1, i1 } @make_tuple_of_bools(i1 noundef{{( zeroext)?}} %a, i1 noundef{{( zeroext| signext)?}} %b)
7474
#[no_mangle]
7575
pub fn make_tuple_of_bools(a: bool, b: bool) -> (bool, bool) {
7676
// CHECK-NOT: alloca

‎tests/codegen-llvm/rust-abi-arch-specific-adjustment.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ pub fn arg_attr_i128(x: i128) -> i128 {
8686
}
8787

8888
#[no_mangle]
89-
// riscv64: define noundef zeroext i1 @arg_attr_bool(i1 noundef zeroext %x)
90-
// loongarch64: define noundef zeroext i1 @arg_attr_bool(i1 noundef zeroext %x)
89+
// riscv64: define noundef i1 @arg_attr_bool(i1 noundef zeroext %x)
90+
// loongarch64: define noundef i1 @arg_attr_bool(i1 noundef zeroext %x)
9191
pub fn arg_attr_bool(x: bool) -> bool {
9292
x
9393
}

‎tests/codegen-llvm/scalar-pair-bool.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
#![crate_type = "lib"]
44

5-
// CHECK: define{{.*}}{ i1, i1 } @pair_bool_bool(i1 noundef zeroext %pair.0, i1 noundef zeroext %pair.1)
5+
// CHECK: define{{.*}}{ i1, i1 } @pair_bool_bool(i1 noundef{{( zeroext)?}} %pair.0, i1 noundef{{( zeroext| signext)?}} %pair.1)
66
#[no_mangle]
77
pub fn pair_bool_bool(pair: (bool, bool)) -> (bool, bool) {
88
pair
99
}
1010

11-
// CHECK: define{{.*}}{ i1, i32 } @pair_bool_i32(i1 noundef zeroext %pair.0, i32 noundef %pair.1)
11+
// CHECK: define{{.*}}{ i1, i32 } @pair_bool_i32(i1 noundef{{( zeroext)?}} %pair.0, i32 noundef %pair.1)
1212
#[no_mangle]
1313
pub fn pair_bool_i32(pair: (bool, i32)) -> (bool, i32) {
1414
pair
1515
}
1616

17-
// CHECK: define{{.*}}{ i32, i1 } @pair_i32_bool(i32 noundef %pair.0, i1 noundef zeroext %pair.1)
17+
// CHECK: define{{.*}}{ i32, i1 } @pair_i32_bool(i32 noundef %pair.0, i1 noundef{{( zeroext)?}} %pair.1)
1818
#[no_mangle]
1919
pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
2020
pair
2121
}
2222

23-
// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
23+
// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef{{( zeroext)?}} %_1.0, i1 noundef{{( zeroext| signext)?}} %_1.1)
2424
#[no_mangle]
2525
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
2626
// Make sure it can operate directly on the unpacked args
@@ -30,7 +30,7 @@ pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
3030
(a && b, a || b)
3131
}
3232

33-
// CHECK: define{{.*}}void @pair_branches(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
33+
// CHECK: define{{.*}}void @pair_branches(i1 noundef{{( zeroext)?}} %_1.0, i1 noundef{{( zeroext| signext)?}} %_1.1)
3434
#[no_mangle]
3535
pub fn pair_branches((a, b): (bool, bool)) {
3636
// Make sure it can branch directly on the unpacked bool args

‎tests/codegen-llvm/some-abis-do-extend-params-to-32-bits.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ use minicore::*;
3333
//
3434
// ZERO/SIGN-EXTENDING TO 32 BITS NON-EXTENDING
3535
// ============================== =======================
36+
// x86_64: void @c_arg_bool(i1 zeroext %_a)
37+
// i686: void @c_arg_bool(i1 zeroext %_a)
38+
// aarch64-apple: void @c_arg_bool(i1 zeroext %_a)
39+
// aarch64-windows: void @c_arg_bool(i1 %_a)
40+
// aarch64-linux: void @c_arg_bool(i1 %_a)
41+
// arm: void @c_arg_bool(i1 zeroext %_a)
42+
// riscv: void @c_arg_bool(i1 zeroext %_a)
43+
#[no_mangle]
44+
pub extern "C" fn c_arg_bool(_a: bool) {}
45+
3646
// x86_64: void @c_arg_u8(i8 zeroext %_a)
3747
// i686: void @c_arg_u8(i8 zeroext %_a)
3848
// aarch64-apple: void @c_arg_u8(i8 zeroext %_a)
@@ -113,6 +123,18 @@ pub extern "C" fn c_arg_i32(_a: i32) {}
113123
#[no_mangle]
114124
pub extern "C" fn c_arg_i64(_a: i64) {}
115125

126+
// x86_64: zeroext i1 @c_ret_bool()
127+
// i686: zeroext i1 @c_ret_bool()
128+
// aarch64-apple: zeroext i1 @c_ret_bool()
129+
// aarch64-windows: i1 @c_ret_bool()
130+
// aarch64-linux: i1 @c_ret_bool()
131+
// arm: zeroext i1 @c_ret_bool()
132+
// riscv: zeroext i1 @c_ret_bool()
133+
#[no_mangle]
134+
pub extern "C" fn c_ret_bool() -> bool {
135+
false
136+
}
137+
116138
// x86_64: zeroext i8 @c_ret_u8()
117139
// i686: zeroext i8 @c_ret_u8()
118140
// aarch64-apple: zeroext i8 @c_ret_u8()
@@ -210,10 +232,13 @@ pub extern "C" fn c_ret_i64() -> i64 {
210232
}
211233

212234
const C_SOURCE_FILE: &'static str = r##"
235+
#include <stdbool.h>
213236
#include <stdlib.h>
214237
#include <stdint.h>
215238
#include <stdio.h>
216239
240+
void c_arg_bool(bool _a) { }
241+
217242
void c_arg_u8(uint8_t _a) { }
218243
void c_arg_u16(uint16_t _a) { }
219244
void c_arg_u32(uint32_t _a) { }
@@ -224,6 +249,8 @@ void c_arg_i16(int16_t _a) { }
224249
void c_arg_i32(int32_t _a) { }
225250
void c_arg_i64(int64_t _a) { }
226251
252+
bool c_ret_bool() { return false; }
253+
227254
uint8_t c_ret_u8() { return 0; }
228255
uint16_t c_ret_u16() { return 0; }
229256
uint32_t c_ret_u32() { return 0; }

0 commit comments

Comments
 (0)