Teach the grouper some simple tricks about looking contradictory
predicates.  For example if we have:

Scope:
  CheckType i32
    ABC
  CheckType f32
    DEF
  CheckType i32
    GHI

Then we know that we can transform this into:
Scope:
  CheckType i32
    Scope
      ABC
      GHI
  CheckType f32
    DEF

This reorders the check for the 'GHI' predicate above
the check for the 'DEF' predidate.  However it is safe to do this
in this situation because we know that a node cannot have both an
i32 and f32 type.

We're now doing more factoring that the old isel did.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97312 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/DAGISelMatcher.cpp b/utils/TableGen/DAGISelMatcher.cpp
index 561d612..dfb2361 100644
--- a/utils/TableGen/DAGISelMatcher.cpp
+++ b/utils/TableGen/DAGISelMatcher.cpp
@@ -25,6 +25,10 @@
     return Next->print(OS, indent);
 }
 
+void Matcher::printOne(raw_ostream &OS) const {
+  printImpl(OS, 0);
+}
+
 ScopeMatcher::~ScopeMatcher() {
   for (unsigned i = 0, e = Children.size(); i != e; ++i)
     delete Children[i];
@@ -253,3 +257,54 @@
   return HashUnsigneds(Results.begin(), Results.end()) ^ 
           ((unsigned)(intptr_t)&Pattern << 8);
 }
+
+// isContradictoryImpl Implementations.
+
+bool CheckOpcodeMatcher::isContradictoryImpl(const Matcher *M) const {
+  if (const CheckOpcodeMatcher *COM = dyn_cast<CheckOpcodeMatcher>(M)) {
+    // One node can't have two different opcodes!
+    return COM->getOpcodeName() != getOpcodeName();
+  }
+  
+  // TODO: CheckMultiOpcodeMatcher?
+  // TODO: CheckType?
+  return false;
+}
+
+static bool TypesAreContradictory(MVT::SimpleValueType T1,
+                                  MVT::SimpleValueType T2) {
+  // If the two types are the same, then they are the same, so they don't
+  // contradict.
+  if (T1 == T2) return false;
+  
+  // If either type is about iPtr, then they don't conflict unless the other
+  // one is not a scalar integer type.
+  if (T1 == MVT::iPTR)
+    return !MVT(T2).isInteger() || MVT(T2).isVector();
+  
+  if (T2 == MVT::iPTR)
+    return !MVT(T1).isInteger() || MVT(T1).isVector();
+  
+  // Otherwise, they are two different non-iPTR types, they conflict.
+  return true;
+}
+
+bool CheckTypeMatcher::isContradictoryImpl(const Matcher *M) const {
+  if (const CheckTypeMatcher *CT = dyn_cast<CheckTypeMatcher>(M))
+    return TypesAreContradictory(getType(), CT->getType());
+  return false;
+}
+
+bool CheckChildTypeMatcher::isContradictoryImpl(const Matcher *M) const {
+  if (const CheckChildTypeMatcher *CC = dyn_cast<CheckChildTypeMatcher>(M)) {
+    // If the two checks are about different nodes, we don't know if they
+    // conflict!
+    if (CC->getChildNo() != getChildNo())
+      return false;
+    
+    return TypesAreContradictory(getType(), CC->getType());
+  }
+  return false;
+}
+  
+