- // If we're scannig for a type comparison and the type comparison got
- // moved late, see if we can pull it up.
- if (isa<CheckTypeMatcher>(Optn)) {
- CheckTypeMatcher *CTM = FindCheckType(OptionsToMatch[Scan]);
- if (CTM != 0 && CTM != OptionsToMatch[Scan] &&
- CTM->canMoveBefore(OptionsToMatch[Scan])) {
- Matcher *MatcherWithoutCTM = OptionsToMatch[Scan]->unlinkNode(CTM);
- CTM->setNext(MatcherWithoutCTM);
- OptionsToMatch[Scan] = CTM;
+ // If we're scanning for a simple node, see if it occurs later in the
+ // sequence. If so, and if we can move it up, it might be contradictory
+ // or the same as what we're looking for. If so, reorder it.
+ if (Optn->isSimplePredicateOrRecordNode()) {
+ Matcher *M2 = FindNodeWithKind(ScanMatcher, Optn->getKind());
+ if (M2 != 0 && M2 != ScanMatcher &&
+ M2->canMoveBefore(ScanMatcher) &&
+ (M2->isEqual(Optn) || M2->isContradictory(Optn))) {
+ Matcher *MatcherWithoutM2 = ScanMatcher->unlinkNode(M2);
+ M2->setNext(MatcherWithoutM2);
+ OptionsToMatch[Scan] = M2;