-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[MacroFusion][RISCV] Allocate same register for second instruction of fusible pair #77461
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
wangpc-pp
wants to merge
1
commit into
llvm:main
Choose a base branch
from
wangpc-pp:main-macrofusion-regalloc
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.
Open
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 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,37 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
;RUN: llc < %s -mtriple=riscv64 -mattr=+f -target-abi=lp64f \ | ||
;RUN: | FileCheck %s --check-prefix=NOFUSION | ||
;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion \ | ||
;RUN: -target-abi=lp64f | FileCheck %s --check-prefix=FUSION | ||
;RUN: llc < %s -mtriple=riscv64 -mattr=+f,+lui-addi-fusion,+use-postra-scheduler \ | ||
;RUN: -target-abi=lp64f | FileCheck %s --check-prefixes=FUSION-POSTRA | ||
|
||
define void @foo(i32 noundef signext %0, i32 noundef signext %1) { | ||
; NOFUSION-LABEL: foo: | ||
; NOFUSION: # %bb.0: | ||
; NOFUSION-NEXT: lui a0, 3014 | ||
; NOFUSION-NEXT: addiw a2, a0, 334 | ||
; NOFUSION-NEXT: mv a0, a1 | ||
; NOFUSION-NEXT: mv a1, a2 | ||
; NOFUSION-NEXT: tail bar | ||
; | ||
; FUSION-LABEL: foo: | ||
; FUSION: # %bb.0: | ||
; FUSION-NEXT: lui a2, 3014 | ||
; FUSION-NEXT: addiw a2, a2, 334 | ||
; FUSION-NEXT: mv a0, a1 | ||
; FUSION-NEXT: mv a1, a2 | ||
; FUSION-NEXT: tail bar | ||
; | ||
; FUSION-POSTRA-LABEL: foo: | ||
; FUSION-POSTRA: # %bb.0: | ||
; FUSION-POSTRA-NEXT: lui a2, 3014 | ||
; FUSION-POSTRA-NEXT: addiw a2, a2, 334 | ||
; FUSION-POSTRA-NEXT: mv a0, a1 | ||
; FUSION-POSTRA-NEXT: mv a1, a2 | ||
; FUSION-POSTRA-NEXT: tail bar | ||
tail call void @bar(i32 noundef signext %1, i32 noundef signext 12345678) | ||
ret void | ||
} | ||
|
||
declare void @bar(i32 noundef signext, i32 noundef signext) |
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.
Is the point to add a flag to simplify the code which detects fusible patterns? I realise that some processors may have a lot of fusions, but is adding a new flag really the right solution?
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!
I think this can be feasible, there are already some values in MIFlag that are not so common, like
NoConvergent
(SIMT only I think),Unpredictable
(X86 only), etc.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.
What if the second fusion instruction is an instruction with 2 register sources instead of 1 register and an immediate. We'll need to know which operand to constrain.
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.
Currently, I think this is a uncommon case and I don't know if there are such fusions. Do you have any example? Maybe integer multiply-add fusion?
Even if so, I think we can know the constrainted operands via its opcode and constrain them in the
getRegAllocationHints
implementation. We don't think we need to record this info in target-independent part.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.
From the RISC-V section of this page https://en.wikichip.org/wiki/macro-operation_fusion which are also listed here https://xiangshan-doc.readthedocs.io/zh-cn/latest/frontend/decode/
There are a few others on https://xiangshan-doc.readthedocs.io/zh-cn/latest/frontend/decode/
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, I didn't take a deep look into XiangShan's fusions (facepalming).
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.
Then we need to handle them case by case via opcode when adding hints.