Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
96f385b
RawVecInner: add missing `unsafe` to unsafe fns
btj Aug 7, 2025
42cf78f
llvm: update remarks support on LLVM 22
durin42 Sep 22, 2025
f509dff
f16_f128: enable some more tests in Miri
RalfJung Sep 18, 2025
b2634e3
std: add support for armv7a-vex-v5 target
tropicaaal Sep 24, 2025
a86f140
do not materialise X in [X; 0] when X is unsizing a const
dingxiangfei2009 Aug 11, 2025
120162e
add test fixture for newly allowed const expr
dingxiangfei2009 Aug 12, 2025
b77de83
mark THIR use as candidate for constness check
dingxiangfei2009 Sep 24, 2025
a00f241
unstably constify float mul_add methods
Qelxiros Sep 18, 2025
aa75d34
Small string formatting cleanup
GuillaumeGomez Sep 24, 2025
fe440ec
llvm: add a destructor to call releaseSerializer
cuviper Sep 24, 2025
bc37dd4
Remove an erroneous normalization step in `tests/run-make/linker-warn…
fmease Sep 24, 2025
6de25aa
Rollup merge of #145067 - btj:patch-3, r=tgross35
matthiaskrgr Sep 25, 2025
afef339
Rollup merge of #145277 - dingxiangfei2009:fold-coercion-into-const, …
matthiaskrgr Sep 25, 2025
a4a77e9
Rollup merge of #145973 - vexide:vex-std, r=tgross35
matthiaskrgr Sep 25, 2025
eef61dd
Rollup merge of #146735 - Qelxiros:const_mul_add, r=tgross35,RalfJung
matthiaskrgr Sep 25, 2025
a227044
Rollup merge of #146737 - RalfJung:f16-f128-miri, r=tgross35
matthiaskrgr Sep 25, 2025
fa47398
Rollup merge of #146905 - durin42:llvm-22-bitstream-remarks, r=nikic
matthiaskrgr Sep 25, 2025
a369f41
Rollup merge of #146982 - fmease:fix-rmake-linker-warning, r=bjorn3
matthiaskrgr Sep 25, 2025
12b063e
Rollup merge of #147005 - GuillaumeGomez:string-formatting-cleanup, r…
matthiaskrgr Sep 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,14 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
dest,
rustc_apfloat::Round::NearestTiesToEven,
)?,
sym::fmaf16 => self.fma_intrinsic::<Half>(args, dest)?,
sym::fmaf32 => self.fma_intrinsic::<Single>(args, dest)?,
sym::fmaf64 => self.fma_intrinsic::<Double>(args, dest)?,
sym::fmaf128 => self.fma_intrinsic::<Quad>(args, dest)?,
sym::fmuladdf16 => self.float_muladd_intrinsic::<Half>(args, dest)?,
sym::fmuladdf32 => self.float_muladd_intrinsic::<Single>(args, dest)?,
sym::fmuladdf64 => self.float_muladd_intrinsic::<Double>(args, dest)?,
sym::fmuladdf128 => self.float_muladd_intrinsic::<Quad>(args, dest)?,

// Unsupported intrinsic: skip the return_to_block below.
_ => return interp_ok(false),
Expand Down Expand Up @@ -1035,4 +1043,42 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
self.write_scalar(res, dest)?;
interp_ok(())
}

fn fma_intrinsic<F>(
&mut self,
args: &[OpTy<'tcx, M::Provenance>],
dest: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ()>
where
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
{
let a: F = self.read_scalar(&args[0])?.to_float()?;
let b: F = self.read_scalar(&args[1])?.to_float()?;
let c: F = self.read_scalar(&args[2])?.to_float()?;

let res = a.mul_add(b, c).value;
let res = self.adjust_nan(res, &[a, b, c]);
self.write_scalar(res, dest)?;
interp_ok(())
}

fn float_muladd_intrinsic<F>(
&mut self,
args: &[OpTy<'tcx, M::Provenance>],
dest: &PlaceTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx, ()>
where
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
{
let a: F = self.read_scalar(&args[0])?.to_float()?;
let b: F = self.read_scalar(&args[1])?.to_float()?;
let c: F = self.read_scalar(&args[2])?.to_float()?;

let fuse = M::float_fuse_mul_add(self);

let res = if fuse { a.mul_add(b, c).value } else { ((a * b).value + c).value };
let res = self.adjust_nan(res, &[a, b, c]);
self.write_scalar(res, dest)?;
interp_ok(())
}
}
8 changes: 8 additions & 0 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ pub trait Machine<'tcx>: Sized {
a
}

/// Determines whether the `fmuladd` intrinsics fuse the multiply-add or use separate operations.
fn float_fuse_mul_add(_ecx: &mut InterpCx<'tcx, Self>) -> bool;

/// Called before a basic block terminator is executed.
#[inline]
fn before_terminator(_ecx: &mut InterpCx<'tcx, Self>) -> InterpResult<'tcx> {
Expand Down Expand Up @@ -672,6 +675,11 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
match fn_val {}
}

#[inline(always)]
fn float_fuse_mul_add(_ecx: &mut InterpCx<$tcx, Self>) -> bool {
true
}

#[inline(always)]
fn ub_checks(_ecx: &InterpCx<$tcx, Self>) -> InterpResult<$tcx, bool> {
// We can't look at `tcx.sess` here as that can differ across crates, which can lead to
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ fn get_codegen_sysroot(
.collect::<Vec<_>>()
.join("\n* ");
let err = format!(
"failed to find a `codegen-backends` folder \
in the sysroot candidates:\n* {candidates}"
"failed to find a `codegen-backends` folder in the sysroot candidates:\n\
* {candidates}"
);
early_dcx.early_fatal(err);
});
Expand All @@ -396,10 +396,8 @@ fn get_codegen_sysroot(

let d = sysroot.read_dir().unwrap_or_else(|e| {
let err = format!(
"failed to load default codegen backend, couldn't \
read `{}`: {}",
"failed to load default codegen backend, couldn't read `{}`: {e}",
sysroot.display(),
e
);
early_dcx.early_fatal(err);
});
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,14 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
RemarkStreamer(std::move(RemarkStreamer)),
LlvmRemarkStreamer(std::move(LlvmRemarkStreamer)) {}

#if LLVM_VERSION_GE(22, 0)
~RustDiagnosticHandler() {
if (RemarkStreamer) {
RemarkStreamer->releaseSerializer();
}
}
#endif

virtual bool handleDiagnostics(const DiagnosticInfo &DI) override {
// If this diagnostic is one of the optimization remark kinds, we can
// check if it's enabled before emitting it. This can avoid many
Expand Down Expand Up @@ -1779,9 +1787,14 @@ extern "C" void LLVMRustContextConfigureDiagnosticHandler(
// Do not delete the file after we gather remarks
RemarkFile->keep();

#if LLVM_VERSION_GE(22, 0)
auto RemarkSerializer = remarks::createRemarkSerializer(
llvm::remarks::Format::YAML, RemarkFile->os());
#else
auto RemarkSerializer = remarks::createRemarkSerializer(
llvm::remarks::Format::YAML, remarks::SerializerMode::Separate,
RemarkFile->os());
#endif
if (Error E = RemarkSerializer.takeError()) {
std::string Error = std::string("Cannot create remark serializer: ") +
toString(std::move(E));
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_middle::middle::region;
use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::*;
use rustc_middle::thir::*;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::cast::{CastTy, mir_cast_kind};
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, Ty, UpvarArgs};
Expand Down Expand Up @@ -656,6 +657,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(rvalue)
}

/// Recursively inspect a THIR expression and probe through unsizing
/// operations that can be const-folded today.
fn check_constness(&self, mut kind: &'a ExprKind<'tcx>) -> bool {
loop {
debug!(?kind, "check_constness");
match kind {
&ExprKind::ValueTypeAscription { source: eid, user_ty: _, user_ty_span: _ }
| &ExprKind::Use { source: eid }
| &ExprKind::PointerCoercion {
cast: PointerCoercion::Unsize,
source: eid,
is_from_as_cast: _,
}
| &ExprKind::Scope { region_scope: _, lint_level: _, value: eid } => {
kind = &self.thir[eid].kind
}
_ => return matches!(Category::of(&kind), Some(Category::Constant)),
}
}
}

fn build_zero_repeat(
&mut self,
mut block: BasicBlock,
Expand All @@ -666,7 +688,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let this = self;
let value_expr = &this.thir[value];
let elem_ty = value_expr.ty;
if let Some(Category::Constant) = Category::of(&value_expr.kind) {
if this.check_constness(&value_expr.kind) {
// Repeating a const does nothing
} else {
// For a non-const, we may need to generate an appropriate `Drop`
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/targets/armv7a_vex_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn target() -> Target {
description: Some("ARMv7-A Cortex-A9 VEX V5 Brain".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(false),
std: Some(true),
},
pointer_width: 32,
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
Expand Down
10 changes: 10 additions & 0 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ dependencies = [
"rustc-demangle",
"std_detect",
"unwind",
"vex-sdk",
"wasi 0.11.1+wasi-snapshot-preview1",
"wasi 0.14.4+wasi-0.2.4",
"windows-targets 0.0.0",
Expand Down Expand Up @@ -379,6 +380,15 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "vex-sdk"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89f74fce61d7a7ba1589da9634c6305a72befb7cc9150c1f872d87d8060f32b9"
dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
Expand Down
Loading
Loading