Skip to content

Commit f122268

Browse files
authored
[AMDGPU][NFC] Extend PredicateControl to support True16 predicates. (#82245)
Using OtherPredicates for True16 predicates is often problematic due to interference with other kinds of predicates, particularly when this overrides predicates inherited from pseudo instructions.
1 parent 90c46be commit f122268

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
include "llvm/TableGen/SearchableTable.td"
1010
include "llvm/Target/Target.td"
1111
include "AMDGPUFeatures.td"
12+
include "AMDGPUPredicateControl.td"
1213

1314
def p0 : PtrValueType<i64, 0>;
1415
def p1 : PtrValueType<i64, 1>;
@@ -1895,10 +1896,10 @@ def NotHasTrue16BitInsts : Predicate<"!Subtarget->hasTrue16BitInsts()">;
18951896
// True16 instructions as they are defined in the ISA. Fake True16
18961897
// instructions have the same encoding as real ones but syntactically
18971898
// only allow 32-bit registers in operands and use low halves thereof.
1898-
def UseRealTrue16Insts : Predicate<"Subtarget->useRealTrue16Insts()">,
1899+
def UseRealTrue16Insts : True16PredicateClass<"Subtarget->useRealTrue16Insts()">,
18991900
AssemblerPredicate<(all_of FeatureTrue16BitInsts, FeatureRealTrue16Insts)>;
1900-
def UseFakeTrue16Insts : Predicate<"Subtarget->hasTrue16BitInsts() && "
1901-
"!Subtarget->useRealTrue16Insts()">;
1901+
def UseFakeTrue16Insts : True16PredicateClass<"Subtarget->hasTrue16BitInsts() && "
1902+
"!Subtarget->useRealTrue16Insts()">;
19021903

19031904
def HasVOP3PInsts : Predicate<"Subtarget->hasVOP3PInsts()">,
19041905
AssemblerPredicate<(all_of FeatureVOP3P)>;

llvm/lib/Target/AMDGPU/AMDGPUInstructions.td

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,11 @@ class ILFormat<dag outs, dag ins, string asmstr, list<dag> pattern>
7676
let isCodeGenOnly = 1;
7777
}
7878

79-
def TruePredicate : Predicate<"">;
80-
81-
// FIXME: Tablegen should specially supports this
82-
def FalsePredicate : Predicate<"false">;
83-
84-
// Add a predicate to the list if does not already exist to deduplicate it.
85-
class PredConcat<list<Predicate> lst, Predicate pred> {
86-
list<Predicate> ret = !listconcat(lst, !listremove([pred], lst));
87-
}
88-
8979
// Get the union of two Register lists
9080
class RegListUnion<list<Register> lstA, list<Register> lstB> {
9181
list<Register> ret = !listconcat(lstA, !listremove(lstB, lstA));
9282
}
9383

94-
class PredicateControl {
95-
Predicate SubtargetPredicate = TruePredicate;
96-
Predicate AssemblerPredicate = TruePredicate;
97-
Predicate WaveSizePredicate = TruePredicate;
98-
list<Predicate> OtherPredicates = [];
99-
list<Predicate> Predicates = PredConcat<
100-
PredConcat<PredConcat<OtherPredicates,
101-
SubtargetPredicate>.ret,
102-
AssemblerPredicate>.ret,
103-
WaveSizePredicate>.ret;
104-
}
105-
10684
class AMDGPUPat<dag pattern, dag result> : Pat<pattern, result>,
10785
PredicateControl, GISelFlags;
10886

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- AMDGPUPredicateControl.td --------------------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
def TruePredicate : Predicate<"">;
10+
11+
// FIXME: Tablegen should specially supports this
12+
def FalsePredicate : Predicate<"false">;
13+
14+
// Add a predicate to the list if does not already exist to deduplicate it.
15+
class PredConcat<Predicate pred, list<Predicate> lst> {
16+
list<Predicate> ret = !listconcat(lst, !listremove([pred], lst));
17+
}
18+
19+
// Prevent using other kinds of predicates where True16 predicates are
20+
// expected by giving them their own class.
21+
class True16PredicateClass<string cond> : Predicate<cond>;
22+
def NoTrue16Predicate : True16PredicateClass<"">;
23+
24+
class PredicateControl {
25+
Predicate SubtargetPredicate = TruePredicate;
26+
Predicate AssemblerPredicate = TruePredicate;
27+
Predicate WaveSizePredicate = TruePredicate;
28+
True16PredicateClass True16Predicate = NoTrue16Predicate;
29+
list<Predicate> OtherPredicates = [];
30+
list<Predicate> Predicates =
31+
PredConcat<SubtargetPredicate,
32+
PredConcat<AssemblerPredicate,
33+
PredConcat<WaveSizePredicate,
34+
PredConcat<True16Predicate,
35+
OtherPredicates>.ret>.ret>.ret>.ret;
36+
}

llvm/lib/Target/AMDGPU/R600.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ include "R600Schedule.td"
3535
include "R600Processors.td"
3636
include "R600InstrInfo.td"
3737
include "AMDGPUInstrInfo.td"
38+
include "AMDGPUPredicateControl.td"
3839
include "AMDGPUInstructions.td"
3940
include "R600Instructions.td"
4041
include "R700Instructions.td"

llvm/lib/Target/AMDGPU/VOPInstructions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,8 @@ multiclass VOP3_Real_dpp8_with_name<GFXGen Gen, bits<10> op, string opName,
14841484
let AsmString = asmName # ps.Pfl.AsmVOP3DPP8,
14851485
DecoderNamespace = "DPP8"#Gen.DecoderNamespace#
14861486
!if(ps.Pfl.IsRealTrue16, "", "_FAKE16"),
1487-
OtherPredicates = !if(ps.Pfl.IsRealTrue16, [UseRealTrue16Insts],
1488-
[TruePredicate]) in {
1487+
True16Predicate = !if(ps.Pfl.IsRealTrue16, UseRealTrue16Insts,
1488+
NoTrue16Predicate) in {
14891489
defm NAME : VOP3_Real_dpp8_Base<Gen, op, opName>;
14901490
}
14911491
}

0 commit comments

Comments
 (0)