Skip to content

Commit 0e18133

Browse files
committedAug 16, 2018
[TableGen] TypeSetByHwMode::operator== optimization
This operator is called a great deal, by checking for the cheap isSimple equality cases first (a common occurrence) we can improve performance as we avoid a lot of std::map find/iteration in hasDefault. isSimple also means that a default value is present, so we can avoid some hasDefault calls. This also avoids a rather dodgy piece of logic that was checking for isSimple() && !VTS.isSimple() but not the inverse - it now uses the general hasDefault mode comparison test instead. Saves around 15secs in debug builds of x86 -gen-dag-isel. Differential Revision: https://reviews.llvm.org/D50841 llvm-svn: 339890
1 parent 0ea8d8b commit 0e18133

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎llvm/utils/TableGen/CodeGenDAGPatterns.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,18 @@ void TypeSetByHwMode::writeToStream(const SetType &S, raw_ostream &OS) {
198198
}
199199

200200
bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const {
201-
bool HaveDefault = hasDefault();
202-
if (HaveDefault != VTS.hasDefault())
201+
// The isSimple call is much quicker than hasDefault - check this first.
202+
bool IsSimple = isSimple();
203+
bool VTSIsSimple = VTS.isSimple();
204+
if (IsSimple && VTSIsSimple)
205+
return *begin() == *VTS.begin();
206+
207+
// Speedup: We have a default if the set is simple.
208+
bool HaveDefault = IsSimple || hasDefault();
209+
bool VTSHaveDefault = VTSIsSimple || VTS.hasDefault();
210+
if (HaveDefault != VTSHaveDefault)
203211
return false;
204212

205-
if (isSimple()) {
206-
if (VTS.isSimple())
207-
return *begin() == *VTS.begin();
208-
return false;
209-
}
210-
211213
SmallDenseSet<unsigned, 4> Modes;
212214
for (auto &I : *this)
213215
Modes.insert(I.first);

0 commit comments

Comments
 (0)
Please sign in to comment.