-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LLVM] Combine v_cvt_f32_f16 and v_add_f32/v_mul_f32 into v_fma_mix_f32 #160151
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
Acim-Maravic
wants to merge
1
commit into
llvm:main
Choose a base branch
from
Acim-Maravic:combine-cvt-add-mul-fma-mix
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 |
---|---|---|
|
@@ -168,6 +168,7 @@ multiclass MadFmaMixPats<SDPatternOperator fma_like, | |
ValueType vecVT = v2f16> { | ||
defvar VOP3PMadMixModsPat = !if (!eq(VT, bf16), VOP3PMadMixBF16Mods, VOP3PMadMixMods); | ||
defvar VOP3PMadMixModsExtPat = !if (!eq(VT, bf16), VOP3PMadMixBF16ModsExt, VOP3PMadMixModsExt); | ||
defvar VOP3PMadMixModsNegPat = !if (!eq(VT, bf16), VOP3PMadMixBF16ModsNeg, VOP3PMadMixModsNeg); | ||
// At least one of the operands needs to be an fpextend of an f16 | ||
// for this to be worthwhile, so we need three patterns here. | ||
// TODO: Could we use a predicate to inspect src1/2/3 instead? | ||
|
@@ -190,6 +191,30 @@ multiclass MadFmaMixPats<SDPatternOperator fma_like, | |
(mix_inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, | ||
DSTCLAMP.NONE)>; | ||
|
||
def : GCNPat < | ||
(f32 (fadd (f32 (VOP3PMadMixModsExtPat VT:$src0, i32:$src0_mods)), | ||
(f32 (VOP3PMadMixModsPat f32:$src1, i32:$src1_mods)))), | ||
(mix_inst $src0_mods, $src0, (i32 0), (i32 1), $src1_mods, $src1, | ||
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 needs to use the f32 value 1.0 i.e. 3f800000, not just "1". Same below. 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. You can refer to this in patterns as |
||
DSTCLAMP.NONE)>; | ||
|
||
def : GCNPat < | ||
(f32 (fmul (f32 (VOP3PMadMixModsExtPat VT:$src0, i32:$src0_mods)), | ||
(f32 (VOP3PMadMixModsPat f32:$src1, i32:$src1_mods)))), | ||
(mix_inst $src0_mods, $src0, $src1_mods, $src1, (i32 0), (i32 0), | ||
DSTCLAMP.NONE)>; | ||
|
||
def : GCNPat < | ||
(f32 (fsub (f32 (VOP3PMadMixModsExtPat VT:$src0, i32:$src0_mods)), | ||
(f32 (VOP3PMadMixModsNegPat f32:$src1, i32:$src1_mods)))), | ||
(mix_inst $src0_mods, $src0, (i32 0), (i32 1), $src1_mods, $src1, | ||
DSTCLAMP.NONE)>; | ||
|
||
def : GCNPat < | ||
(f32 (fsub (f32 (VOP3PMadMixModsNegPat f32:$src0, i32:$src0_mods)), | ||
(f32 (VOP3PMadMixModsExtPat VT:$src1, i32:$src1_mods)))), | ||
(mix_inst $src0_mods, $src0, (i32 0), (i32 1), $src1_mods, $src1, | ||
DSTCLAMP.NONE)>; | ||
|
||
def : GCNPat < | ||
(AMDGPUclamp (build_vector | ||
(VT (fpround (fma_like (f32 (VOP3PMadMixModsPat VT:$lo_src0, i32:$lo_src0_modifiers)), | ||
|
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.
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.
Can you implement the globalisel equivalent
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.
A GlobalISel equivalent for this pattern is not necessary. In SelectionDAG, DAGCombiner folds (fadd y, (fneg x)) into (fsub y, x), before the main instruction selection matching occurs. An alternative could be to modify the DAGCombiner to avoid folding fadd (fneg x) into fsub when the target has FMA support and at least one of the operands is an fpextend
?
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 more like another missing combine in globalisel