Skip to content

Carry the b_offset inside BackendRepr::ScalarPair#158666

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
scottmcm:scalar-but-packed
Jul 9, 2026
Merged

Carry the b_offset inside BackendRepr::ScalarPair#158666
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
scottmcm:scalar-but-packed

Conversation

@scottmcm

@scottmcm scottmcm commented Jul 1, 2026

Copy link
Copy Markdown
Member

View all comments

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,

as oh my was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR. I tried to make it as direct a change as I could: if it was (..) before it's { .. } now, if it was (_, _) before it's { a: _, b: _, b_offset: _ } now. I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc. I'll add some inline notes for places of particular interest.

r? @workingjubilee

@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

This PR changes rustc_public

cc @oli-obk, @celinval, @ouz-a, @makai410

Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs

cc @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 1, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 1, 2026
@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

) => {
l1.primitive() == r1.primitive()
&& l2.primitive() == r2.primitive()
&& l_offset == r_offset

@scottmcm scottmcm Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: since this is an eq-like method, I also check that the offsets are the same here. (They always will be right now, but it makes sense to check it regardless IMHO.)

View changes since the review

abi::BackendRepr::ScalarPair { a: out_a, b: out_b, b_offset: out_offset },
) if in_a.size(cx) == out_a.size(cx)
&& in_b.size(cx) == out_b.size(cx)
&& in_offset == out_offset =>

@scottmcm scottmcm Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: when transmuting we only want to transmute the immediates individually when the second one is at the same offset in the source and destination.

(It'll probably be UB if they're not, but not necessarily since the out_b might allow uninit, so it's not worth trying to do something smart for those cases. They can fall through to the via-alloca implementation.)

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, so the code is now more correct also! neat.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was correct before as well because same scalars implied same offset, but it's clearer that it's correct now, and definitely more resiliently correct to subtle changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is any target where we have scalars of equal size but different alignment (u64 vs f64?), this was wrong before. But I agree the new code is right. :)

}
(
Immediate::ScalarPair(a_val, b_val),
BackendRepr::ScalarPair { a: _, b: _, b_offset },

@scottmcm scottmcm Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: by not needing to recompute the offset the two scalars actually ended up unused here.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

a1.size(&self.ecx) == a2.size(&self.ecx)
&& b1.size(&self.ecx) == b2.size(&self.ecx)
// The alignment of the second component determines its offset, so that also needs to match.
&& b1.default_align(&self.ecx) == b2.default_align(&self.ecx)

@scottmcm scottmcm Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: like the other spot this is thinking about transmutes, so now we can check the offset directly instead of indirectly via the default alignment.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat side effect!

@rust-log-analyzer

This comment has been minimized.

"`ScalarPair` second field at bad offset in {inner:#?}",
);
assert_eq!(
b_offset, field2_offset,

@scottmcm scottmcm Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: for this PR I kept all the existing checks here, since it's not actually changing any layouts. (That's wanting on the MCP FCP.) Just added this new one that the offset stored in the variant matches the expected field offset.

View changes since the review

@scottmcm scottmcm force-pushed the scalar-but-packed branch from 455c80c to ede96e9 Compare July 1, 2026 17:14
@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Jul 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some incantations to the PR since the code is now a bit short on them. :^)

a couple minor wording nitpicks, because you wrote r? workingjubilee and I'd hate to disappoint. I will give it another scan once you're done fighting CI and r+ then, but it seems good! my eyes have indeed confirmed "this sure is a lot of whitespace changes thanks to rustfmt".

oh, the callconv code does need a further scan, I'll get to that about then but I don't expect it to need any changes.

View changes since this review

Comment thread compiler/rustc_abi/src/lib.rs Outdated
Immediate::from(if offset.bytes() == 0 {
a_val
} else {
assert_eq!(offset, a.size(cx).align_to(b.default_align(cx).abi));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the shades of the Seraphim!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you found some of the more cursed code in the interpreter. ;)

But, this is not on my "needs a rewrite" list. It's all inherent complexity that I think exists for a good reason. But I may of course have missed a way to do this nicer.

Comment on lines +968 to -965
let BackendRepr::ScalarPair { a: _, b: _, b_offset } = dest.layout.backend_repr
else {
bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout);
};
let b_offset = a_scalar.size(bx).align_to(b_scalar.default_align(bx).abi);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the hoary hosts of Hoggoth!

assert_eq!(field.size, a.size(bx.cx()));
(Some(a), a_llval)
} else {
assert_eq!(offset, a.size(bx.cx()).align_to(b.default_align(bx.cx()).abi));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the crimson bands of Cyttorak!

a1.size(&self.ecx) == a2.size(&self.ecx)
&& b1.size(&self.ecx) == b2.size(&self.ecx)
// The alignment of the second component determines its offset, so that also needs to match.
&& b1.default_align(&self.ecx) == b2.default_align(&self.ecx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat side effect!

Comment on lines 398 to +401
BackendRepr::Scalar(scalar) => PassMode::Direct(scalar_attrs(scalar, Size::ZERO)),
BackendRepr::ScalarPair(a, b) => PassMode::Pair(
scalar_attrs(a, Size::ZERO),
scalar_attrs(b, a.size(cx).align_to(b.default_align(cx).abi)),
),
BackendRepr::ScalarPair { a, b, b_offset } => {
PassMode::Pair(scalar_attrs(a, Size::ZERO), scalar_attrs(b, b_offset))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chintap ...I need to look more closely at the surrounding code here because this is actually something that makes me wonder how correct it is.

Or was, for that matter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the maze of code this is entangled with. Yes, this version is correct, and will remain correct.

Comment thread compiler/rustc_const_eval/src/interpret/place.rs Outdated
abi::BackendRepr::ScalarPair { a: out_a, b: out_b, b_offset: out_offset },
) if in_a.size(cx) == out_a.size(cx)
&& in_b.size(cx) == out_b.size(cx)
&& in_offset == out_offset =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, so the code is now more correct also! neat.

Comment thread compiler/rustc_abi/src/lib.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@oli-obk

oli-obk commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 1, 2026
Carry the `b_offset` inside `BackendRepr::ScalarPair`
@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: e1ccfbf (e1ccfbf5eacfbdc172c8ed08bfba6e211f662bd7)
Base parent: e2b71ad (e2b71ade2db4ea263ab0d561d889f3e3795a500d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e1ccfbf): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary -6.9%, secondary -4.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-6.9% [-6.9%, -6.9%] 1
Improvements ✅
(secondary)
-4.3% [-8.8%, -2.1%] 4
All ❌✅ (primary) -6.9% [-6.9%, -6.9%] 1

Cycles

Results (primary -2.3%, secondary -3.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.3% [-2.8%, -2.0%] 3
Improvements ✅
(secondary)
-3.6% [-4.0%, -3.2%] 2
All ❌✅ (primary) -2.3% [-2.8%, -2.0%] 3

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.049s -> 485.092s (-1.01%)
Artifact size: 393.28 MiB -> 393.26 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 1, 2026
@RalfJung

RalfJung commented Jul 8, 2026

Copy link
Copy Markdown
Member

@bors r=workingjubilee

@rust-bors

rust-bors Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 47a510b has been approved by workingjubilee

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 8, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #150946 (intrinsics: Add a fallback for non-const libm float functions)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158951 (Merge three `MaxUniverse`s into one)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
…uwer

Rollup of 25 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #158968 (stdarch subtree update)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158912 (Introduce new bootstrap config section for PGO configuration)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #158307 (CI job for parallel frontend ui tests)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158741 (Simplify `Option::into_flat_iter` signature)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158883 (tests: fix enum-match.rs to handle LLVM 23)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 8, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
rust-bors Bot pushed a commit that referenced this pull request Jul 8, 2026
Rollup of 25 pull requests

Successful merges:

 - #158871 (add relnotes for 1.97.0)
 - #158968 (stdarch subtree update)
 - #157690 (codegen_ssa: pack small const aggregates into immediate stores)
 - #158541 (Move `std::io::Write` to `core::io`)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #156370 (Reject linked dylib EII default overrides)
 - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158617 (allow mGCA const arguments to fall back to anon consts)
 - #158645 (Fix splat ICEs and ban it in closures)
 - #158655 (Fix coroutine MIR saved local remapping)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #158307 (CI job for parallel frontend ui tests)
 - #158347 (Improve generic parameters handling for #[diagnostic::on_const])
 - #158722 (delegation: do not always inherit `ConstArgHasType` predicates)
 - #158741 (Simplify `Option::into_flat_iter` signature)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 9, 2026
…ingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
rust-bors Bot pushed a commit that referenced this pull request Jul 9, 2026
Rollup of 23 pull requests

Successful merges:

 - #158968 (stdarch subtree update)
 - #154445 (rustdoc: Represent `--output-format=json` coverage and ir differently)
 - #158495 (Rename HAS_CT_PROJECTION to HAS_CONST_ALIAS)
 - #158666 (Carry the `b_offset` inside `BackendRepr::ScalarPair`)
 - #158870 (std: merge the unix-like io::error modules into one file)
 - #158920 (Update wasm-component-ld to 0.5.26)
 - #158926 (wrapping_sh* methods: clarify underspecified reference)
 - #158927 (add core test run with `-Zforce-intrinsic-fallback`)
 - #158932 (Do not build the compiler when invoking `x perf compare`)
 - #158937 (Emit the emscripten entry point as `__main_argc_argv`)
 - #151379 (Stabilize `VecDeque::retain_back` from `truncate_front`)
 - #156144 (Better docs for PartialEq (includes macro rename))
 - #156548 ( Library support for aarch64-unknown-linux-pauthtest target)
 - #157995 (`Vec::dedup_by` docs explicit function argument order)
 - #158307 (CI job for parallel frontend ui tests)
 - #158741 (Simplify `Option::into_flat_iter` signature)
 - #158807 (Add regression test for CString::clone_into unwind safety)
 - #158862 (Fix the span for parameter suggestion )
 - #158894 (Make the ordering of non-terminal binds in ambiguity error messages deterministic)
 - #158902 (add codegen test for range length bound propagation)
 - #158913 (Update `browser-ui-test` version to `0.24.1`)
 - #158935 (std: support real fd methods on Emscripten)
 - #158978 (Add regression test for too-big by-value ABI args)
@rust-bors rust-bors Bot merged commit c688130 into rust-lang:main Jul 9, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 9, 2026
rust-timer added a commit that referenced this pull request Jul 9, 2026
Rollup merge of #158666 - scottmcm:scalar-but-packed, r=workingjubilee

Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by rust-lang/compiler-team#1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
@scottmcm scottmcm deleted the scalar-but-packed branch July 9, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants