diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -4310,7 +4310,8 @@ std::vector Copy; PatternsToMatch.swap(Copy); - auto AppendPattern = [this, &ModeChecks](PatternToMatch &P, unsigned Mode) { + auto AppendPattern = [this](PatternToMatch &P, unsigned Mode, + const std::vector &Check) { TreePatternNodePtr NewSrc = P.getSrcPattern()->clone(); TreePatternNodePtr NewDst = P.getDstPattern()->clone(); if (!NewSrc->setDefaultMode(Mode) || !NewDst->setDefaultMode(Mode)) { @@ -4318,8 +4319,7 @@ } std::vector Preds = P.getPredicates(); - const std::vector &MC = ModeChecks[Mode]; - llvm::append_range(Preds, MC); + llvm::append_range(Preds, Check); PatternsToMatch.emplace_back(P.getSrcRecord(), std::move(Preds), std::move(NewSrc), std::move(NewDst), P.getDstRegs(), @@ -4355,31 +4355,31 @@ // duplicated patterns with different predicate checks, construct the // default check as a negation of all predicates that are actually present // in the source/destination patterns. - std::vector DefaultPred; + std::vector DefaultCheck; for (unsigned M : Modes) { if (M == DefaultMode) continue; - if (ModeChecks.find(M) != ModeChecks.end()) - continue; - // Fill the map entry for this mode. const HwMode &HM = CGH.getMode(M); - ModeChecks[M].emplace_back(Predicate(HM.Features, true)); + if (ModeChecks.find(M) == ModeChecks.end()) { + // Fill the map entry for this mode. + ModeChecks[M].emplace_back(Predicate(HM.Features, true)); + } // Add negations of the HM's predicates to the default predicate. - DefaultPred.emplace_back(Predicate(HM.Features, false)); + DefaultCheck.emplace_back(Predicate(HM.Features, false)); } for (unsigned M : Modes) { if (M == DefaultMode) continue; - AppendPattern(P, M); + AppendPattern(P, M, ModeChecks[M]); } bool HasDefault = Modes.count(DefaultMode); if (HasDefault) - AppendPattern(P, DefaultMode); + AppendPattern(P, DefaultMode, DefaultCheck); } }