[llvm-commits] [llvm] r97509 - in /llvm/trunk: test/CodeGen/Alpha/add.ll utils/TableGen/CodeGenDAGPatterns.cpp utils/TableGen/CodeGenDAGPatterns.h utils/TableGen/DAGISelEmitter.cpp utils/TableGen/Record.h

Chris Lattner sabre at nondot.org
Mon Mar 1 14:09:11 PST 2010


Author: lattner
Date: Mon Mar  1 16:09:11 2010
New Revision: 97509

URL: http://llvm.org/viewvc/llvm-project?rev=97509&view=rev
Log:
Fix PR2590 by making PatternSortingPredicate actually be 
ordered correctly.  Previously it would get in trouble when
two patterns were too similar and give them nondet ordering.
We force this by using the record ID order as a fallback.

The testsuite diff is due to alpha patterns being ordered
slightly differently, the change is a semantic noop afaict:

< 	lda $0,-100($16)
---
> 	subq $16,100,$0


Modified:
    llvm/trunk/test/CodeGen/Alpha/add.ll
    llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
    llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
    llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
    llvm/trunk/utils/TableGen/Record.h

Modified: llvm/trunk/test/CodeGen/Alpha/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Alpha/add.ll?rev=97509&r1=97508&r2=97509&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Alpha/add.ll (original)
+++ llvm/trunk/test/CodeGen/Alpha/add.ll Mon Mar  1 16:09:11 2010
@@ -4,9 +4,8 @@
 ; RUN: grep {	addl} %t.s | count 2
 ; RUN: grep {	addq} %t.s | count 2
 ; RUN: grep {	subl} %t.s | count 2
-; RUN: grep {	subq} %t.s | count 1
+; RUN: grep {	subq} %t.s | count 2
 ;
-; RUN: grep {lda \$0,-100(\$16)} %t.s | count 1
 ; RUN: grep {s4addl} %t.s | count 2
 ; RUN: grep {s8addl} %t.s | count 2
 ; RUN: grep {s4addq} %t.s | count 2

Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=97509&r1=97508&r2=97509&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Mon Mar  1 16:09:11 2010
@@ -2110,7 +2110,8 @@
                                      SrcPattern,
                                      TheInst.getResultPattern(),
                                      TheInst.getImpResults(),
-                                     Instr->getValueAsInt("AddedComplexity")));
+                                     Instr->getValueAsInt("AddedComplexity"),
+                                     Instr->getID()));
   }
 }
 
@@ -2320,7 +2321,8 @@
                  PatternToMatch(Patterns[i]->getValueAsListInit("Predicates"),
                                 Pattern->getTree(0),
                                 Temp.getOnlyTree(), InstImpResults,
-                                Patterns[i]->getValueAsInt("AddedComplexity")));
+                                Patterns[i]->getValueAsInt("AddedComplexity"),
+                                Patterns[i]->getID()));
   }
 }
 
@@ -2614,7 +2616,8 @@
         push_back(PatternToMatch(PatternsToMatch[i].getPredicates(),
                                  Variant, PatternsToMatch[i].getDstPattern(),
                                  PatternsToMatch[i].getDstRegs(),
-                                 PatternsToMatch[i].getAddedComplexity()));
+                                 PatternsToMatch[i].getAddedComplexity(),
+                                 Record::getNewUID()));
     }
 
     DEBUG(errs() << "\n");

Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=97509&r1=97508&r2=97509&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Mon Mar  1 16:09:11 2010
@@ -476,15 +476,16 @@
   PatternToMatch(ListInit *preds,
                  TreePatternNode *src, TreePatternNode *dst,
                  const std::vector<Record*> &dstregs,
-                 unsigned complexity):
-    Predicates(preds), SrcPattern(src), DstPattern(dst), Dstregs(dstregs),
-    AddedComplexity(complexity) {}
+                 unsigned complexity, unsigned uid)
+    : Predicates(preds), SrcPattern(src), DstPattern(dst),
+      Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {}
 
   ListInit        *Predicates;  // Top level predicate conditions to match.
   TreePatternNode *SrcPattern;  // Source pattern to match.
   TreePatternNode *DstPattern;  // Resulting pattern.
   std::vector<Record*> Dstregs; // Physical register defs being matched.
   unsigned         AddedComplexity; // Add to matching pattern complexity.
+  unsigned         ID;          // Unique ID for the record.
 
   ListInit        *getPredicates() const { return Predicates; }
   TreePatternNode *getSrcPattern() const { return SrcPattern; }

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=97509&r1=97508&r2=97509&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Mon Mar  1 16:09:11 2010
@@ -174,8 +174,14 @@
     if (LHSCost < RHSCost) return true;
     if (LHSCost > RHSCost) return false;
     
-    return getResultPatternSize(LHS->getDstPattern(), CGP) <
-           getResultPatternSize(RHS->getDstPattern(), CGP);
+    unsigned LHSPatSize = getResultPatternSize(LHS->getDstPattern(), CGP);
+    unsigned RHSPatSize = getResultPatternSize(RHS->getDstPattern(), CGP);
+    if (LHSPatSize < RHSPatSize) return true;
+    if (LHSPatSize > RHSPatSize) return false;
+    
+    // Sort based on the UID of the pattern, giving us a deterministic ordering.
+    assert(LHS->ID != RHS->ID);
+    return LHS->ID < RHS->ID;
   }
 };
 }

Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=97509&r1=97508&r2=97509&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Mon Mar  1 16:09:11 2010
@@ -1225,6 +1225,10 @@
     ID(LastID++), Name(N), Loc(loc) {}
   ~Record() {}
 
+  
+  static unsigned getNewUID() { return LastID++; }
+    
+    
   unsigned getID() const { return ID; }
 
   const std::string &getName() const { return Name; }





More information about the llvm-commits mailing list