[llvm] d5ca2e4 - [AMDGPU] Improve MIR pattern for FMinFMaxLegacy combine. NFC. (#90968)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 5 02:29:04 PDT 2024
Author: Jay Foad
Date: 2024-05-05T10:29:01+01:00
New Revision: d5ca2e46ca97758de6edb9f071f2114205380d87
URL: https://github.com/llvm/llvm-project/commit/d5ca2e46ca97758de6edb9f071f2114205380d87
DIFF: https://github.com/llvm/llvm-project/commit/d5ca2e46ca97758de6edb9f071f2114205380d87.diff
LOG: [AMDGPU] Improve MIR pattern for FMinFMaxLegacy combine. NFC. (#90968)
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUCombine.td
llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCombine.td b/llvm/lib/Target/AMDGPU/AMDGPUCombine.td
index 3e043db115b7d8..9703eea59b2970 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 ff7cf9c8d6dcc2..23b71fa51921ed 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;
@@ -158,17 +159,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();
More information about the llvm-commits
mailing list