Skip to content

Commit d0475ed

Browse files
authored
Merge pull request #1598 from rust-lang/compiler_builtins_compare_type
Use the correct return type for compiler-builtins float compares
2 parents 775ae5e + 992c2c6 commit d0475ed

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/codegen_f16_f128.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::compiler_builtins::CMP_RESULT_TY;
12
use crate::prelude::*;
23

34
pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
@@ -70,13 +71,10 @@ pub(crate) fn fcmp(fx: &mut FunctionCx<'_, '_, '_>, cc: FloatCC, lhs: Value, rhs
7071
let res = fx.lib_call(
7172
name,
7273
vec![AbiParam::new(types::F128), AbiParam::new(types::F128)],
73-
// FIXME(rust-lang/compiler-builtins#919): This should be `I64` on non-AArch64
74-
// architectures, but switching it before compiler-builtins is fixed causes test
75-
// failures.
76-
vec![AbiParam::new(types::I32)],
74+
vec![AbiParam::new(CMP_RESULT_TY)],
7775
&[lhs, rhs],
7876
)[0];
79-
let zero = fx.bcx.ins().iconst(types::I32, 0);
77+
let zero = fx.bcx.ins().iconst(CMP_RESULT_TY, 0);
8078
let res = fx.bcx.ins().icmp(int_cc, res, zero);
8179
res
8280
}

src/compiler_builtins.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ use std::ffi::c_int;
33
#[cfg(feature = "jit")]
44
use std::ffi::c_void;
55

6+
use cranelift_codegen::ir::{Type, types};
7+
68
// FIXME replace with core::ffi::c_size_t once stabilized
79
#[allow(non_camel_case_types)]
810
#[cfg(feature = "jit")]
911
type size_t = usize;
1012

13+
// Needs to stay in sync with compiler-builtins
14+
15+
// Aarch64 uses `int` rather than a pointer-sized value.
16+
#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))]
17+
#[cfg(feature = "jit")]
18+
type CmpResult = i32;
19+
#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))]
20+
pub(crate) const CMP_RESULT_TY: Type = types::I32;
21+
22+
// In compiler-rt, LLP64 ABIs use `long long` and everything else uses `long`. In effect,
23+
// this means the return value is always pointer-sized.
24+
#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))]
25+
#[cfg(feature = "jit")]
26+
type CmpResult = isize;
27+
#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))]
28+
#[cfg(target_pointer_width = "32")]
29+
pub(crate) const CMP_RESULT_TY: Type = types::I32;
30+
#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))]
31+
#[cfg(target_pointer_width = "64")]
32+
pub(crate) const CMP_RESULT_TY: Type = types::I64;
33+
1134
macro_rules! builtin_functions {
1235
(
1336
$register:ident;
@@ -88,12 +111,12 @@ builtin_functions! {
88111
#[cfg(not(all(target_os = "windows", target_env = "gnu")))]
89112
fn fmodf128(a: f128, b: f128) -> f128;
90113
// float comparison
91-
fn __eqtf2(a: f128, b: f128) -> i32;
92-
fn __netf2(a: f128, b: f128) -> i32;
93-
fn __lttf2(a: f128, b: f128) -> i32;
94-
fn __letf2(a: f128, b: f128) -> i32;
95-
fn __gttf2(a: f128, b: f128) -> i32;
96-
fn __getf2(a: f128, b: f128) -> i32;
114+
fn __eqtf2(a: f128, b: f128) -> CmpResult;
115+
fn __netf2(a: f128, b: f128) -> CmpResult;
116+
fn __lttf2(a: f128, b: f128) -> CmpResult;
117+
fn __letf2(a: f128, b: f128) -> CmpResult;
118+
fn __gttf2(a: f128, b: f128) -> CmpResult;
119+
fn __getf2(a: f128, b: f128) -> CmpResult;
97120
#[cfg(not(all(target_os = "windows", target_env = "gnu")))]
98121
fn fminimumf128(a: f128, b: f128) -> f128;
99122
#[cfg(not(all(target_os = "windows", target_env = "gnu")))]

0 commit comments

Comments
 (0)