-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Illegal instructions generated for Arm Cortex-R5 processor when compiling code using floating-point operations #128448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As mentioned on the thread, this seems to come from LLVM. Would you mind filing an issue there? Here is an llc reproduction that shows |
Whoops, didn't mean to remove prioritize but I think the labels raced. |
cc @chrisnc as the maintainer for this target. We updated the float support in #123159 to be more-correct for this target but it looks like we didn't quite stick the landing I guess?
We most definitely intentionally included the R5 here, though apparently we assume an R5F. |
LLVM's policy for Arm |
https://godbolt.org/z/cj38s8Ev6 This will also disable the floating-point support. I think the issue is that the implied |
Thanks a lot @chrisnc for investigating this issue!
Yes, right now that seems the clearest approach. There's the downside that Or should the non-
Should I still go ahead and file an issue with LLVM as suggested initially by @tgross35? One source of confusion for me is that LLVM seems to distinguish between Cortex-R4 and Cortex-R4F, but not between Cortex-R5 and Cortex-R5F. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
I don't think there's a way to disable this right now except to use nightly. I can't find an open issue for stabilizing these right now, but that is the path. This warning is relatively recent, and this issue gives some explanation of why it's there: #117616.
The
I think that would be worthwhile, at least to understand why there is a separate |
We should probably just add this feature. |
@chrisnc For note, LLVM seems to have flipflopped on the maximal vs. minimal thing for Arm CPUs at least twice now, and recent Arm CPUs (aarch64, mostly) are more likely to use a minimal featureset, though that may only be true from Armv9 onwards. |
Whoops, I missed that this was also unknown, not just unstable, when I wrote my comment. I'm not sure this will be possible though, because it affects the ABI, and the reasoning here applies to Arm also. Should
Interesting... At least for the v7m, v7r, v8m, and v8r cores, the default feature sets have all been maximal when each core was added and then not changed except for refactoring and bug fixes from what I can see, but A-profile and Aarch64 are quite a bit more varied and may have different considerations. It seems that R4 as distinct from R4F was done originally in GCC in 2008 and then LLVM followed it, but no other exceptions exist, even though "M4F" and "R5F" and others are commonly mentioned when a non-trivial population of them are |
Just saw this and wanted to note that it's documented for the M-Profile Arm targets in some detail in the Platform Docs. Might be worth updating the R-Profile target docs in the same manner. I don't think it's a bug in LLVM, just a policy decision. The solution is to identify, and then stablise, the features that turn off the undesired instructions. Or to not specify 'target-cpu' and rely on the baseline architecture support, which is probably fine in many cases. |
I've refrained from doing this because I don't think it's the right path long term. Editing feature lists is not something that LLVM expects frontend users to do (e.g., it is not |
I agree that that's a better solution, but I didn't like the previous state of "just can't be done". |
I think a better recommendation in the current state of affairs is to provide a custom target json with the features you want. This has the benefit of not emitting warnings at build time, and also avoids any mismatch between the features/ABI that |
Sure, but that requires using the nightly toolchain. I think the ABI incompatibility issues are being addressed - AIUI flags that change the ABI will get special treatment (or be rejected). And none of the ones I suggest in the docs do so - to the best of my knowledge. |
The specific combinations in the docs are okay as of now, but the general practice of using |
If you use it with a hard-float target, it would definitely be bad. But the platform docs only say to use it with a soft-float EABI target, and only when you've selected a target-cpu that turns on FPU support by default. Looking at the code that comes out of |
Already acknowledged that "the specific combinations in the docs are okay as of now", but the point is just that there is very little to protect you if you stray from that even slightly, so I'm worried about users reading these docs and coming away with the impression that fiddling with feature lists of the built-in targets is a stable and well-supported way to specify a compilation target in general, when it's not.
|
When targeting the Arm Cortex-R5 processor, rustc and llvm generate assembly containing floating-point instructions. These are not available on the Cortex-R5 (only on the Cortex-R5F) and cause the processor to halt.
Details
For example, the following code:
compiled with flags
--target armv7r-none-eabi -C opt-level=3 -C target-cpu=cortex-r5
generates the assembly (compiler explorer link):Note the
vadd.f32
andvadd.f64
instructions, that are available on the Cortex-R5F which has an FPU, but that are illegal instructions on the Cortex-R5 without an FPU.My expectation is that, using the target
armv7r-none-eabi
(rather thanarmv7r-none-eabihf
) and the target CPUcortex-r5
(rather thancortex-r5f
), rustc and llvm would generate legal instructions for the processor, i.e. use software floating-point features rather than hard-float instructions.Relevant information
Original thread on URLO: Unexpected codegen for Cortex-R5 without FPU.
The upstream LLVM CPU model for cortex-r5 includes the flag FeatureVFP3_D16, which seems OK for the R5F but wrong for the R5. However, manually disabling that feature doesn't seem to help (see below). Link to llvm repo at tag 18.1.7.
Information from the ARM Cortex-R Series Programmer's Guide: 6.1.6. VFP in the Cortex-R processors.
Things that do work
Skipping the target-cpu flag
Compiling the snippet above with flags
--target armv7r-none-eabi -C opt-level=3
generates:Adding the soft-float target feature
Compiling the snippet above with flags
--target armv7r-none-eabi -C opt-level=3 -C target-cpu=cortex-r5 -C target-feature=+soft-float
generates:However, rustc generates the warning:
Things that don't work
Removing the vfp3d16 target feature
Compiling the snippet above with flags
--target armv7r-none-eabi -C opt-level=3 -C target-cpu=cortex-r5 -C target-feature=-vfp3d16
generates:Meta
I've tested both stable and nightly toolchains, with same results.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: