powerpc: warn against incorrect values for ABI-relevant target features#157085
Conversation
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
c2a0a73 to
5025c08
Compare
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 |
|
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 |
|
Oh I didn't realize we have SPE targets. But yeah, looking at those targets... they set |
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? |
5025c08 to
a72f0b0
Compare
Yes, sorry for not being clear on that in my previous reply. |
|
See also https://www.nxp.com/docs/en/reference-manual/E500ABIUG.pdf
64-bit floats are passed in 2 GPRs. |
This comment has been minimized.
This comment has been minimized.
|
@rustbot reroll |
|
@rustbot reroll |
|
Waiting for the pinged people to respond (for 1-2 weeks max, I guess). |
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. |
|
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. |
|
While users of spe targets do exist (as of at least a year ago), in practice they always use I previously worked on getting these targets to work without |
|
@taiki-e so there are |
cd4b12d to
751237a
Compare
This comment has been minimized.
This comment has been minimized.
751237a to
af52abf
Compare
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
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
af52abf to
7c12835
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
7c12835 to
f57a122
Compare
f57a122 to
591d5da
Compare
|
This should be ready then. :) |
|
@bors r+ |
…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
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)
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
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)
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
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:
(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
addRegisterClasscalls:Cc @nikic for help with interpreting this LLVM code.
Cc @Gelbpunkt @famfo @neuschaefer as maintainers of affected targets