diff options
| author | bors <bors@rust-lang.org> | 2025-07-05 01:37:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-05 01:37:08 +0000 |
| commit | 733b47ea4b1b86216f14ef56e49440c33933f230 (patch) | |
| tree | 17ee40b79aa3e3da70bb9d3a97ed3338585ee1ef /compiler/rustc_transmute/src/layout/tree.rs | |
| parent | d98a5da813da67eb189387b8ccfb73cf481275d8 (diff) | |
| parent | d020e38fa229d184026ac9b1a7ea73b9f99e8e7a (diff) | |
| download | rust-733b47ea4b1b86216f14ef56e49440c33933f230.tar.gz rust-733b47ea4b1b86216f14ef56e49440c33933f230.zip | |
Auto merge of #138759 - scottmcm:operand-builder, r=saethlin
Allow `enum` and `union` literals to also create SSA values
Today, `Some(x)` always goes through an `alloca`, even in trivial cases where the niching means the constructor doesn't even change the value.
For example, <https://rust.godbolt.org/z/6KG6PqoYz>
```rust
pub fn demo(r: &i32) -> Option<&i32> {
Some(r)
}
```
currently emits the IR
```llvm
define align 4 ptr `@demo(ptr` align 4 %r) unnamed_addr {
start:
%_0 = alloca [8 x i8], align 8
store ptr %r, ptr %_0, align 8
%0 = load ptr, ptr %_0, align 8
ret ptr %0
}
```
but with this PR it becomes just
```llvm
define align 4 ptr `@demo(ptr` align 4 %r) unnamed_addr {
start:
ret ptr %r
}
```
(Of course the optimizer can clean that up, but it'd be nice if it didn't have to -- especially in debug where it doesn't run. This is like rust-lang/rust#123886, but that only handled non-simd `struct`s -- this PR generalizes it to all non-simd ADTs.)
Doing this means handing variants other than `FIRST_VARIANT`, handling the active field for unions, refactoring the discriminant code so the Place and Operand parts can share the calculation, etc.
Other PRs that led up to this one:
- https://github.com/rust-lang/rust/pull/142005
- https://github.com/rust-lang/rust/pull/142103
- https://github.com/rust-lang/rust/pull/142324
- https://github.com/rust-lang/rust/pull/142383
---
try-job: aarch64-gnu
Diffstat (limited to 'compiler/rustc_transmute/src/layout/tree.rs')
0 files changed, 0 insertions, 0 deletions
