-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[RISCV] Inline Assembly Support for GPR Pairs ('R') #112983
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Why did we need this change but AArch64 didn't?
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.
This is to prevent an assert that is hit in
RegsForValue::AddInlineAsmOperands
without this code.I think AArch64 is not hitting this because they didn't test very much - the
amocas.q
example has a lot of hard cases (multiple returns, matching input/output operands) which hit a lot of the hard cases in SelectionDAGBuilder. Note I had to fix one place where AArch64 was definitely wrong - the changes to callgetAsmOperandValueType
when there are multiple outputs from asm - AArch64 should have hit this case and didn't.I've spent a few more hours this evening trying to trace down this assert, and I feel closer, but not quite there. The testcase to use to get where I've got to (with the assert) is
test_Pr_wide_scalar_inout
.SelectionDAGBuilder.cpp's
getRegistersForValue
seems to be doing the right thing, always calling this with theVT
andRegisterVT
with the same values, as far as I can tell. It seems to create theOpInfo.AssignedRegs
in such a way that the later call togetNumRegisters
inRegsForValue::AddInlineAsmOperands
will get the same value as it did when it was created.Where this seems to go wrong is the matching inputs code in SelectionDAGBuilder.cpp -
llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Lines 10119 to 10139 in 8b55162
This seems to have its own logic about creating the
RegsForValue MatchedRegs(...)
based on the surrounding DAG Context, and seems to avoid the info available inOpInfo
which should have some relevancy, instead this code is directly pulling out similar (but not quite identical) information from the DAG. WhengetNumRegisters
is eventually called inMatchedRegs::AddInlineAsmOperands
, it usesMVT::i128
rather thanMVT::riscv_i64_pair
, which means it thinks it needs two registers, not just one. I think thisMVT::i128
is coming fromInOperandVal.getValueType()
when MatchedRegs is created.When this code is compared to
getRegistersForValue
, the two really don't seem to line up, logically - I would expect them both to be doing similar things, but they're not - how theRegsForValue
object is created ingetRegistersForValue
is reasonably different to this logic.git-blame-ing this code, it seems to have been introduced for supporting i128 on SystemZ - presumably also for paired operands - and they do have a
getNumRegisters
override, which returns1
- https://reviews.llvm.org/D100788 (refactors have hit a good number of lines around the SelectionDAGBuilder.cpp visitInlineAsm code I believe to be at fault, but nothing that's not NFC since that change).I don't feel good about the matching inputs code in SelectionDAGBuilder - I don't understand it, and I don't think my addition to
getNumRegisters
should be necessary if SelectionDAGBuilder.cpp worked more closely to howgetRegistersForValue
works. The extra confusing thing here is thatgetRegistersForValue
might have mutatedOpInfo
when there's a matched input - but returnedstd::nullopt
, so maybe the logic for matched inputs needs to just match the tail end ofgetRegistersForValue
. I'm not entirely sure.You're a lot more familiar with SelectionDAG than I am, do you have advice for what I should be doing here? It does seem like more target-independent code needs to be fixed to get rid of this. Maybe that can come later?