-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Implement tail call optimization in machine outliner #115297
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
; RUN: llc < %s -verify-machineinstrs -enable-machine-outliner | FileCheck %s | ||
|
||
target triple = "riscv64-unknown-linux-gnu" | ||
|
||
declare void @foo(i32, i32, i32, i32) minsize | ||
|
||
define void @fentry0(i1 %a) nounwind { | ||
; CHECK-LABEL: fentry0: | ||
; CHECK: # %bb.1: | ||
; CHECK-NEXT: call t0, OUTLINED_FUNCTION_[[BB1:[0-9]+]] | ||
; CHECK-NEXT: call foo | ||
; CHECK-LABEL: .LBB0_2: | ||
; CHECK-NEXT: tail OUTLINED_FUNCTION_[[BB2:[0-9]+]] | ||
entry: | ||
br i1 %a, label %if.then, label %if.end | ||
if.then: | ||
call void @foo(i32 1, i32 2, i32 3, i32 4) | ||
br label %if.end | ||
if.end: | ||
call void @foo(i32 5, i32 6, i32 7, i32 8) | ||
ret void | ||
} | ||
|
||
define void @fentry1(i1 %a) nounwind { | ||
; CHECK-LABEL: fentry1: | ||
; CHECK: # %bb.1: | ||
; CHECK-NEXT: call t0, OUTLINED_FUNCTION_[[BB1:[0-9]+]] | ||
; CHECK-NEXT: call foo | ||
; CHECK-LABEL: .LBB1_2: | ||
; CHECK-NEXT: tail OUTLINED_FUNCTION_[[BB2:[0-9]+]] | ||
entry: | ||
br i1 %a, label %if.then, label %if.end | ||
if.then: | ||
call void @foo(i32 1, i32 2, i32 3, i32 4) | ||
br label %if.end | ||
if.end: | ||
call void @foo(i32 5, i32 6, i32 7, i32 8) | ||
ret void | ||
} | ||
|
||
define void @fentry2(i1 %a) nounwind { | ||
; CHECK-LABEL: fentry2: | ||
; CHECK: # %bb.1: | ||
; CHECK-NEXT: call t0, OUTLINED_FUNCTION_[[BB1:[0-9]+]] | ||
; CHECK-NEXT: call foo | ||
; CHECK-LABEL: .LBB2_2: | ||
; CHECK-NEXT: tail OUTLINED_FUNCTION_[[BB2:[0-9]+]] | ||
entry: | ||
br i1 %a, label %if.then, label %if.end | ||
if.then: | ||
call void @foo(i32 1, i32 2, i32 3, i32 4) | ||
br label %if.end | ||
if.end: | ||
call void @foo(i32 5, i32 6, i32 7, i32 8) | ||
ret void | ||
} | ||
|
||
; CHECK: OUTLINED_FUNCTION_[[BB2]]: | ||
; CHECK: li a0, 5 | ||
; CHECK-NEXT: li a1, 6 | ||
; CHECK-NEXT: li a2, 7 | ||
; CHECK-NEXT: li a3, 8 | ||
; CHECK-NEXT: call foo | ||
|
||
; CHECK: OUTLINED_FUNCTION_[[BB1]]: | ||
; CHECK: li a0, 1 | ||
; CHECK-NEXT: li a1, 2 | ||
; CHECK-NEXT: li a2, 3 | ||
; CHECK-NEXT: li a3, 4 | ||
; CHECK-NEXT: jr t0 |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
PseudoTAIL expands to AUIPC+JALR using X6 or X7 as a temporary. If the linker doesn't relax the AUIPC+JALR sequence to JAL, then X6 or X7 will be overwritten. How do we know it is ok to overwrite X6 or X7?
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.
Thanks for the comment, I did not consider the case of the influence of registers x6 and x7 before relaxation. Apparently, even llvm-test-suite didn't get such case.
I rewrote verification algorithm for tail call. If we modify X6/X7 (Specific register get from enabled extensions info) earlier than reads from X6/X7, than my optimization can be applied.