[llvm] AMDGPU: Partially clean up canonicalized predicates in tablegen (PR #85404)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 07:15:31 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/85404
This was the easy case. There are more issues with some of the other is_canonicalized* patterns. First there appears to be a tablegen bug where the predicate is silently ignored if used as a ComplexPattern source, and we also probably need a version with an operand.
>From 3e07ba826a5b7a584fe6a50c5e9b1e7afe0644be Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 14 Mar 2024 15:12:04 +0530
Subject: [PATCH] AMDGPU: Partially clean up canonicalized predicates in
tablegen
This was the easy case. There are more issues with some of the
other is_canonicalized* patterns. First there appears to be a
tablegen bug where the predicate is silently ignored if used
as a ComplexPattern source, and we also probably need a version
with an operand.
---
llvm/lib/Target/AMDGPU/SIInstrInfo.td | 13 ++++++++++
llvm/lib/Target/AMDGPU/SIInstructions.td | 30 +++++-------------------
2 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
index 835a5a24723154..1694436bad15ce 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -835,6 +835,19 @@ def fp16_zeros_high_16bits : PatLeaf<(f16 VGPR_32:$src), [{
return fp16SrcZerosHighBits(N->getOpcode());
}]>;
+def is_canonicalized : PatLeaf<(fAny srcvalue:$src), [{
+ const SITargetLowering &Lowering =
+ *static_cast<const SITargetLowering *>(getTargetLowering());
+ return Lowering.isCanonicalized(*CurDAG, SDValue(N, 0));
+}]> {
+ let GISelPredicateCode = [{
+ const SITargetLowering *TLI = static_cast<const SITargetLowering *>(
+ MF.getSubtarget().getTargetLowering());
+ const MachineOperand &Dst = MI.getOperand(0);
+ assert(Dst.isDef());
+ return TLI->isCanonicalized(Dst.getReg(), MF);
+ }];
+}
//===----------------------------------------------------------------------===//
// MUBUF/SMEM Patterns
diff --git a/llvm/lib/Target/AMDGPU/SIInstructions.td b/llvm/lib/Target/AMDGPU/SIInstructions.td
index 3ab788406ecb28..1c942dcefdacea 100644
--- a/llvm/lib/Target/AMDGPU/SIInstructions.td
+++ b/llvm/lib/Target/AMDGPU/SIInstructions.td
@@ -2946,30 +2946,12 @@ def : GCNPat<
// If fcanonicalize's operand is implicitly canonicalized, we only need a copy.
let AddedComplexity = 1000 in {
-def : GCNPat<
- (is_canonicalized_1<fcanonicalize> f16:$src),
- (COPY f16:$src)
->;
-
-def : GCNPat<
- (is_canonicalized_1<fcanonicalize> v2f16:$src),
- (COPY v2f16:$src)
->;
-
-def : GCNPat<
- (is_canonicalized_1<fcanonicalize> f32:$src),
- (COPY f32:$src)
->;
-
-def : GCNPat<
- (is_canonicalized_1<fcanonicalize> v2f32:$src),
- (COPY v2f32:$src)
->;
-
-def : GCNPat<
- (is_canonicalized_1<fcanonicalize> f64:$src),
- (COPY f64:$src)
->;
+foreach vt = [f16, v2f16, f32, v2f32, f64] in {
+ def : GCNPat<
+ (fcanonicalize (vt is_canonicalized:$src)),
+ (COPY vt:$src)
+ >;
+}
}
// Prefer selecting to max when legal, but using mul is always valid.
More information about the llvm-commits
mailing list