-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[NFC] Add useFPRegsForHalfType(). #74147
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
Conversation
An example of how this can be used, which I plan to submit after this: hvdijk@softpromotehalf-fpreg-arm |
You need to update all the "SoftPromoteHalf..." functions in |
Could you elaborate a bit on this? During testing with the aforementioned hvdijk@softpromotehalf-fpreg-arm, things seemed to work. Are you imagining anything in particular that doesn't work? |
There are a handful of functions there that assume |
Ah, thank you, I see what you mean and what's going wrong. What you say shouldn't be an issue directly, but you are right that this PR is incorrect. Inside functions, I continue to use Edit: Actually... Isn't that already what happens on current LLVM too? In which case, isn't that what should continue to happen? |
Are you trying to only apply this promotion to function arguments and return values? If so, then it should be entirely done in handling a calling convention. This PR changes type legalization which will apply to all values of type |
Kind of. I'm only trying to use |
There are extra complications because The bigger issue is that legalising to I'll have another look at your "You need to update all the "SoftPromoteHalf..." functions" comment and see if I can find a test case that shows something that needs updating. |
So, revisiting this... The |
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.
That sounds reasonable.
// the size matters. | ||
// Return true if the half type should be promoted using soft promotion rules | ||
// where each operation is promoted to f32 individually, then converted to | ||
// fp16. The default behavior is to promote links of operations, keeping |
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.
Do you mean "chains of operations"?
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.
Yes, thank you. I struggled to find the right wording, managed to remember to update it in the commit message and MR description, but forgot to also update the comment. Fixed.
virtual bool softPromoteHalfType() const { return false; } | ||
|
||
// Return true if, for soft-promoted half, the half type should be passed | ||
// around as f32. The default behavior is to pass around as i16. If |
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.
Maybe instead of "should be passed around" have "should be passed in function calls". Does this apply to return values as well?
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.
It does, and agreed that that would be clearer. Updated to say "passed to and returned from functions".
Currently, half operations can be promoted in one of two ways. * If softPromoteHalfType() returns false, fp16 values are passed to and returned from functions in fp32 registers, and whole chains of fp16 operations are promoted to fp32 in one go. * If softPromoteHalfType() returns true, fp16 values are passed to and returned from functions in i16 registers, and individual fp16 operations are promoted to fp32 and the result truncated to fp16 right away. The softPromoteHalfType behavior is necessary for correctness, but changing this for an existing target breaks the ABI. Therefore, this commit adds a third option: * If softPromoteHalfType() returns true and useFPRegsForHalfType() returns true as well, fp16 values are passed to and returned from functions in fp32 registers, but individual fp16 operations are promoted to fp32 and the result truncated to fp16 right away. This change does not yet update any target to make use of it.
6b65afa
to
07916dc
Compare
In my previous comment, when I wrote I have gone over all the I have updated both this and my |
ping. We had a path forwards and it turned out that LLVM already did exactly what that path forwards entailed so it required no further changes beyond what was already in the PR, but then it was silent again. We've now probably missed the opportunity to get this fixed in LLVM 18, with the release branch already being created. Can I do anything to speed this along so we can get this into LLVM 19, at least? |
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.
LGTM
Are you planning to have another PR with changes to targets? It's not yet too late to get it in 18.1.0. |
Thanks!
I have the commit for ARM ready to create a PR as soon as I confirm no new tests need updating, will create that later today. I would be very happy if that can get into 18.1.0. |
There is a process for cherry-picking fixes into release branches. I don't remember exactly what it is though... |
Follow-up: #80440. If that is approved and merged, I think I'll just create an issue and ask Tom Stellard's opinion on cherry-picking. |
Currently, half operations can be promoted in one of two ways. * If softPromoteHalfType() returns false, fp16 values are passed around in fp32 registers, and whole chains of fp16 operations are promoted to fp32 in one go. * If softPromoteHalfType() returns true, fp16 values are passed around in i16 registers, and individual fp16 operations are promoted to fp32 and the result truncated to fp16 right away. The softPromoteHalfType behavior is necessary for correctness, but changing this for an existing target breaks the ABI. Therefore, this commit adds a third option: * If softPromoteHalfType() returns true and useFPRegsForHalfType() returns true as well, fp16 values are passed around in fp32 registers, but individual fp16 operations are promoted to fp32 and the result truncated to fp16 right away. This change does not yet update any target to make use of it.
Currently, half operations can be promoted in one of two ways.
The softPromoteHalfType behavior is necessary for correctness, but changing this for an existing target breaks the ABI. Therefore, this commit adds a third option:
This change does not yet update any target to make use of it.