-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[StatepointLowering] Handle struct return through stack #157251
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
Open
abhishek-kaushik22
wants to merge
3
commits into
llvm:main
Choose a base branch
from
abhishek-kaushik22:statepoint-struct
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−2
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,13 +337,17 @@ static std::pair<SDValue, SDNode *> lowerCallFromStatepointLoweringInfo( | |
// | ||
// get_return_value can either be a sequence of CopyFromReg instructions | ||
// to grab the return value from the return register(s), or it can be a LOAD | ||
// to load a value returned by reference via a stack slot. | ||
// to load a value returned by reference via a stack slot, or it can be a | ||
// struct returned by value through stack. | ||
|
||
if (CallEnd->getOpcode() == ISD::EH_LABEL) | ||
CallEnd = CallEnd->getOperand(0).getNode(); | ||
|
||
bool HasDef = !SI.CLI.RetTy->isVoidTy(); | ||
bool HasDef = !SI.CLI.RetTy->isVoidTy() || !SI.CLI.OutVals.empty(); | ||
if (HasDef) { | ||
if (CallEnd->getOpcode() == ISD::TokenFactor) | ||
CallEnd = CallEnd->getOperand(0).getNode(); | ||
Comment on lines
+348
to
+349
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is making an assumption about the ordering of the TokenFactor inputs, don't do that? You should have an explicit reference to the call end direct from lowerInvokable? |
||
|
||
if (CallEnd->getOpcode() == ISD::LOAD) | ||
CallEnd = CallEnd->getOperand(0).getNode(); | ||
else | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s | ||
|
||
; This test checks that statepoint lowering works when the call returns a | ||
; struct using a stack slot (sret). Previously, this case caused an assertion | ||
; because the lowering code assumed the chain ended at CALLSEQ_END. The fix | ||
; handles TokenFactor/LOAD cases so the chain is found correctly. | ||
|
||
%t = type { i32, i32, i32, i32 } | ||
|
||
define %t @PR74612() gc "statepoint-example" { | ||
; CHECK-LABEL: PR74612: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: pushq %rbx | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: subq $16, %rsp | ||
; CHECK-NEXT: .cfi_def_cfa_offset 32 | ||
; CHECK-NEXT: .cfi_offset %rbx, -16 | ||
; CHECK-NEXT: movq %rdi, %rbx | ||
; CHECK-NEXT: movq %rsp, %rdi | ||
; CHECK-NEXT: callq bar@PLT | ||
; CHECK-NEXT: .Ltmp0: | ||
; CHECK-NEXT: movl {{[0-9]+}}(%rsp), %eax | ||
; CHECK-NEXT: movl {{[0-9]+}}(%rsp), %ecx | ||
; CHECK-NEXT: movl (%rsp), %edx | ||
; CHECK-NEXT: movl {{[0-9]+}}(%rsp), %esi | ||
; CHECK-NEXT: movl %edx, (%rbx) | ||
; CHECK-NEXT: movl %ecx, 8(%rbx) | ||
; CHECK-NEXT: movl %eax, 12(%rbx) | ||
; CHECK-NEXT: movl %esi, 4(%rbx) | ||
; CHECK-NEXT: movq %rbx, %rax | ||
; CHECK-NEXT: addq $16, %rsp | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: popq %rbx | ||
; CHECK-NEXT: .cfi_def_cfa_offset 8 | ||
; CHECK-NEXT: retq | ||
%statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(%t ()) @bar, i32 0, i32 0, i32 0, i32 0) | ||
%res = call %t @llvm.experimental.gc.result.s_zeros(token %statepoint_token) | ||
ret %t %res | ||
} | ||
|
||
declare %t @bar() | ||
declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...) | ||
declare %t @llvm.experimental.gc.result.s_zeros(token) |
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.
Should be redundant?