-
Notifications
You must be signed in to change notification settings - Fork 212
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
Ensure shift instrinsic arguments match width of compiler-rt's. #522
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by comment:
While this appears to follow the calling convention that LLVM uses, it does not follow the calling convention that avr-gcc uses: https://godbolt.org/z/azq4749hd
b
is only a single byte on avr-gcc.(I also see now that the C implementation in compiler-rt has the same bug, but only realized it now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AIUI, these code paths are skipped when compiling for
avr
, precisely because there's a pass which gets rid of these types of shifts in LLVM. So I made no accommodations for its nonstandard calling conventions in this PR.That being said, I don't know what a proper fix should look like that fixes
avr
,msp430
, andeverything-else
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, because I wrote that pass ;)
But it only works for 32-bit values.
__ashldi3
is a 64-bit shift function, which is emitted as a regular compiler-rt call. Proof: https://godbolt.org/z/zqWfE6ndqAnyway, it doesn't really matter as LLVM uses
i16
and noti8
like avr-gcc does. This PR would only be buggy for avr-gcc, right now it is safe with LLVM (but this could in theory change asi8
is more efficient).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minddump for future-me follows:
__ashldi3
'sb
argument is supposed to take anint
, which must be at least 16 bits. But indeed, your GCC code snippet is only sending a byte to__ashldi3
, while the LLVM version sends 16 bits (theclr r17
line is clearing the top-most bits).gcc
's docs also says__ashldi3
is supposed to return along
, and__ashlti3
is the function that is supposed to return along long
.compiler-rt
doesn't seem to support thet
versions of functions, and tends to hardcode a 64/32-bit int in places gcc's builtins do not1. In addition tocompiler-rt
usesunsigned
in args where gcc's builtins aresigned
.In other words, it seems like both
gcc
compiler-rt
builtins tend to do their own things and aren't directly compatible with each other.avr
using a byte in for thegcc
__ashldi3
b
arg, but 2 bytes forcompiler-rt
's__ashldi3
b
arg is just one example of this. It's not going to be fun :P. Unifyingcompiler-rt
's andgcc
's builtins in terms ofcompiler_builtins
might be necessary due to thegcc
backend though.b
args notwithstanding :P.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this not break for Rust code, where all the shift functions are skipped for AVR (
avr_skip
)?