<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 errors if operand with suboperands used without repeating type in output pattern"
   href="http://llvm.org/bugs/show_bug.cgi?id=21539">21539</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TableGen errors if operand with suboperands used without repeating type in output pattern
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>TableGen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Matthew.Arsenault@amd.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If you attempt to use a custom Operand type with suboperands, and don't repeat
the type in the output pattern, there is an error from operand number mismatch.
For any other operand type, just specifying the name of the operand in the
result is enough.

e.g.

def MEMOP  : Operand<iPTR> {
  let MIOperandInfo = (ops PtrRC:$base, PtrRC:$reg, PtrRC:$offset);
  let PrintMethod = "printAddrMode3Op";
}

// OK, MEMOP explicitly mentioned in output pattern
class LDPat<Instruction inst, SDPatternOperator ldnode, ValueType vt> : Pat <
  (vt (ldnode (LoadAddr MEMOP:$address))),
  (inst MEMOP:$address) 
<span class="quote">>;</span >

// Errors, the complex operand only counts towards one operand of the output
instruction and errors when it should count as 3
class LDPat<Instruction inst, SDPatternOperator ldnode, ValueType vt> : Pat <
  (vt (ldnode (LoadAddr MEMOP:$address))),
  (inst $address)
<span class="quote">>;</span >





The problem is in CodeGenDAGPatterns.cpp:

          if (Child->getNumMIResults(CDP) < NumArgs) {
            // Match first sub-operand against the child we already have.
            Record *SubRec = cast<DefInit>(MIOpInfo->getArg(0))->getDef();
            MadeChange |=
              Child->UpdateNodeTypeFromInst(ChildResNo, SubRec, TP);

            // And the remaining sub-operands against subsequent children.
            for (unsigned Arg = 1; Arg < NumArgs; ++Arg) {
              if (ChildNo >= getNumChildren()) {
                emitTooFewOperandsError(TP, getOperator()->getName(),
                                        getNumChildren());
                return false;
              }
              Child = getChild(ChildNo++);

              SubRec = cast<DefInit>(MIOpInfo->getArg(Arg))->getDef();
              MadeChange |=
                Child->UpdateNodeTypeFromInst(ChildResNo, SubRec, TP);
            }
            continue;
          }

In the working case with the explicitly specified Operand type,
Child->getNumMIResults(CDP)
returns the correct 3 from the isLeaf() / dyn_cast<DefInit>() path. In the
broken case, this only returns 1 where the leaf is an UnsetInit. I'm not really
sure what this is attempting to do in the case where
Child->getNumMIResults(CDP) < NumArgs). Is it trying to allow using multiple
operands that together make up the components of a single complex operand?</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>