Skip to content

Commit fc06c8e

Browse files
authored
AMDGPU: Partially clean up canonicalized predicates in tablegen (#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.
1 parent 0674ed7 commit fc06c8e

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,19 @@ def fp16_zeros_high_16bits : PatLeaf<(f16 VGPR_32:$src), [{
835835
return fp16SrcZerosHighBits(N->getOpcode());
836836
}]>;
837837

838+
def is_canonicalized : PatLeaf<(fAny srcvalue:$src), [{
839+
const SITargetLowering &Lowering =
840+
*static_cast<const SITargetLowering *>(getTargetLowering());
841+
return Lowering.isCanonicalized(*CurDAG, SDValue(N, 0));
842+
}]> {
843+
let GISelPredicateCode = [{
844+
const SITargetLowering *TLI = static_cast<const SITargetLowering *>(
845+
MF.getSubtarget().getTargetLowering());
846+
const MachineOperand &Dst = MI.getOperand(0);
847+
assert(Dst.isDef());
848+
return TLI->isCanonicalized(Dst.getReg(), MF);
849+
}];
850+
}
838851

839852
//===----------------------------------------------------------------------===//
840853
// MUBUF/SMEM Patterns

llvm/lib/Target/AMDGPU/SIInstructions.td

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,30 +2946,12 @@ def : GCNPat<
29462946

29472947
// If fcanonicalize's operand is implicitly canonicalized, we only need a copy.
29482948
let AddedComplexity = 1000 in {
2949-
def : GCNPat<
2950-
(is_canonicalized_1<fcanonicalize> f16:$src),
2951-
(COPY f16:$src)
2952-
>;
2953-
2954-
def : GCNPat<
2955-
(is_canonicalized_1<fcanonicalize> v2f16:$src),
2956-
(COPY v2f16:$src)
2957-
>;
2958-
2959-
def : GCNPat<
2960-
(is_canonicalized_1<fcanonicalize> f32:$src),
2961-
(COPY f32:$src)
2962-
>;
2963-
2964-
def : GCNPat<
2965-
(is_canonicalized_1<fcanonicalize> v2f32:$src),
2966-
(COPY v2f32:$src)
2967-
>;
2968-
2969-
def : GCNPat<
2970-
(is_canonicalized_1<fcanonicalize> f64:$src),
2971-
(COPY f64:$src)
2972-
>;
2949+
foreach vt = [f16, v2f16, f32, v2f32, f64] in {
2950+
def : GCNPat<
2951+
(fcanonicalize (vt is_canonicalized:$src)),
2952+
(COPY vt:$src)
2953+
>;
2954+
}
29732955
}
29742956

29752957
// Prefer selecting to max when legal, but using mul is always valid.

0 commit comments

Comments
 (0)