Skip to content

Commit bc98c31

Browse files
committed
Revert "[SelectionDAG] Add space-optimized forms of OPC_CheckPredicate (#73488)"
This reverts commit 1a57927. Test address-space-patfrags.td.test is failing https://lab.llvm.org/buildbot/#/builders/104/builds/15012
1 parent bbbe8ec commit bc98c31

File tree

5 files changed

+45
-94
lines changed

5 files changed

+45
-94
lines changed

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,6 @@ class SelectionDAGISel : public MachineFunctionPass {
169169
OPC_CheckPatternPredicate7,
170170
OPC_CheckPatternPredicateTwoByte,
171171
OPC_CheckPredicate,
172-
OPC_CheckPredicate0,
173-
OPC_CheckPredicate1,
174-
OPC_CheckPredicate2,
175-
OPC_CheckPredicate3,
176-
OPC_CheckPredicate4,
177-
OPC_CheckPredicate5,
178-
OPC_CheckPredicate6,
179-
OPC_CheckPredicate7,
180172
OPC_CheckPredicateWithOperands,
181173
OPC_CheckOpcode,
182174
OPC_SwitchOpcode,

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,13 +2712,9 @@ CheckPatternPredicate(unsigned Opcode, const unsigned char *MatcherTable,
27122712

27132713
/// CheckNodePredicate - Implements OP_CheckNodePredicate.
27142714
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
2715-
CheckNodePredicate(unsigned Opcode, const unsigned char *MatcherTable,
2716-
unsigned &MatcherIndex, const SelectionDAGISel &SDISel,
2717-
SDNode *N) {
2718-
unsigned PredNo = Opcode == SelectionDAGISel::OPC_CheckPredicate
2719-
? MatcherTable[MatcherIndex++]
2720-
: Opcode - SelectionDAGISel::OPC_CheckPredicate0;
2721-
return SDISel.CheckNodePredicate(N, PredNo);
2715+
CheckNodePredicate(const unsigned char *MatcherTable, unsigned &MatcherIndex,
2716+
const SelectionDAGISel &SDISel, SDNode *N) {
2717+
return SDISel.CheckNodePredicate(N, MatcherTable[MatcherIndex++]);
27222718
}
27232719

27242720
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
@@ -2872,15 +2868,7 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
28722868
Result = !::CheckPatternPredicate(Opcode, Table, Index, SDISel);
28732869
return Index;
28742870
case SelectionDAGISel::OPC_CheckPredicate:
2875-
case SelectionDAGISel::OPC_CheckPredicate0:
2876-
case SelectionDAGISel::OPC_CheckPredicate1:
2877-
case SelectionDAGISel::OPC_CheckPredicate2:
2878-
case SelectionDAGISel::OPC_CheckPredicate3:
2879-
case SelectionDAGISel::OPC_CheckPredicate4:
2880-
case SelectionDAGISel::OPC_CheckPredicate5:
2881-
case SelectionDAGISel::OPC_CheckPredicate6:
2882-
case SelectionDAGISel::OPC_CheckPredicate7:
2883-
Result = !::CheckNodePredicate(Opcode, Table, Index, SDISel, N.getNode());
2871+
Result = !::CheckNodePredicate(Table, Index, SDISel, N.getNode());
28842872
return Index;
28852873
case SelectionDAGISel::OPC_CheckOpcode:
28862874
Result = !::CheckOpcode(Table, Index, N.getNode());
@@ -3371,16 +3359,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
33713359
if (!::CheckPatternPredicate(Opcode, MatcherTable, MatcherIndex, *this))
33723360
break;
33733361
continue;
3374-
case SelectionDAGISel::OPC_CheckPredicate0:
3375-
case SelectionDAGISel::OPC_CheckPredicate1:
3376-
case SelectionDAGISel::OPC_CheckPredicate2:
3377-
case SelectionDAGISel::OPC_CheckPredicate3:
3378-
case SelectionDAGISel::OPC_CheckPredicate4:
3379-
case SelectionDAGISel::OPC_CheckPredicate5:
3380-
case SelectionDAGISel::OPC_CheckPredicate6:
3381-
case SelectionDAGISel::OPC_CheckPredicate7:
33823362
case OPC_CheckPredicate:
3383-
if (!::CheckNodePredicate(Opcode, MatcherTable, MatcherIndex, *this,
3363+
if (!::CheckNodePredicate(MatcherTable, MatcherIndex, *this,
33843364
N.getNode()))
33853365
break;
33863366
continue;

llvm/test/TableGen/address-space-patfrags.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def inst_d : Instruction {
4646
let InOperandList = (ins GPR32:$src0, GPR32:$src1);
4747
}
4848

49-
// SDAG: case 1: {
49+
// SDAG: case 2: {
5050
// SDAG-NEXT: // Predicate_pat_frag_b
5151
// SDAG-NEXT: // Predicate_truncstorei16_addrspace
5252
// SDAG-NEXT: SDNode *N = Node;
@@ -69,7 +69,7 @@ def : Pat <
6969
>;
7070

7171

72-
// SDAG: case 6: {
72+
// SDAG: case 3: {
7373
// SDAG: // Predicate_pat_frag_a
7474
// SDAG-NEXT: SDNode *N = Node;
7575
// SDAG-NEXT: (void)N;

llvm/test/TableGen/predicate-patfags.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def TGTmul24_oneuse : PatFrag<
3939
}
4040

4141
// SDAG: OPC_CheckOpcode, TARGET_VAL(ISD::INTRINSIC_W_CHAIN),
42-
// SDAG: OPC_CheckPredicate0, // Predicate_TGTmul24_oneuse
42+
// SDAG: OPC_CheckPredicate, 0, // Predicate_TGTmul24_oneuse
4343

4444
// SDAG: OPC_CheckOpcode, TARGET_VAL(TargetISD::MUL24),
45-
// SDAG: OPC_CheckPredicate0, // Predicate_TGTmul24_oneuse
45+
// SDAG: OPC_CheckPredicate, 0, // Predicate_TGTmul24_oneuse
4646

4747
// GISEL: GIM_CheckOpcode, /*MI*/1, GIMT_Encode2(TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS),
4848
// GISEL: GIM_CheckIntrinsicID, /*MI*/1, /*Op*/1, GIMT_Encode2(Intrinsic::tgt_mul24),

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class MatcherTableEmitter {
5252

5353
SmallVector<unsigned, Matcher::HighestKind+1> OpcodeCounts;
5454

55-
std::vector<TreePattern *> NodePredicates;
56-
std::vector<TreePattern *> NodePredicatesWithOperands;
55+
DenseMap<TreePattern *, unsigned> NodePredicateMap;
56+
std::vector<TreePredicateFn> NodePredicates;
57+
std::vector<TreePredicateFn> NodePredicatesWithOperands;
5758

5859
// We de-duplicate the predicates by code string, and use this map to track
5960
// all the patterns with "identical" predicates.
@@ -87,8 +88,6 @@ class MatcherTableEmitter {
8788
DenseMap<const ComplexPattern *, unsigned> ComplexPatternUsage;
8889
// Record the usage of PatternPredicate.
8990
std::map<StringRef, unsigned> PatternPredicateUsage;
90-
// Record the usage of Predicate.
91-
DenseMap<TreePattern *, unsigned> PredicateUsage;
9291

9392
// Iterate the whole MatcherTable once and do some statistics.
9493
std::function<void(const Matcher *)> Statistic = [&](const Matcher *N) {
@@ -106,8 +105,6 @@ class MatcherTableEmitter {
106105
++ComplexPatternUsage[&CPM->getPattern()];
107106
else if (auto *CPPM = dyn_cast<CheckPatternPredicateMatcher>(N))
108107
++PatternPredicateUsage[CPPM->getPredicate()];
109-
else if (auto *PM = dyn_cast<CheckPredicateMatcher>(N))
110-
++PredicateUsage[PM->getPredicate().getOrigPatFragRecord()];
111108
N = N->getNext();
112109
}
113110
};
@@ -128,39 +125,6 @@ class MatcherTableEmitter {
128125
[](const auto &A, const auto &B) { return A.second > B.second; });
129126
for (const auto &PatternPredicate : PatternPredicateList)
130127
PatternPredicates.push_back(PatternPredicate.first);
131-
132-
// Sort Predicates by usage.
133-
// Merge predicates with same code.
134-
for (const auto &Usage : PredicateUsage) {
135-
TreePattern *TP = Usage.first;
136-
TreePredicateFn Pred(TP);
137-
NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()].push_back(TP);
138-
}
139-
140-
std::vector<std::pair<TreePattern *, unsigned>> PredicateList;
141-
// Sum the usage.
142-
for (auto &Predicate : NodePredicatesByCodeToRun) {
143-
TinyPtrVector<TreePattern *> &TPs = Predicate.second;
144-
sort(TPs, [](const auto *A, const auto *B) {
145-
return A->getRecord()->getName() < B->getRecord()->getName();
146-
});
147-
unsigned Uses = 0;
148-
for (TreePattern *TP : TPs)
149-
Uses += PredicateUsage.at(TP);
150-
151-
// We only add the first predicate here since they are with the same code.
152-
PredicateList.push_back({TPs[0], Uses});
153-
}
154-
155-
sort(PredicateList,
156-
[](const auto &A, const auto &B) { return A.second > B.second; });
157-
for (const auto &Predicate : PredicateList) {
158-
TreePattern *TP = Predicate.first;
159-
if (TreePredicateFn(TP).usesOperands())
160-
NodePredicatesWithOperands.push_back(TP);
161-
else
162-
NodePredicates.push_back(TP);
163-
}
164128
}
165129

166130
unsigned EmitMatcherList(const Matcher *N, const unsigned Indent,
@@ -175,7 +139,7 @@ class MatcherTableEmitter {
175139
void EmitPatternMatchTable(raw_ostream &OS);
176140

177141
private:
178-
void EmitNodePredicatesFunction(const std::vector<TreePattern *> &Preds,
142+
void EmitNodePredicatesFunction(const std::vector<TreePredicateFn> &Preds,
179143
StringRef Decl, raw_ostream &OS);
180144

181145
unsigned SizeMatcher(Matcher *N, raw_ostream &OS);
@@ -184,13 +148,33 @@ class MatcherTableEmitter {
184148
raw_ostream &OS);
185149

186150
unsigned getNodePredicate(TreePredicateFn Pred) {
187-
// We use the first predicate.
188-
TreePattern *PredPat =
189-
NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()][0];
190-
return Pred.usesOperands()
191-
? llvm::find(NodePredicatesWithOperands, PredPat) -
192-
NodePredicatesWithOperands.begin()
193-
: llvm::find(NodePredicates, PredPat) - NodePredicates.begin();
151+
TreePattern *TP = Pred.getOrigPatFragRecord();
152+
unsigned &Entry = NodePredicateMap[TP];
153+
if (Entry == 0) {
154+
TinyPtrVector<TreePattern *> &SameCodePreds =
155+
NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()];
156+
if (SameCodePreds.empty()) {
157+
// We've never seen a predicate with the same code: allocate an entry.
158+
if (Pred.usesOperands()) {
159+
NodePredicatesWithOperands.push_back(Pred);
160+
Entry = NodePredicatesWithOperands.size();
161+
} else {
162+
NodePredicates.push_back(Pred);
163+
Entry = NodePredicates.size();
164+
}
165+
} else {
166+
// We did see an identical predicate: re-use it.
167+
Entry = NodePredicateMap[SameCodePreds.front()];
168+
assert(Entry != 0);
169+
assert(TreePredicateFn(SameCodePreds.front()).usesOperands() ==
170+
Pred.usesOperands() &&
171+
"PatFrags with some code must have same usesOperands setting");
172+
}
173+
// In both cases, we've never seen this particular predicate before, so
174+
// mark it in the list of predicates sharing the same code.
175+
SameCodePreds.push_back(TP);
176+
}
177+
return Entry-1;
194178
}
195179

196180
unsigned getPatternPredicate(StringRef PredName) {
@@ -545,7 +529,6 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
545529
case Matcher::CheckPredicate: {
546530
TreePredicateFn Pred = cast<CheckPredicateMatcher>(N)->getPredicate();
547531
unsigned OperandBytes = 0;
548-
unsigned PredNo = getNodePredicate(Pred);
549532

550533
if (Pred.usesOperands()) {
551534
unsigned NumOps = cast<CheckPredicateMatcher>(N)->getNumOperands();
@@ -554,15 +537,10 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
554537
OS << cast<CheckPredicateMatcher>(N)->getOperandNo(i) << ", ";
555538
OperandBytes = 1 + NumOps;
556539
} else {
557-
if (PredNo < 8) {
558-
OperandBytes = -1;
559-
OS << "OPC_CheckPredicate" << PredNo << ", ";
560-
} else
561-
OS << "OPC_CheckPredicate, ";
540+
OS << "OPC_CheckPredicate, ";
562541
}
563542

564-
if (PredNo >= 8 || Pred.usesOperands())
565-
OS << PredNo << ',';
543+
OS << getNodePredicate(Pred) << ',';
566544
if (!OmitComments)
567545
OS << " // " << Pred.getFnName();
568546
OS << '\n';
@@ -1051,7 +1029,8 @@ EmitMatcherList(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
10511029
}
10521030

10531031
void MatcherTableEmitter::EmitNodePredicatesFunction(
1054-
const std::vector<TreePattern *> &Preds, StringRef Decl, raw_ostream &OS) {
1032+
const std::vector<TreePredicateFn> &Preds, StringRef Decl,
1033+
raw_ostream &OS) {
10551034
if (Preds.empty())
10561035
return;
10571036

@@ -1061,7 +1040,7 @@ void MatcherTableEmitter::EmitNodePredicatesFunction(
10611040
OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
10621041
for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
10631042
// Emit the predicate code corresponding to this pattern.
1064-
TreePredicateFn PredFn(Preds[i]);
1043+
const TreePredicateFn PredFn = Preds[i];
10651044
assert(!PredFn.isAlwaysTrue() && "No code in this predicate");
10661045
std::string PredFnCodeStr = PredFn.getCodeToRunOnSDNode();
10671046

0 commit comments

Comments
 (0)