<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - TableGen: Matchables are not well ordered"
   href="http://llvm.org/bugs/show_bug.cgi?id=22796">22796</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TableGen: Matchables are not well ordered
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dblaikie@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dexonsmith@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>There appear to be contradictions in the ordering of matchables.

I found this when attempting to change the data structures for the matchables
(see the review thread for r222935)

By walking the 'sorted' list after the stable_sort of Matchables, I was able to
find places where the sorting was incomplete:

  std::stable_sort(Info.Matchables.begin(), Info.Matchables.end(),
                   [](const std::unique_ptr<MatchableInfo> &a,
                      const std::unique_ptr<MatchableInfo> &b){
                     return *a < *b;});

  for (auto I = Info.Matchables.begin(), E = Info.Matchables.end(); I != E;
       ++I) {
    for (auto J = I; J != E; ++J) {
      bool greater = **J < **I;
      assert(!greater);
    }
  }

I added further checks (which I've lost, but could help someone reconstruct if
they're interested) to try to find specific contradictions, especially in short
cycles. Here's one short cycle I found:

X:
Mnemonic: vshl
AsmOperands.size(): 4
AsmOperands[0].Class: MCK_CondCode
AsmOperands[1].Class: MCK__DOT_u64

X + 1:
Mnemonic: vshl
AsmOperands.size(): 4
AsmOperands[0].Class: MCK_CondCode
AsmOperands[1].Class: MCK__DOT_i64

X + 2:
Mnemonic: vshl
AsmOperands.size(): 4
AsmOperands[0].Class.MCK_CondCode
AsmOperands[1].Class.MCK_s8

(MCK__DOT_u64 < MCK__DOT_i64)
(MCK_s8 < MCK__DOT_u64)
(MCK__DOT_i64 < MCK__DOT_s8)

This is because:

u64 < i64: u64 is a subset of i64
i64 < s8: i64 and s8 are not subsets of each other, so order by ValueName
('.i64' < '.s8')
s8 < u64: s8 and u64 are not subsets of each other, so order by ValueName
('.u64' !< '.s8')</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>