Skip to content

Commit 336209e

Browse files
committedJan 10, 2025
Auto merge of #135328 - bjorn3:sync_cg_clif-2025-01-10, r=bjorn3
Subtree sync for rustc_codegen_cranelift This has a couple of changes that will conflict with #134338. r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
·
1.89.01.86.0
2 parents 252b07b + 92a664e commit 336209e

File tree

15 files changed

+93
-320
lines changed

15 files changed

+93
-320
lines changed
 

‎compiler/rustc_codegen_cranelift/Cargo.lock

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
1010

1111
[[package]]
1212
name = "anyhow"
13-
version = "1.0.94"
13+
version = "1.0.95"
1414
source = "registry+https://github.com/rust-lang/crates.io-index"
15-
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
15+
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
1616

1717
[[package]]
1818
name = "arbitrary"
19-
version = "1.3.2"
19+
version = "1.4.1"
2020
source = "registry+https://github.com/rust-lang/crates.io-index"
21-
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
21+
checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223"
2222

2323
[[package]]
2424
name = "bitflags"
@@ -211,9 +211,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
211211

212212
[[package]]
213213
name = "foldhash"
214-
version = "0.1.3"
214+
version = "0.1.4"
215215
source = "registry+https://github.com/rust-lang/crates.io-index"
216-
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
216+
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
217217

218218
[[package]]
219219
name = "gimli"
@@ -253,15 +253,15 @@ dependencies = [
253253

254254
[[package]]
255255
name = "libc"
256-
version = "0.2.155"
256+
version = "0.2.169"
257257
source = "registry+https://github.com/rust-lang/crates.io-index"
258-
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
258+
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
259259

260260
[[package]]
261261
name = "libloading"
262-
version = "0.8.4"
262+
version = "0.8.6"
263263
source = "registry+https://github.com/rust-lang/crates.io-index"
264-
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
264+
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
265265
dependencies = [
266266
"cfg-if",
267267
"windows-targets",
@@ -290,9 +290,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
290290

291291
[[package]]
292292
name = "object"
293-
version = "0.36.5"
293+
version = "0.36.7"
294294
source = "registry+https://github.com/rust-lang/crates.io-index"
295-
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e"
295+
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
296296
dependencies = [
297297
"crc32fast",
298298
"hashbrown 0.15.2",
@@ -311,9 +311,9 @@ dependencies = [
311311

312312
[[package]]
313313
name = "quote"
314-
version = "1.0.36"
314+
version = "1.0.38"
315315
source = "registry+https://github.com/rust-lang/crates.io-index"
316-
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
316+
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
317317
dependencies = [
318318
"proc-macro2",
319319
]
@@ -346,9 +346,9 @@ dependencies = [
346346

347347
[[package]]
348348
name = "rustc-hash"
349-
version = "2.0.0"
349+
version = "2.1.0"
350350
source = "registry+https://github.com/rust-lang/crates.io-index"
351-
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
351+
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
352352

353353
[[package]]
354354
name = "rustc_codegen_cranelift"
@@ -370,18 +370,18 @@ dependencies = [
370370

371371
[[package]]
372372
name = "serde"
373-
version = "1.0.215"
373+
version = "1.0.217"
374374
source = "registry+https://github.com/rust-lang/crates.io-index"
375-
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
375+
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
376376
dependencies = [
377377
"serde_derive",
378378
]
379379

380380
[[package]]
381381
name = "serde_derive"
382-
version = "1.0.215"
382+
version = "1.0.217"
383383
source = "registry+https://github.com/rust-lang/crates.io-index"
384-
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
384+
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
385385
dependencies = [
386386
"proc-macro2",
387387
"quote",
@@ -402,9 +402,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
402402

403403
[[package]]
404404
name = "syn"
405-
version = "2.0.90"
405+
version = "2.0.95"
406406
source = "registry+https://github.com/rust-lang/crates.io-index"
407-
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
407+
checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a"
408408
dependencies = [
409409
"proc-macro2",
410410
"quote",
@@ -419,9 +419,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
419419

420420
[[package]]
421421
name = "unicode-ident"
422-
version = "1.0.12"
422+
version = "1.0.14"
423423
source = "registry+https://github.com/rust-lang/crates.io-index"
424-
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
424+
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
425425

426426
[[package]]
427427
name = "wasmtime-jit-icache-coherence"

‎compiler/rustc_codegen_cranelift/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ libloading = { version = "0.8.0", optional = true }
2323
smallvec = "1.8.1"
2424

2525
[patch.crates-io]
26+
# Uncomment to use an unreleased version of cranelift
27+
#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
28+
#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
29+
#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
30+
#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
31+
#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
32+
#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
33+
2634
# Uncomment to use local checkout of cranelift
2735
#cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }
2836
#cranelift-frontend = { path = "../wasmtime/cranelift/frontend" }

‎compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@ pub(crate) fn build_sysroot(
3333
let cg_clif_dylib_path = match cg_clif_dylib_src {
3434
CodegenBackend::Local(src_path) => {
3535
// Copy the backend
36-
let cg_clif_dylib_path = if cfg!(windows) {
37-
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
38-
// binaries.
39-
dist_dir.join("bin")
40-
} else {
41-
dist_dir.join("lib")
42-
}
43-
.join(src_path.file_name().unwrap());
36+
let cg_clif_dylib_path = dist_dir.join("lib").join(src_path.file_name().unwrap());
4437
try_hard_link(src_path, &cg_clif_dylib_path);
4538
CodegenBackend::Local(cg_clif_dylib_path)
4639
}
@@ -102,19 +95,14 @@ pub(crate) fn build_sysroot(
10295
.install_into_sysroot(dist_dir);
10396
}
10497

105-
let mut target_compiler = {
106-
let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif"));
107-
let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif"));
108-
109-
Compiler {
110-
cargo: bootstrap_host_compiler.cargo.clone(),
111-
rustc: rustc_clif.clone(),
112-
rustdoc: rustdoc_clif.clone(),
113-
rustflags: vec![],
114-
rustdocflags: vec![],
115-
triple: target_triple,
116-
runner: vec![],
117-
}
98+
let mut target_compiler = Compiler {
99+
cargo: bootstrap_host_compiler.cargo.clone(),
100+
rustc: dist_dir.join(wrapper_base_name.replace("____", "rustc-clif")),
101+
rustdoc: dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif")),
102+
rustflags: vec![],
103+
rustdocflags: vec![],
104+
triple: target_triple,
105+
runner: vec![],
118106
};
119107
if !is_native {
120108
target_compiler.set_cross_linker_and_runner();

‎compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
7373
"example/arbitrary_self_types_pointers_and_wrappers.rs",
7474
&[],
7575
),
76-
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
77-
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
7876
TestCase::jit_bin("jit.std_example", "example/std_example.rs", "arg"),
7977
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
8078
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
@@ -89,7 +87,6 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
8987
&[],
9088
),
9189
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
92-
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
9390
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
9491
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
9592
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),

‎compiler/rustc_codegen_cranelift/config.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ aot.mini_core_hello_world
2121
testsuite.base_sysroot
2222
aot.arbitrary_self_types_pointers_and_wrappers
2323
aot.issue_91827_extern_types
24-
build.alloc_system
25-
aot.alloc_example
2624
jit.std_example
2725
aot.std_example
2826
aot.dst_field_align
2927
aot.subslice-patterns-const-eval
3028
aot.track-caller-attribute
3129
aot.float-minmax-pass
32-
aot.mod_bench
3330
aot.issue-72793
3431
aot.issue-59326
3532
aot.neon

‎compiler/rustc_codegen_cranelift/example/alloc_example.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎compiler/rustc_codegen_cranelift/example/alloc_system.rs

Lines changed: 0 additions & 124 deletions
This file was deleted.

‎compiler/rustc_codegen_cranelift/example/mod_bench.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2025-01-05"
2+
channel = "nightly-2025-01-10"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]
44
profile = "minimal"

‎compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
if let Some(name) = option_env!("BUILTIN_BACKEND") {
1717
rustflags.push(format!("-Zcodegen-backend={name}"));
1818
} else {
19-
let dylib = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
19+
let dylib = sysroot.join("lib").join(
2020
env::consts::DLL_PREFIX.to_string()
2121
+ "rustc_codegen_cranelift"
2222
+ env::consts::DLL_SUFFIX,

‎compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
sysroot = sysroot.parent().unwrap();
1212
}
1313

14-
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
14+
let cg_clif_dylib_path = sysroot.join("lib").join(
1515
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
1616
);
1717

‎compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
sysroot = sysroot.parent().unwrap();
1212
}
1313

14-
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
14+
let cg_clif_dylib_path = sysroot.join("lib").join(
1515
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
1616
);
1717

‎compiler/rustc_codegen_cranelift/src/codegen_i128.rs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ pub(crate) fn maybe_codegen<'tcx>(
6262
}
6363
}
6464

65-
pub(crate) fn maybe_codegen_checked<'tcx>(
65+
pub(crate) fn maybe_codegen_mul_checked<'tcx>(
6666
fx: &mut FunctionCx<'_, '_, 'tcx>,
67-
bin_op: BinOp,
6867
lhs: CValue<'tcx>,
6968
rhs: CValue<'tcx>,
7069
) -> Option<CValue<'tcx>> {
@@ -78,32 +77,19 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
7877

7978
let is_signed = type_sign(lhs.layout().ty);
8079

81-
match bin_op {
82-
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
83-
BinOp::Add | BinOp::Sub => None,
84-
BinOp::Mul => {
85-
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
86-
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
87-
let param_types = vec![
88-
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
89-
AbiParam::new(types::I128),
90-
AbiParam::new(types::I128),
91-
];
92-
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
93-
fx.lib_call(
94-
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
95-
param_types,
96-
vec![],
97-
&args,
98-
);
99-
Some(out_place.to_cvalue(fx))
100-
}
101-
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
102-
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
103-
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
104-
BinOp::Div | BinOp::Rem => unreachable!(),
105-
BinOp::Cmp => unreachable!(),
106-
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
107-
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => unreachable!(),
108-
}
80+
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
81+
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
82+
let param_types = vec![
83+
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
84+
AbiParam::new(types::I128),
85+
AbiParam::new(types::I128),
86+
];
87+
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
88+
fx.lib_call(
89+
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
90+
param_types,
91+
vec![],
92+
&args,
93+
);
94+
Some(out_place.to_cvalue(fx))
10995
}

‎compiler/rustc_codegen_cranelift/src/driver/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ impl Drop for TimingGuard {
7373

7474
impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
7575
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
76-
let mut timing_guard =
77-
TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None };
76+
let mut timing_guard = Box::new(TimingGuard {
77+
profiler: std::mem::ManuallyDrop::new(self.0.clone()),
78+
inner: None,
79+
});
7880
timing_guard.inner = Some(
7981
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
8082
.generic_activity(pass.description()),
8183
);
82-
Box::new(timing_guard)
84+
timing_guard
8385
}
8486
}

‎compiler/rustc_codegen_cranelift/src/num.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
use crate::prelude::*;
44

5-
pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
5+
pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> IntCC {
66
use BinOp::*;
77
use IntCC::*;
8-
Some(match bin_op {
8+
match bin_op {
99
Eq => Equal,
1010
Lt => {
1111
if signed {
@@ -36,8 +36,8 @@ pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
3636
UnsignedGreaterThan
3737
}
3838
}
39-
_ => return None,
40-
})
39+
_ => unreachable!(),
40+
}
4141
}
4242

4343
fn codegen_three_way_compare<'tcx>(
@@ -48,8 +48,8 @@ fn codegen_three_way_compare<'tcx>(
4848
) -> CValue<'tcx> {
4949
// This emits `(lhs > rhs) - (lhs < rhs)`, which is cranelift's preferred form per
5050
// <https://github.com/bytecodealliance/wasmtime/blob/8052bb9e3b792503b225f2a5b2ba3bc023bff462/cranelift/codegen/src/prelude_opt.isle#L41-L47>
51-
let gt_cc = crate::num::bin_op_to_intcc(BinOp::Gt, signed).unwrap();
52-
let lt_cc = crate::num::bin_op_to_intcc(BinOp::Lt, signed).unwrap();
51+
let gt_cc = crate::num::bin_op_to_intcc(BinOp::Gt, signed);
52+
let lt_cc = crate::num::bin_op_to_intcc(BinOp::Lt, signed);
5353
let gt = fx.bcx.ins().icmp(gt_cc, lhs, rhs);
5454
let lt = fx.bcx.ins().icmp(lt_cc, lhs, rhs);
5555
let val = fx.bcx.ins().isub(gt, lt);
@@ -63,11 +63,7 @@ fn codegen_compare_bin_op<'tcx>(
6363
lhs: Value,
6464
rhs: Value,
6565
) -> CValue<'tcx> {
66-
if bin_op == BinOp::Cmp {
67-
return codegen_three_way_compare(fx, signed, lhs, rhs);
68-
}
69-
70-
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
66+
let intcc = crate::num::bin_op_to_intcc(bin_op, signed);
7167
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
7268
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
7369
}
@@ -79,7 +75,7 @@ pub(crate) fn codegen_binop<'tcx>(
7975
in_rhs: CValue<'tcx>,
8076
) -> CValue<'tcx> {
8177
match bin_op {
82-
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt | BinOp::Cmp => {
78+
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
8379
match in_lhs.layout().ty.kind() {
8480
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
8581
let signed = type_sign(in_lhs.layout().ty);
@@ -91,6 +87,16 @@ pub(crate) fn codegen_binop<'tcx>(
9187
_ => {}
9288
}
9389
}
90+
BinOp::Cmp => match in_lhs.layout().ty.kind() {
91+
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
92+
let signed = type_sign(in_lhs.layout().ty);
93+
let lhs = in_lhs.load_scalar(fx);
94+
let rhs = in_rhs.load_scalar(fx);
95+
96+
return codegen_three_way_compare(fx, signed, lhs, rhs);
97+
}
98+
_ => {}
99+
},
94100
_ => {}
95101
}
96102

@@ -200,10 +206,6 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
200206
let lhs = in_lhs.load_scalar(fx);
201207
let rhs = in_rhs.load_scalar(fx);
202208

203-
if let Some(res) = crate::codegen_i128::maybe_codegen_checked(fx, bin_op, in_lhs, in_rhs) {
204-
return res;
205-
}
206-
207209
let signed = type_sign(in_lhs.layout().ty);
208210

209211
let (res, has_overflow) = match bin_op {
@@ -236,6 +238,10 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
236238
(val, has_overflow)
237239
}
238240
BinOp::Mul => {
241+
if let Some(res) = crate::codegen_i128::maybe_codegen_mul_checked(fx, in_lhs, in_rhs) {
242+
return res;
243+
}
244+
239245
let ty = fx.bcx.func.dfg.value_type(lhs);
240246
match ty {
241247
types::I8 | types::I16 | types::I32 if !signed => {
@@ -357,14 +363,12 @@ pub(crate) fn codegen_float_binop<'tcx>(
357363
_ => bug!(),
358364
};
359365

360-
let ret_val = fx.lib_call(
366+
fx.lib_call(
361367
name,
362368
vec![AbiParam::new(ty), AbiParam::new(ty)],
363369
vec![AbiParam::new(ty)],
364370
&[lhs, rhs],
365-
)[0];
366-
367-
return CValue::by_val(ret_val, in_lhs.layout());
371+
)[0]
368372
}
369373
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
370374
let fltcc = match bin_op {
@@ -431,13 +435,9 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
431435
BinOp::Lt | BinOp::Le | BinOp::Ge | BinOp::Gt => {
432436
let ptr_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_ptr, rhs_ptr);
433437

434-
let ptr_cmp =
435-
fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false).unwrap(), lhs_ptr, rhs_ptr);
436-
let extra_cmp = fx.bcx.ins().icmp(
437-
bin_op_to_intcc(bin_op, false).unwrap(),
438-
lhs_extra,
439-
rhs_extra,
440-
);
438+
let ptr_cmp = fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false), lhs_ptr, rhs_ptr);
439+
let extra_cmp =
440+
fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false), lhs_extra, rhs_extra);
441441

442442
fx.bcx.ins().select(ptr_eq, extra_cmp, ptr_cmp)
443443
}

0 commit comments

Comments
 (0)
Please sign in to comment.