Skip to content

powerpc: warn against incorrect values for ABI-relevant target features#157085

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
RalfJung:powerpc-abi-features
Jun 3, 2026
Merged

powerpc: warn against incorrect values for ABI-relevant target features#157085
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
RalfJung:powerpc-abi-features

Conversation

@RalfJung
Copy link
Copy Markdown
Member

@RalfJung RalfJung commented May 28, 2026

View all comments

This fills in #131799 for PowerPC. Based on this comment by @beetrees, the relevant target features are "hard-float" and "spe". I confirmed this by looking at the LLVM sources:

  // Set up the register classes.
  addRegisterClass(MVT::i32, &PPC::GPRCRegClass);
  if (!useSoftFloat()) {
    if (hasSPE()) {
      addRegisterClass(MVT::f32, &PPC::GPRCRegClass);
      // EFPU2 APU only supports f32
      if (!Subtarget.hasEFPU2())
        addRegisterClass(MVT::f64, &PPC::SPERCRegClass);
    } else {
      addRegisterClass(MVT::f32, &PPC::F4RCRegClass);
      addRegisterClass(MVT::f64, &PPC::F8RCRegClass);
    }
  }

(this is in llvm/lib/Target/PowerPC/PPCISelLowering.cpp)

So, we make rustc emit a warning indicating the ABI compatibility issues if "spe" or hard-float" gets toggled. The plan is to eventually make this a hard error.

I also found this code there, in the handling for "altivec", that look like they are enabling more registers to be used for the ABI, but maybe I am missing a subtle difference in these addRegisterClass calls:

      if (Subtarget.hasP8Vector())
        addRegisterClass(MVT::f32, &PPC::VSSRCRegClass);

      addRegisterClass(MVT::f64, &PPC::VSFRCRegClass);

      addRegisterClass(MVT::v4i32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v4f32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v2f64, &PPC::VSRCRegClass);

Cc @nikic for help with interpreting this LLVM code.

Cc @Gelbpunkt @famfo @neuschaefer as maintainers of affected targets

@rustbot rustbot added 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 May 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 28, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@RalfJung RalfJung changed the title powerpc: warn against correct values for ABI-relevant target features powerpc: warn against incorrect values for ABI-relevant target features May 28, 2026
@RalfJung RalfJung force-pushed the powerpc-abi-features branch from c2a0a73 to 5025c08 Compare May 28, 2026 22:02
@Gelbpunkt
Copy link
Copy Markdown
Contributor

So, we make rustc emit a warning indicating the ABI compatibility issues if "spe" or hard-float" gets toggled. The plan is to eventually make this a hard error.

This is correct to my knowledge, the SPE instructions perform float-point math on the integer registers.

However I'm wondering whether this change will break the SPE targets since to my understanding this enforces hard-float to be enabled and spe to not be enabled for any of the 32-bit PowerPC targets, which includes the existing SPE targets?

@Gelbpunkt
Copy link
Copy Markdown
Contributor

Oh, well, now that I'm looking at the SPE target definitions, they don't even seem to enable SPE in LLVM, so they're probably already broken as-is

@RalfJung
Copy link
Copy Markdown
Member Author

Oh I didn't realize we have SPE targets.

But yeah, looking at those targets... they set -mspe for the linker, but they don't seem to tell LLVM that this should be using SPE? How dos that make any sense? Does LLVM use the target string to figure out the ABI? From the LLVM code, it doesn't look like it.
Cc @BKPepe @biabbas @hax0kartik (you are listed as maintainers for SPE targets)

@RalfJung
Copy link
Copy Markdown
Member Author

This is correct to my knowledge, the SPE instructions perform float-point math on the integer registers.

That wouldn't matter for the ABI. But I guess they will then also use integer registers for passing float arguments / return values, and that makes them ABI-incompatible with non-SPE targets?

@RalfJung RalfJung force-pushed the powerpc-abi-features branch from 5025c08 to a72f0b0 Compare May 29, 2026 07:08
@Gelbpunkt
Copy link
Copy Markdown
Contributor

That wouldn't matter for the ABI. But I guess they will then also use integer registers for passing float arguments / return values, and that makes them ABI-incompatible with non-SPE targets?

Yes, sorry for not being clear on that in my previous reply.

@Gelbpunkt
Copy link
Copy Markdown
Contributor

Gelbpunkt commented May 29, 2026

See also https://www.nxp.com/docs/en/reference-manual/E500ABIUG.pdf

The following algorithm specifies where argument data is passed for the C language [...]

SIMPLE_ARG: A SIMPLE_ARG is one of the following:
— One of the simple integer types no more than 32 bits wide (char, short, int, long, enum)
— A single-precision float
— A pointer to an object of any type
— A struct, union, or long double, any of which shall be treated as a pointer to the
object, or to a copy of the object where necessary to enforce call-by-value
semantics. Only if the caller can ascertain that the object is constant can it pass
a pointer to the object itself.
If gr>10, go to OTHER. Otherwise, load the argument value into general register gr,
set gr to gr+1, and go to SCAN. Values shorter than 32 bits are sign-extended or
zero-extended, depending on whether they are signed or unsigned.

64-bit floats are passed in 2 GPRs.

@rust-log-analyzer

This comment has been minimized.

@chenyukang
Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned mu001999 and unassigned chenyukang May 29, 2026
@mu001999
Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned petrochenkov and unassigned mu001999 May 29, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

Waiting for the pinged people to respond (for 1-2 weeks max, I guess).
@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2026
@hax0kartik
Copy link
Copy Markdown
Contributor

hax0kartik commented May 29, 2026

Oh I didn't realize we have SPE targets.

But yeah, looking at those targets... they set -mspe for the linker, but they don't seem to tell LLVM that this should be using SPE? How dos that make any sense? Does LLVM use the target string to figure out the ABI? From the LLVM code, it doesn't look like it. Cc @BKPepe @biabbas @hax0kartik (you are listed as maintainers for SPE targets)

Atleast, for vxWorks, I can confirm that this is an error in the spec file. It needs to pass a -mspe / -mcpu flag(-mcpu=8548) to llvm to have it generate the spe instructions. Thanks for pointing this out.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented May 29, 2026

So, this target is more than 6 years old, and it never actually generated correct machine code...?

Clearly we can just remove it then as it cannot have any users? Or am I missing something? Does normal non-SPE code mostly work on SPE hardware and that's why nobody noticed?

@hax0kartik
Copy link
Copy Markdown
Contributor

hax0kartik commented May 30, 2026

So, this target is more than 6 years old, and it never actually generated correct machine code...?

Clearly we can just remove it then as it cannot have any users? Or am I missing something? Does normal non-SPE code mostly work on SPE hardware and that's why nobody noticed?

I believe we do not have any customer currently who uses rust for ppc arch and that too for SPE. Nonetheless, we would still like to keep support for this. I must agree that the target hasn’t been well tested, if tested at all.

Normal ppc float instructions do not work on spe.

Pl give 1-2 days to work on a fix for this. Thanks.

@taiki-e
Copy link
Copy Markdown
Member

taiki-e commented May 30, 2026

While users of spe targets do exist (as of at least a year ago), in practice they always use -C target-cpu, so they rarely encounter this kind of problem.

I previously worked on getting these targets to work without -C target-cpu (even though I'm not an actual user), but I haven't had much time lately and only created a patch for the spe feature issue (taiki-e@8185fbc), without submitting it (UPDATE: submitted #157137).

@RalfJung
Copy link
Copy Markdown
Member Author

@taiki-e so there are -Ctarget-cpu values that imply spe?

@RalfJung RalfJung force-pushed the powerpc-abi-features branch from cd4b12d to 751237a Compare May 30, 2026 08:59
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the powerpc-abi-features branch from 751237a to af52abf Compare May 30, 2026 10:03
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 2, 2026
rustc_target: Use +spe for powerpcspe targets

LLVM does not infer this from the target name and `abi: "spe"` is just for cfg.  To actually generate the correct instructions for these targets (without `-C target-cpu`), we need to pass `+spe` to LLVM.

Fixes rust-lang#138960
See also rust-lang#157085
Related rust-lang#137860

cc @RalfJung
cc @BKPepe ([powerpc-unknown-linux-muslspe target maintainer](https://doc.rust-lang.org/nightly/rustc/platform-support/powerpc-unknown-linux-muslspe.html#target-maintainers))
cc @glaubitz (who added powerpc-unknown-linux-gnuspe in rust-lang#48484)
cc @biabbas @hax0kartik ([*-wrs-vxworks target maintainers](https://doc.rust-lang.org/nightly/rustc/platform-support/vxworks.html#target-maintainers))

@rustbot label +O-PowerPC +A-target-feature
rust-timer added a commit that referenced this pull request Jun 2, 2026
Rollup merge of #157137 - taiki-e:powerpcspe, r=RalfJung

rustc_target: Use +spe for powerpcspe targets

LLVM does not infer this from the target name and `abi: "spe"` is just for cfg.  To actually generate the correct instructions for these targets (without `-C target-cpu`), we need to pass `+spe` to LLVM.

Fixes #138960
See also #157085
Related #137860

cc @RalfJung
cc @BKPepe ([powerpc-unknown-linux-muslspe target maintainer](https://doc.rust-lang.org/nightly/rustc/platform-support/powerpc-unknown-linux-muslspe.html#target-maintainers))
cc @glaubitz (who added powerpc-unknown-linux-gnuspe in #48484)
cc @biabbas @hax0kartik ([*-wrs-vxworks target maintainers](https://doc.rust-lang.org/nightly/rustc/platform-support/vxworks.html#target-maintainers))

@rustbot label +O-PowerPC +A-target-feature
@RalfJung RalfJung force-pushed the powerpc-abi-features branch from af52abf to 7c12835 Compare June 3, 2026 06:16
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 3, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the powerpc-abi-features branch from 7c12835 to f57a122 Compare June 3, 2026 15:04
Comment thread compiler/rustc_target/src/target_features.rs Outdated
@RalfJung RalfJung force-pushed the powerpc-abi-features branch from f57a122 to 591d5da Compare June 3, 2026 15:30
@RalfJung RalfJung removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jun 3, 2026
@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Jun 3, 2026

This should be ready then. :)
@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 3, 2026
@petrochenkov
Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 3, 2026

📌 Commit 591d5da has been approved by petrochenkov

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 5. This pull request will be tested once the tree is reopened.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 3, 2026
…etrochenkov

powerpc: warn against incorrect values for ABI-relevant target features

This fills in rust-lang#131799 for PowerPC. Based on [this comment](rust-lang#131799 (comment)) by @beetrees, the relevant target features are "hard-float" and "spe". I confirmed this by looking at the LLVM sources:
```
  // Set up the register classes.
  addRegisterClass(MVT::i32, &PPC::GPRCRegClass);
  if (!useSoftFloat()) {
    if (hasSPE()) {
      addRegisterClass(MVT::f32, &PPC::GPRCRegClass);
      // EFPU2 APU only supports f32
      if (!Subtarget.hasEFPU2())
        addRegisterClass(MVT::f64, &PPC::SPERCRegClass);
    } else {
      addRegisterClass(MVT::f32, &PPC::F4RCRegClass);
      addRegisterClass(MVT::f64, &PPC::F8RCRegClass);
    }
  }
```
(this is in `llvm/lib/Target/PowerPC/PPCISelLowering.cpp`)

So, we make rustc emit a warning indicating the ABI compatibility issues if "spe" or hard-float" gets toggled. The plan is to eventually make this a hard error.

I also found this code there, in the handling for "altivec", that look like they are enabling more registers to be used for the ABI, but maybe I am missing a subtle difference in these `addRegisterClass` calls:
```
      if (Subtarget.hasP8Vector())
        addRegisterClass(MVT::f32, &PPC::VSSRCRegClass);

      addRegisterClass(MVT::f64, &PPC::VSFRCRegClass);

      addRegisterClass(MVT::v4i32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v4f32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v2f64, &PPC::VSRCRegClass);
```
Cc @nikic for help with interpreting this LLVM code.

Cc @Gelbpunkt @famfo @neuschaefer as maintainers of affected targets
rust-bors Bot pushed a commit that referenced this pull request Jun 3, 2026
Rollup of 12 pull requests

Successful merges:

 - #157085 (powerpc: warn against incorrect values for ABI-relevant target features)
 - #157170 (Use `impl` restrictions in `std`, `core`)
 - #157217 ([tiny] remove unecessary `.into()` calls)
 - #157262 (rustdoc: IXCRE: Preserve sizedness bounds on type params belonging to the parent item)
 - #157379 (Some more simple per-owner resolver changes)
 - #157381 (librustdoc: fix CSS border issue to support Firefox high contrast mode)
 - #155512 (interpreter: improve comments and error message in mir_assign_valid_types)
 - #157254 (Correct description of panic.rs)
 - #157290 (interpret: fix mir::UnOp layout computation)
 - #157332 (Rewrite target checking for `#[sanitize]`)
 - #157351 (Avoid leaking the query-job collection warning into the panic query stack)
 - #157389 (Add @clarfonthey to libs review rotation)
@rust-bors rust-bors Bot merged commit ca881ba into rust-lang:main Jun 3, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 3, 2026
rust-timer added a commit that referenced this pull request Jun 3, 2026
Rollup merge of #157085 - RalfJung:powerpc-abi-features, r=petrochenkov

powerpc: warn against incorrect values for ABI-relevant target features

This fills in #131799 for PowerPC. Based on [this comment](#131799 (comment)) by @beetrees, the relevant target features are "hard-float" and "spe". I confirmed this by looking at the LLVM sources:
```
  // Set up the register classes.
  addRegisterClass(MVT::i32, &PPC::GPRCRegClass);
  if (!useSoftFloat()) {
    if (hasSPE()) {
      addRegisterClass(MVT::f32, &PPC::GPRCRegClass);
      // EFPU2 APU only supports f32
      if (!Subtarget.hasEFPU2())
        addRegisterClass(MVT::f64, &PPC::SPERCRegClass);
    } else {
      addRegisterClass(MVT::f32, &PPC::F4RCRegClass);
      addRegisterClass(MVT::f64, &PPC::F8RCRegClass);
    }
  }
```
(this is in `llvm/lib/Target/PowerPC/PPCISelLowering.cpp`)

So, we make rustc emit a warning indicating the ABI compatibility issues if "spe" or hard-float" gets toggled. The plan is to eventually make this a hard error.

I also found this code there, in the handling for "altivec", that look like they are enabling more registers to be used for the ABI, but maybe I am missing a subtle difference in these `addRegisterClass` calls:
```
      if (Subtarget.hasP8Vector())
        addRegisterClass(MVT::f32, &PPC::VSSRCRegClass);

      addRegisterClass(MVT::f64, &PPC::VSFRCRegClass);

      addRegisterClass(MVT::v4i32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v4f32, &PPC::VSRCRegClass);
      addRegisterClass(MVT::v2f64, &PPC::VSRCRegClass);
```
Cc @nikic for help with interpreting this LLVM code.

Cc @Gelbpunkt @famfo @neuschaefer as maintainers of affected targets
@RalfJung RalfJung deleted the powerpc-abi-features branch June 4, 2026 07:41
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jun 4, 2026
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#157085 (powerpc: warn against incorrect values for ABI-relevant target features)
 - rust-lang/rust#157170 (Use `impl` restrictions in `std`, `core`)
 - rust-lang/rust#157217 ([tiny] remove unecessary `.into()` calls)
 - rust-lang/rust#157262 (rustdoc: IXCRE: Preserve sizedness bounds on type params belonging to the parent item)
 - rust-lang/rust#157379 (Some more simple per-owner resolver changes)
 - rust-lang/rust#157381 (librustdoc: fix CSS border issue to support Firefox high contrast mode)
 - rust-lang/rust#155512 (interpreter: improve comments and error message in mir_assign_valid_types)
 - rust-lang/rust#157254 (Correct description of panic.rs)
 - rust-lang/rust#157290 (interpret: fix mir::UnOp layout computation)
 - rust-lang/rust#157332 (Rewrite target checking for `#[sanitize]`)
 - rust-lang/rust#157351 (Avoid leaking the query-job collection warning into the panic query stack)
 - rust-lang/rust#157389 (Add @clarfonthey to libs review rotation)
pull Bot pushed a commit to xtqqczze/rust-lang-rustc-dev-guide that referenced this pull request Jun 4, 2026
rustc_target: Use +spe for powerpcspe targets

LLVM does not infer this from the target name and `abi: "spe"` is just for cfg.  To actually generate the correct instructions for these targets (without `-C target-cpu`), we need to pass `+spe` to LLVM.

Fixes rust-lang/rust#138960
See also rust-lang/rust#157085
Related rust-lang/rust#137860

cc @RalfJung
cc @BKPepe ([powerpc-unknown-linux-muslspe target maintainer](https://doc.rust-lang.org/nightly/rustc/platform-support/powerpc-unknown-linux-muslspe.html#target-maintainers))
cc @glaubitz (who added powerpc-unknown-linux-gnuspe in rust-lang/rust#48484)
cc @biabbas @hax0kartik ([*-wrs-vxworks target maintainers](https://doc.rust-lang.org/nightly/rustc/platform-support/vxworks.html#target-maintainers))

@rustbot label +O-PowerPC +A-target-feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

9 participants