-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU] Improve MIR pattern for FMinFMaxLegacy combine. NFC. #90968
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
Conversation
@llvm/pr-subscribers-backend-amdgpu Author: Jay Foad (jayfoad) ChangesFull diff: https://github.com/llvm/llvm-project/pull/90968.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
index 9218760538dc5d..9cd56f4cdb1f53 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
@@ -15,8 +15,9 @@ def fmin_fmax_legacy_matchdata : GIDefMatchData<"FMinFMaxLegacyInfo">;
let Predicates = [HasFminFmaxLegacy] in
def fcmp_select_to_fmin_fmax_legacy : GICombineRule<
(defs root:$select, fmin_fmax_legacy_matchdata:$matchinfo),
- (match (wip_match_opcode G_SELECT):$select,
- [{ return matchFMinFMaxLegacy(*${select}, ${matchinfo}); }]),
+ (match (G_FCMP $cond, $pred, $lhs, $rhs):$fcmp,
+ (G_SELECT f32:$dst, $cond, $true, $false):$select,
+ [{ return matchFMinFMaxLegacy(*${select}, *${fcmp}, ${matchinfo}); }]),
(apply [{ applySelectFCmpToFMinToFMaxLegacy(*${select}, ${matchinfo}); }])>;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
index 43ed14f350215d..fa8420b2f69782 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
@@ -70,7 +70,8 @@ class AMDGPUPostLegalizerCombinerImpl : public Combiner {
};
// TODO: Make sure fmin_legacy/fmax_legacy don't canonicalize
- bool matchFMinFMaxLegacy(MachineInstr &MI, FMinFMaxLegacyInfo &Info) const;
+ bool matchFMinFMaxLegacy(MachineInstr &MI, MachineInstr &FCmp,
+ FMinFMaxLegacyInfo &Info) const;
void applySelectFCmpToFMinToFMaxLegacy(MachineInstr &MI,
const FMinFMaxLegacyInfo &Info) const;
@@ -159,17 +160,14 @@ bool AMDGPUPostLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
}
bool AMDGPUPostLegalizerCombinerImpl::matchFMinFMaxLegacy(
- MachineInstr &MI, FMinFMaxLegacyInfo &Info) const {
- // FIXME: Type predicate on pattern
- if (MRI.getType(MI.getOperand(0).getReg()) != LLT::scalar(32))
- return false;
-
- Register Cond = MI.getOperand(1).getReg();
- if (!MRI.hasOneNonDBGUse(Cond) ||
- !mi_match(Cond, MRI,
- m_GFCmp(m_Pred(Info.Pred), m_Reg(Info.LHS), m_Reg(Info.RHS))))
+ MachineInstr &MI, MachineInstr &FCmp, FMinFMaxLegacyInfo &Info) const {
+ if (!MRI.hasOneNonDBGUse(FCmp.getOperand(0).getReg()))
return false;
+ Info.Pred =
+ static_cast<CmpInst::Predicate>(FCmp.getOperand(1).getPredicate());
+ Info.LHS = FCmp.getOperand(2).getReg();
+ Info.RHS = FCmp.getOperand(3).getReg();
Register True = MI.getOperand(2).getReg();
Register False = MI.getOperand(3).getReg();
|
!mi_match(Cond, MRI, | ||
m_GFCmp(m_Pred(Info.Pred), m_Reg(Info.LHS), m_Reg(Info.RHS)))) | ||
MachineInstr &MI, MachineInstr &FCmp, FMinFMaxLegacyInfo &Info) const { | ||
if (!MRI.hasOneNonDBGUse(FCmp.getOperand(0).getReg())) |
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 there a way to do this check in the MIR pattern?
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.
No. Other uses could have sneaked in.
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.
Sneaked in after the autogenerated matcher runs but before this match function is called? That doesn't sound right.
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.
You could:
GFCmp *Cmp = cast<GFCmp>(&FCmp);
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.
The G_FCMP could be used by other MIs.
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.
The G_FCMP could be used by other MIs.
I know. I would like to write something in the pattern to check for this, instead of writing C++ to check for this.
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.
Open an issue?
@@ -15,8 +15,9 @@ def fmin_fmax_legacy_matchdata : GIDefMatchData<"FMinFMaxLegacyInfo">; | |||
let Predicates = [HasFminFmaxLegacy] in | |||
def fcmp_select_to_fmin_fmax_legacy : GICombineRule< | |||
(defs root:$select, fmin_fmax_legacy_matchdata:$matchinfo), |
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.
Am I supposed to list $fcmp
in the defs since I am passing it into my match function? Or doesn't that count as an "external" use of $fcmp
?
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.
No. I prefer to only list the $root
. defs is probably definitions and not def in SSA.
You could hoist:
into the pattern, but then you to write the pattern twice. |
No description provided.