Skip to content

Add an optional llvm = argument to rustc_intrinsic. - #164544

Open
veluca93 wants to merge 1 commit into
rust-lang:mainfrom
veluca93:rustc_llvm_intrinsic
Open

veluca93 wants to merge 1 commit into
rust-lang:mainfrom
veluca93:rustc_llvm_intrinsic

Conversation

@veluca93

@veluca93 veluca93 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This is meant for usage in core::arch, to define the platform-specific LLVM intrinsics that correspond to each intrinsic.

LLM usage: I used an LLM to point me at places in the code from which to start the implementation, but I did not generate any code. The main non-trivial input from the LLM was to prevent inlining of callees annotated with rustc_llvm_intrinsic. Code has been since re-designed following @bjorn3's and @RalfJung's proposals so there's no trace of any LLM input left :-)

r? RalfJ

@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Oct 18, 2026
@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Error: Failed to set assignee to RalfJ: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@veluca93

Copy link
Copy Markdown
Contributor Author

r? RalfJung

@rustbot

rustbot commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@tgross35

Copy link
Copy Markdown
Member

Cc @folkertdev

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from 39047e6 to a0ad71b Compare October 19, 2026 07:09
@bjorn3

bjorn3 commented Oct 19, 2026

Copy link
Copy Markdown
Member

Can you check that all places in the compiler that check for extern "llvm-intrinsic" have been adjusted as appropriate?

@veluca93

Copy link
Copy Markdown
Contributor Author

Can you check that all places in the compiler that check for extern "llvm-intrinsic" have been adjusted as appropriate?

I gave a look, and I think so, but I am definitely not knowledgeable enough of compiler internals to be sure.

@veluca93
veluca93 marked this pull request as draft October 23, 2026 15:39
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2026
@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch 2 times, most recently from ebce41f to 90416b5 Compare October 28, 2026 12:15
@veluca93
veluca93 marked this pull request as ready for review October 28, 2026 12:15
@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

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

Some changes occurred to constck

cc @fee1-dead

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

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

cc @bjorn3

@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 Oct 28, 2026
@rust-log-analyzer

This comment has been minimized.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from 90416b5 to c906c98 Compare October 28, 2026 19:45
@rustbot

rustbot commented Oct 28, 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 Oct 28, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2026
@rustbot

rustbot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from e294fce to e18a91c Compare November 6, 2026 10:17
@veluca93

veluca93 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@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 Nov 6, 2026
@rust-log-analyzer

This comment has been minimized.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from e18a91c to f28292b Compare November 6, 2026 10:26
@rust-log-analyzer

This comment has been minimized.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from f28292b to 40c3e33 Compare November 6, 2026 10:35
Comment on lines +5 to +13
#[rustc_intrinsic(llvm = "llvm.fshl.i64")]
fn fshl(a: i64, b: i64, sh: i64) -> i64 {
(((a as i128) << 64) | (b as i128) >> sh) as i64
}

fn main() {
const { fshl(1, 2, 3) };
//~^ ERROR: cannot call non-const function `fshl` in constants [E0015]
}

@RalfJung RalfJung Nov 6, 2026 •

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.

Not sure if this is worth a test, it's just standard const checking. Would be very surprising if we allowed calling a function that's not marked as const.

More interesting is ensuring that const stability checks work properly. You could extend tests/ui/consts/const-unstable-intrinsic.rs to also check backend intrinsics.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, and added more tests to the other file.

@RalfJung

RalfJung commented Nov 6, 2026

Copy link
Copy Markdown
Member

Btw the PR title and description seem to still refer to an earlier version of this PR.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from 40c3e33 to 62cfa98 Compare November 6, 2026 14:34
@rustbot

rustbot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@veluca93 veluca93 changed the title Add a rustc_llvm_intrinsic attribute. Add an optional llvm = argument to rustc_intrinsic. Nov 6, 2026
@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from 62cfa98 to e6d0471 Compare November 6, 2026 15:06
Comment thread compiler/rustc_middle/src/ty/layout.rs Resolved
Comment thread compiler/rustc_codegen_gcc/src/lib.rs Resolved
@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from e6d0471 to 7281468 Compare November 7, 2026 13:21
@rust-log-analyzer

This comment has been minimized.

@veluca93
veluca93 force-pushed the rustc_llvm_intrinsic branch from 7281468 to f6b41d9 Compare November 7, 2026 15:20
@rust-bors

rust-bors Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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-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