Commit Graph

433 Commits

Author SHA1 Message Date
bors 8da2d28cbd Auto merge of #142531 - ohadravid:better-storage-calls-copy-prop, r=tmiasko,cjgillot,saethlin
Remove fewer Storage calls in CopyProp and GVN



Modify the CopyProp and GVN MIR optimization passes to remove fewer `Storage{Live,Dead}` calls, allowing for better optimizations by LLVM - see rust-lang/rust#141649.

### Details

The idea is to use a new `MaybeUninitializedLocals` analysis and remove only the storage calls of locals that are maybe-uninit when accessed in a new location.
2026-04-18 09:16:07 +00:00
Jacob Pratt baf4388b8f Rollup merge of #147811 - folkertdev:naked-function-sections, r=Amanieu
naked functions: respect `function-sections`

fixes https://github.com/rust-lang/rust/issues/147789

r? @Amanieu
2026-04-18 00:05:15 -04:00
Ohad Ravid 5632001f83 Improve copy_prop and GVN mir-opt passes to remove fewer storage calls 2026-04-17 16:55:43 +03:00
bors 27dbdb57a2 Auto merge of #155416 - Zalathar:rollup-D1EWnrR, r=Zalathar
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#141633 (Suggest to bind `self.x` to `x` when field `x` may be in format string)
 - rust-lang/rust#152980 (c-variadic: fix implementation on `avr`)
 - rust-lang/rust#154491 (Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug))
 - rust-lang/rust#155318 (Use mutable pointers for Unix path buffers)
 - rust-lang/rust#155335 (Bump bootstrap to 1.96 beta)
 - rust-lang/rust#155354 (Remove AttributeSafety from BUILTIN_ATTRIBUTES)
 - rust-lang/rust#154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases)
 - rust-lang/rust#155095 (changed the information provided by (mut x) to mut x (Fix 155030))
 - rust-lang/rust#155305 (Make `convert_while_ascii` unsafe)
 - rust-lang/rust#155358 (ImproperCTypes: Move erasing_region_normalisation into helper function)
 - rust-lang/rust#155377 (tests/debuginfo/basic-stepping.rs: Remove FIXME related to ZSTs)
 - rust-lang/rust#155383 (Rearrange `rustc_ast_pretty`)
 - rust-lang/rust#155384 (triagebot: notify on diagnostic attribute changes)
 - rust-lang/rust#155386 (Use `box_new` diagnostic item for Box::new suggestions)
 - rust-lang/rust#155391 (Small refactor of `QueryJob::latch` method)
 - rust-lang/rust#155395 (Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc)
 - rust-lang/rust#155396 (`as_ref_unchecked` docs link fix)
 - rust-lang/rust#155411 (compiletest: Remove the `//@ should-ice` directive)
 - rust-lang/rust#155413 (fix: typo in `std::fs::hard_link` documentation)
2026-04-17 07:35:43 +00:00
Dominik Schwaiger da2bbfbbec add llvm writable attribute conditionally 2026-04-16 12:29:39 +00:00
Folkert de Vries bc4aad37ca naked-functions: properly document the -Zfunction-sections windows status 2026-04-16 11:37:45 +02:00
Folkert de Vries 872301bfdd naked functions: respect function_sections on linux/macos 2026-04-16 11:37:45 +02:00
Folkert de Vries 0e522d6c62 naked functions: respect function_sections on windows
For `gnu` function_sections is off by default.
2026-04-16 11:37:45 +02:00
John Kåre Alsaker 99ed1b81d7 Make convert_while_ascii unsafe 2026-04-14 20:27:30 +02:00
Jacob Pratt 803a7227fb Rollup merge of #155005 - folkertdev:simd-element-type-llvm, r=nnethercote
preserve SIMD element type information

Preserve the SIMD element type and provide it to LLVM for better optimization.

This is relevant for AArch64 types like `int16x4x2_t`, see also https://github.com/llvm/llvm-project/issues/181514. Such types are defined like so:

```rust
#[repr(simd)]
struct int16x4_t([i16; 4]);

#[repr(C)]
struct int16x4x2_t(pub int16x4_t, pub int16x4_t);
```

Previously this would be translated to the opaque `[2 x <8 x i8>]`, with this PR it is instead `[2 x <4 x i16>]`. That change is not relevant for the ABI, but using the correct type prevents bitcasts that can (indeed, do) confuse the LLVM pattern matcher.

This change will make it possible to implement the deinterleaving loads on AArch64 in a portable way (without neon-specific intrinsics), which means that e.g. Miri or the cranelift backend can run them without additional support.

discussion at [#t-compiler > loss of vector element type information](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/loss.20of.20vector.20element.20type.20information/with/584483611)
2026-04-14 00:37:24 -04:00
Folkert de Vries 6f428df8df preseve SIMD element type information
and provide it to LLVM for better optimization
2026-04-13 13:26:50 +02:00
sayantn 11f350da38 Add autocast for bf16 and bf16xN 2026-04-12 23:33:27 +05:30
sayantn 5aa800af80 Add autocast for i1 vectors 2026-04-12 23:33:27 +05:30
sayantn 3d89a5be50 Add autocasts for structs 2026-04-12 23:33:27 +05:30
Jacob Pratt d788fbfb58 Rollup merge of #155015 - jakubadamw:issues-104037-112623-113899, r=Kivooeo
Add tests for three fixed issues (an LLVM crash, an ICE and poor codegen)

Closes rust-lang/rust#104037.
Closes rust-lang/rust#112623.
Closes rust-lang/rust#113899.
2026-04-10 00:00:01 -04:00
Jacob Pratt 5a6abf3425 Rollup merge of #154677 - Darksonn:hwasan-tagged-globals, r=davidtwco
hwaddress: automatically add `-Ctarget-feature=+tagged-globals`

Note that since HWAddressSanitizer is/should be a target modifier, we do not have to worry about whether this LLVM target feature changes the ABI.

Fixes: rust-lang/rust#148185
2026-04-09 23:59:59 -04:00
Jacob Adam fc9f492049 Add a codegen test for a missed optimisation with spare niches 2026-04-09 09:42:47 +01:00
Jonathan Brouwer b040d5493e Rollup merge of #154598 - folkertdev:windows-naked-link-section, r=mati865
test `#[naked]` with `#[link_section = "..."]` on windows

As a part of https://github.com/rust-lang/rust/pull/147811 I ran into that we actually don't match (current) LLVM output.

r? @mati865
2026-04-08 23:04:33 +02:00
Jonathan Brouwer 66a00ba2ef Rollup merge of #153995 - Flakebi:gpu-use-convergent, r=nnethercote
Use convergent attribute to funcs for GPU targets

On targets with convergent operations, we need to add the convergent attribute to all functions that run convergent operations. Following clang, we can conservatively apply the attribute to all functions when compiling for such a target and rely on LLVM optimizing away the attribute in cases where it is not necessary.

This affects the amdgpu and nvptx targets.

cc @kjetilkjeka, @kulst for nvptx
cc @ZuseZ4

r? @nnethercote, as you already reviewed this in the other PR

Split out from rust-lang/rust#149637, the part here should be uncontroversial.
2026-04-08 14:21:57 +02:00
bors 30d0309fa8 Auto merge of #148486 - kpreid:vec-iter-drop, r=jhpratt
Explicitly forget the zero remaining elements in `vec::IntoIter::fold()`.



[Original description:] ~~This seems to help LLVM notice that dropping the elements in the destructor of `IntoIter` is not necessary. In cases it doesn’t help, it should be cheap since it is just one assignment.~~

This PR adds a function to `vec::IntoIter()` which is used used by `fold()` and `spec_extend()`, when those operations complete, to forget the zero remaining elements and only deallocate the allocation, ensuring that there will never be a useless loop to drop zero remaining elements when the iterator is dropped.

This is my first ever attempt at this kind of codegen micro-optimization in the standard library, so please let me know what should go into the PR or what sort of additional systematic testing might indicate this is a good or bad idea.
2026-04-08 02:06:51 +00:00
Jonathan Brouwer e3615a3c02 Rollup merge of #153269 - fmease:gci-reach-no-eval, r=BoxyUwU
GCI: During reachability analysis don't try to evaluate the initializer of overly generic free const items

We generally don't want the initializer of free const items to get evaluated if they have any non-lifetime generic parameters. However, while I did account for that in HIR analysis & mono item collection (rust-lang/rust#136168 & rust-lang/rust#136429), I didn't account for reachability analysis so far which means that on main we still evaluate such items if they are *public* for example.

The closed PR rust-lang/rust#142293 from a year ago did address that as a byproduct but of course it wasn't merged since its primary goal was misguided. This PR extracts & improves upon the relevant parts of that PR which are necessary to fix said issue.

Follow up to rust-lang/rust#136168 & rust-lang/rust#136429.
Partially supersedes rust-lang/rust#142293.
Part of rust-lang/rust#113521.

r? @BoxyUwU
2026-04-07 17:26:28 +02:00
Folkert de Vries 72b6825828 test #[naked] with #[link_section = "..."] on windows 2026-04-06 14:58:52 +02:00
bors 0312a55fe4 Auto merge of #154802 - matthiaskrgr:rollup-HWNmEyC, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#154376 (Remove more BuiltinLintDiag variants - part 4)
 - rust-lang/rust#154731 (llvm: Fix array ABI test to not check equality implementation)
 - rust-lang/rust#127534 (feat(core): impl Step for NonZero<u*>)
 - rust-lang/rust#154703 (Fix trailing comma in lifetime suggestion for empty angle brackets)
 - rust-lang/rust#154776 (Fix ICE in read_discriminant for enums with non-contiguous discriminants)
2026-04-04 14:36:56 +00:00
Matthew Maurer d6be991fb4 llvm: Fix array ABI test to not check equality implementation
LLVM has moved memcmp expansion in the pipeline, resulting in the bcmp
call being expanded into loads and register comparisons, which breaks
the test.

Based on history, I believe the test actually intended validate that
these arrays were being passed as pointer arguments, which can be done
more directly.
2026-04-03 22:31:45 +00:00
David Wood a24ee0329e cg_llvm/debuginfo: scalable vectors
Generate debuginfo for scalable vectors, following the structure that
Clang generates for scalable vectors.
2026-04-03 10:37:42 +00:00
David Wood 4fbcb031de cg_llvm: sve_tuple_{create,get,set} intrinsics
Clang changed to representing tuples of scalable vectors as
structs rather than as wide vectors (that is, scalable vector types
where the `N` part of the `<vscale x N x ty>` type was multiplied by
the number of vectors). rustc mirrored this in the initial implementation
of scalable vectors.

Earlier versions of our patches used the wide vector representation and
our intrinsic patches used the legacy
`llvm.aarch64.sve.tuple.{create,get,set}{2,3,4}` intrinsics for creating
these tuples/getting/setting the vectors, which were only supported
due to LLVM's `AutoUpgrade` pass converting these intrinsics into
`llvm.vector.insert`. `AutoUpgrade` only supports these legacy intrinsics
with the wide vector representation.

With the current struct representation, Clang has special handling in
codegen for generating `insertvalue`/`extractvalue` instructions for
these operations, which must be replicated by rustc's codegen for our
intrinsics to use. This patch implements new intrinsics in
`core::intrinsics::scalable` (mirroring the structure of
`core::intrinsics::simd`) which rustc lowers to the appropriate
`insertvalue`/`extractvalue` instructions.
2026-04-03 10:27:30 +00:00
León Orell Valerian Liehr cf4e8c6752 GCI: During reachability analysis don't try to evaluate the initializer of overly generic free const items 2026-04-03 03:22:19 +02:00
Wesley Wiser c9d3a00cd1 Revert "Fix: On wasm targets, call panic_in_cleanup if panic occurs in cleanup"
This reverts commit acbfd79acf.
2026-04-01 21:29:42 -05:00
Alice Ryhl 6fc3880b04 hwaddress: automatically add -Ctarget-feature=tagged-globals 2026-04-01 12:38:55 +00:00
Eddy (Eduard) Stefes f39fa9e4c0 add rustc option -Zpacked-stack
this enables packed-stack just as -mpacked-stack in clang and gcc.
packed-stack is needed on s390x for kernel development.

Co-authored-by: Ralf Jung <post@ralfj.de>
2026-03-31 09:06:31 +02:00
Trevor Gross 0bb3fe315e core: Move {RangeIter, RangeFromIter}::remainder to new_range_remainder
Split the remainder functions from the rest of `std::range`.
2026-03-29 02:11:32 -05:00
Guillaume Gomez 67ab3ac423 Rollup merge of #154043 - RalfJung:simd-min-max, r=Amanieu,calebzulawski,antoyo
simd_fmin/fmax: make semantics and name consistent with scalar intrinsics

This is the SIMD version of https://github.com/rust-lang/rust/pull/153343: change the documented semantics of the SIMD float min/max intrinsics to that of the scalar intrinsics, and also make the name consistent. The overall semantic change this amounts to is that we restrict the non-determinism: the old semantics effectively mean "when one input is an SNaN, the result non-deterministically is a NaN or the other input"; the new semantics say that in this case the other input must be returned. For all other cases, old and new semantics are equivalent. This means all users of these intrinsics that were correct with the old semantics are still correct: the overall set of possible behaviors has become smaller, no new possible behaviors are being added.

In terms of providers of this API:
- Miri, GCC, and cranelift already implement the new semantics, so no changes are needed.
- LLVM is adjusted to use `minimumnum nsz` instead of `minnum`, thus giving us the new semantics.

In terms of consumers of this API:
- Portable SIMD almost certainly wants to match the scalar behavior, so this is strictly a bugfix here.
- Stdarch mostly stopped using the intrinsic, except on nvptx, where arguably the new semantics are closer to what we actually want than the old semantics (https://github.com/rust-lang/stdarch/issues/2056).

Q: Should there be an `f` in the intrinsic name to indicate that it is for floats? E.g., `simd_fminimum_number_nsz`?

Also see https://github.com/rust-lang/rust/issues/153395.
2026-03-29 00:06:50 +01:00
Guillaume Gomez aad3710227 Rollup merge of #153380 - pitaj:stabilize-new_range_from_api, r=tgross35
stabilize new RangeFrom type and iterator

```rust
// in core and std
pub mod range;

// in core::range

pub struct RangeFrom<Idx> {
    pub start: Idx,
}

impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> { /* ... */ }

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
    pub const fn contains<U>(&self, item: &U) -> bool
    where
        Idx: [const] PartialOrd<U>,
        U: ?Sized + [const] PartialOrd<Idx>;
}

impl<Idx: Step> RangeFrom<Idx> {
    pub fn iter(&self) -> RangeFromIter<Idx>;
}

impl<T> const RangeBounds<T> for RangeFrom<T> { /* ... */ }
impl<T> const RangeBounds<T> for RangeFrom<&T> { /* ... */ }

impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { /* ... */ }
impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { /* ... */ }

pub struct RangeFromIter<A>(/* ... */);

// `RangeFromIter::remainder` left unstable

impl<A: Step> Iterator for RangeFromIter<A> {
    type Item = A;
    /* ... */
}

impl<A: Step> FusedIterator for RangeFromIter<A> { }
impl<A: Step> IntoIterator for RangeFrom<A> {
    type Item = A;
    type IntoIter = RangeFromIter<A>;
    /* ... */
}

unsafe impl<T> const SliceIndex<[T]> for range::RangeFrom<usize> {
    type Output = [T];
    /* ... */
}
unsafe impl const SliceIndex<str> for range::RangeFrom<usize> {
    type Output = str;
    /* ... */
}

impl ops::Index<range::RangeFrom<usize>> for CStr {
    type Output = CStr;
    /* ... */
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/125687
2026-03-29 00:06:49 +01:00
Peter Jaszkowiak 085dff4944 stabilize new RangeFrom type and iterator
stabilizes `core::range::RangeFrom`
stabilizes `core::range::RangeFromIter`

add examples for `remainder` method on range iterators
`RangeFromIter::remainder` was not stabilized (see issue 154458)
2026-03-28 12:00:10 -06:00
bors fb27476aaf Auto merge of #154468 - Kobzol:revert-154200, r=dingxiangfei2009
Revert "Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009"

This reverts commit 2f1603077b, reversing
changes made to 6e3c17424d.

Debugging perf. hit from https://github.com/rust-lang/rust/pull/154384.

The binary size hits from https://github.com/rust-lang/rust/pull/154468#issuecomment-4144557076 were due to this PR, not all of the copmile-time hits though.
2026-03-28 16:59:18 +00:00
bors 7e28c7438a Auto merge of #153821 - Lars-Schumann:const-step, r=Mark-Simulacrum
constify `Step` trait and all of its `impl`ementations

constifying [Step](https://github.com/rust-lang/rust/issues/42168) trait and all of its implementations, with some friendly help from [const_cmp](https://github.com/rust-lang/rust/issues/143800)
2026-03-28 10:44:18 +00:00
Jakub Beránek 8b44562bc8 Revert "Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009"
This reverts commit 2f1603077b, reversing
changes made to 6e3c17424d.
2026-03-27 20:08:24 +01:00
Jonathan Brouwer c026640a4f Rollup merge of #154360 - heiher:fromrangeiter-overflow-checks, r=jieyouxu
fromrangeiter-overflow-checks: accept optional `signext` for argument

On some targets such as LoongArch64 and RISCV64, the ABI requires sign-extension for 32-bit integer arguments, so LLVM may emit the `signext` attribute for the `%range` parameter. The existing CHECK pattern required the argument to be exactly `i32 noundef %range`, causing the test to fail on those targets.

Allow an optional `signext` attribute in the CHECK pattern so the test passes consistently across architectures without affecting the intended codegen validation.
2026-03-25 19:53:02 +01:00
Jonathan Brouwer 2f1603077b Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009
debuginfo: emit DW_TAG_call_site entries

Set `FlagAllCallsDescribed` on function definition DIEs so LLVM emits DW_TAG_call_site entries, letting debuggers and analysis tools track tail calls.
2026-03-25 19:52:50 +01:00
Jonathan Brouwer 0cd8de3843 Rollup merge of #153049 - Darksonn:kasan-sw-tags, r=fmease
Add `-Zsanitize=kernel-hwaddress`

The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS`  that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust.

One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable.

Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it.

MCP: https://github.com/rust-lang/compiler-team/issues/975
Tracking issue: https://github.com/rust-lang/rust/issues/154171

cc @rcvalle @maurer @ojeda
2026-03-25 19:52:49 +01:00
WANG Rui 7cb28c980d fromrangeiter-overflow-checks: accept optional signext for argument
On some targets such as LoongArch64 and RISCV64, the ABI requires
sign-extension for 32-bit integer arguments, so LLVM may emit the
`signext` attribute for the `%range` parameter. The existing CHECK
pattern required the argument to be exactly `i32 noundef %range`,
causing the test to fail on those targets.

Allow an optional `signext` attribute in the CHECK pattern so the test
passes consistently across architectures without affecting the intended
codegen validation.
2026-03-25 16:59:43 +08:00
Jonathan Brouwer 61b4c77781 Rollup merge of #154191 - pitaj:fix-154124, r=tgross35
refactor RangeFromIter overflow-checks impl

Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded

Fixes rust-lang/rust#154124

r? @tgross35
2026-03-23 12:00:59 +01:00
Jonathan Brouwer 8b69918e72 Rollup merge of #153069 - blueshift-gg:BPF_unaligned, r=chenyukang
[BPF] add target feature allows-misaligned-mem-access

This PR adds the allows-misaligned-mem-access target feature to the BPF target. The feature can enable misaligned memory access support in the LLVM backend, aligning Rust’s BPF target behavior with the corresponding LLVM update introduced in [llvm/llvm-project#167013](https://github.com/llvm/llvm-project/pull/167013) (included in LLVM 22).
2026-03-23 12:00:58 +01:00
Peter Jaszkowiak 8befc9d082 refactor RangeFromIter overflow-checks impl
Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded
2026-03-22 13:31:50 -06:00
Scott Young 9677d7a587 debuginfo: emit DW_TAG_call_site entries 2026-03-22 08:42:21 -04:00
Ralf Jung 986a280644 simd_fmin/fmax: make semantics and name consistent with scalar intrinsics 2026-03-18 15:17:56 +01:00
Alice Ryhl c679e3daf2 Simplify tests and fix test tidy issue 2026-03-17 20:24:05 +00:00
Alice Ryhl e41bbfaaa6 Explain why __hwasan_tls is present in LLVM codegen 2026-03-17 20:24:05 +00:00
Alice Ryhl a197752e88 Add kernel-hwaddress sanitizer
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2026-03-17 20:23:59 +00:00
Flakebi 8e932ed79c Use convergent attribute to funcs for GPU targets
On targets with convergent operations, we need to add the convergent
attribute to all functions that run convergent operations. Following
clang, we can conservatively apply the attribute to all functions when
compiling for such a target and rely on LLVM optimizing away the
attribute in cases where it is not necessary.

This affects the amdgpu and nvptx targets.
2026-03-17 10:51:31 +01:00