Skip to content

Stop needing materialized places for most intrinsics#156116

Open
scottmcm wants to merge 2 commits intorust-lang:mainfrom
scottmcm:tweak-layout-of-alternative
Open

Stop needing materialized places for most intrinsics#156116
scottmcm wants to merge 2 commits intorust-lang:mainfrom
scottmcm:tweak-layout-of-alternative

Conversation

@scottmcm
Copy link
Copy Markdown
Member

@scottmcm scottmcm commented May 3, 2026

Today even to return a constant from size_of_val it takes an alloca. That's wasteful.

This updates the cg_ssa traits to allow returning an OperandValue instead, which is possible for the vast majority of intrinsics -- this PR moves all but 5 over to doing that in LLVM.

The first commit adds a test to help show the difference here.

cc rust-lang/compiler-team#970 #153250

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 3, 2026
@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from 0bc61de to a8a0062 Compare May 3, 2026 19:13
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from a8a0062 to 7a7f99b Compare May 3, 2026 19:23
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from 7a7f99b to 1f0a500 Compare May 3, 2026 19:51
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from 1f0a500 to 6eb4607 Compare May 3, 2026 19:59
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from 6eb4607 to e19fd5d Compare May 3, 2026 23:57
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from e19fd5d to 2f79728 Compare May 4, 2026 01:04
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the tweak-layout-of-alternative branch from 2f79728 to 10f00b6 Compare May 4, 2026 02:10
@scottmcm
Copy link
Copy Markdown
Member Author

scottmcm commented May 4, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 4, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 4, 2026
Stop needing materialized places for most intrinsics
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 4, 2026

☀️ Try build successful (CI)
Build commit: ce9f4cc (ce9f4cc0887ef1020c405689861eeb71f9095196, parent: 045b17737dab5fcc28e4cbee0cfe2ce4ed363b32)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (ce9f4cc): comparison URL.

Overall result: ✅ improvements - 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

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 1
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 2
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 1

Max RSS (memory usage)

Results (secondary -0.0%)

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)
2.7% [0.5%, 7.5%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.5% [-6.3%, -0.6%] 4
All ❌✅ (primary) - - 0

Cycles

Results (secondary -1.2%)

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.7% [0.6%, 0.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.9% [-5.7%, -0.4%] 5
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.1%, secondary -0.1%)

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)
-0.1% [-0.2%, -0.1%] 18
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.0%] 25
All ❌✅ (primary) -0.1% [-0.2%, -0.1%] 18

Bootstrap: 496.439s -> 493.878s (-0.52%)
Artifact size: 394.45 MiB -> 394.37 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 4, 2026
@scottmcm
Copy link
Copy Markdown
Member Author

scottmcm commented May 4, 2026

r? codegen

@scottmcm scottmcm marked this pull request as ready for review May 4, 2026 06:29
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 4, 2026

The GCC codegen subtree was changed

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 4, 2026
let func_ty = func.ty(&self.fx.mir.local_decls, tcx);
if let ty::FnDef(def_id, _args) = *func_ty.kind()
&& let Some(intrinsic) = tcx.intrinsic(def_id)
&& self.fx.cx.intrinsic_call_expects_place_always(intrinsic.name)
Copy link
Copy Markdown
Member Author

@scottmcm scottmcm May 4, 2026

Choose a reason for hiding this comment

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

annot: needing this check is unfortunate here, since we have to do it for all Calls. But perf says it doesn't cause a regression, so I think it's fine for now to keep this PR manageable, and we can hopefully remove it eventually with more updates to the backends.

(Worst come to worst the backends can make their own allocas for some intrinsics if really necessary. And extra typed copy on some intrinsics occasionally would be well worth it to get not making all the unnecessary ones on most of the intrinsics.)

View changes since the review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 5, 2026

☔ The latest upstream changes (presumably #156166) made this pull request unmergeable. Please resolve the merge conflicts.

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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants