From 0e1813390520a06820070188829c46ce9c7dbd28 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 16 Aug 2018 16:16:28 +0000 Subject: [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 --- llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'llvm/utils/TableGen/CodeGenDAGPatterns.cpp') diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index 5bf84da218e..4ef437523d5 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -198,16 +198,18 @@ void TypeSetByHwMode::writeToStream(const SetType &S, raw_ostream &OS) { } bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const { - bool HaveDefault = hasDefault(); - if (HaveDefault != VTS.hasDefault()) + // The isSimple call is much quicker than hasDefault - check this first. + bool IsSimple = isSimple(); + bool VTSIsSimple = VTS.isSimple(); + if (IsSimple && VTSIsSimple) + return *begin() == *VTS.begin(); + + // Speedup: We have a default if the set is simple. + bool HaveDefault = IsSimple || hasDefault(); + bool VTSHaveDefault = VTSIsSimple || VTS.hasDefault(); + if (HaveDefault != VTSHaveDefault) return false; - if (isSimple()) { - if (VTS.isSimple()) - return *begin() == *VTS.begin(); - return false; - } - SmallDenseSet Modes; for (auto &I : *this) Modes.insert(I.first); -- cgit v1.2.3