<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Ericsson Hilda";
        panose-1:0 0 5 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New",serif;}
tt
        {mso-style-priority:99;
        font-family:"Courier New",serif;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.xapple-converted-space
        {mso-style-name:x_apple-converted-space;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle23
        {mso-style-type:personal-compose;
        font-family:"Times New Roman",serif;
        color:black;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=SV link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>Hi Daniel,<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>Thanks for replying; I was hoping to get in touch with you on this issue.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>I had a look at how SelectionIDAG does it when generating the matcher table, and it does consider the implicit defs as additional output. Here is the match table generated for the pattern:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*     0*/ OPC_CheckOpcode, TARGET_VAL(ISD::SIGN_EXTEND),<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*     3*/ OPC_MoveChild0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*     4*/ OPC_CheckOpcode, TARGET_VAL(ISD::SHL),<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*     7*/ OPC_MoveChild0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*     8*/ OPC_CheckOpcode, TARGET_VAL(ISD::ANY_EXTEND),<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    11*/ OPC_RecordChild0, // #0 = $src<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    12*/ OPC_CheckChild0Type, MVT::i16,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    14*/ OPC_MoveParent,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    15*/ OPC_RecordChild1, // #1 = $imm<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    16*/ OPC_MoveChild1,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    17*/ OPC_CheckOpcode, TARGET_VAL(ISD::Constant),<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    20*/ OPC_CheckPredicate, 0, // Predicate_Imm_17_31_i16<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    22*/ OPC_CheckType, MVT::i16,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    24*/ OPC_MoveParent,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    25*/ OPC_CheckType, MVT::i32,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    27*/ OPC_MoveParent,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    28*/ OPC_CheckType, MVT::i40,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    30*/ OPC_EmitNode1, TARGET_VAL(TargetOpcode::IMPLICIT_DEF), 0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i40, 0/*#Ops*/,  // Results = #2<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    36*/ OPC_EmitNode1, TARGET_VAL(TargetOpcode::IMPLICIT_DEF), 0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i32, 0/*#Ops*/,  // Results = #3<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    42*/ OPC_EmitInteger, MVT::i32, OurTarget::hi16, // Results = #4<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    45*/ OPC_EmitNode1, TARGET_VAL(TargetOpcode::INSERT_SUBREG), 0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i32, 3/*#Ops*/, 3, 0, 4,  // Results = #5<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    54*/ OPC_EmitNode1, TARGET_VAL(OurTarget::clearLo32_pseudo), 0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i32, 1/*#Ops*/, 5,  // Results = #6<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    61*/ OPC_EmitInteger, MVT::i16, 0, <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    64*/ OPC_EmitRegister, MVT::i16, 0 /*zero_reg*/,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    67*/ OPC_EmitInteger, MVT::i16, 0, <o:p></o:p></span></p></div><div><p class=MsoNormal><b><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    70*/ OPC_EmitNode2, TARGET_VAL(OurTarget::shfts_a32_imm7), 0,<o:p></o:p></span></b></p></div><div><p class=MsoNormal><b><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i32, MVT::i16, 5/*#Ops*/, 6, 1, 7, 8, 9,  // Results = #10 #11<o:p></o:p></span></b></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    82*/ OPC_EmitInteger, MVT::i32, OurTarget::acc,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    85*/ OPC_EmitNode1, TARGET_VAL(TargetOpcode::INSERT_SUBREG), 0,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i40, 3/*#Ops*/, 2, 10, 12,  // Results = #13<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    94*/ OPC_EmitInteger, MVT::i16, 0, <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    97*/ OPC_EmitRegister, MVT::i16, 0 /*zero_reg*/,<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*   100*/ OPC_EmitInteger, MVT::i16, 0, <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*   103*/ OPC_MorphNodeTo1, TARGET_VAL(OurTarget::sext_a32), 0,<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>               MVT::i40, 4/*#Ops*/, 13, 14, 15, 16, ...<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>The line of interest here is the one below </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*    70 */</span><span lang=EN-US style='font-size:12.0pt;color:black'>. There, we can see that the instruction produces two results of type </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>MVT::i32</span><span lang=EN-US style='font-size:12.0pt;color:black'> (the value produced by the instruction) respectively </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>MVT::i16</span><span lang=EN-US style='font-size:12.0pt;color:black'> (the CCReg updated by the instruction). These are labeled as results </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>#10</span><span lang=EN-US style='font-size:12.0pt;color:black'> respectively </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>#11</span><span lang=EN-US style='font-size:12.0pt;color:black'>. Looking at operand identifiers after </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>/*#Ops*/</span><span lang=EN-US style='font-size:12.0pt;color:black'>, we can see that only </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>#10</span><span lang=EN-US style='font-size:12.0pt;color:black'> is used by the rest of the resulting pattern (by </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>INSERT_SUBREG</span><span lang=EN-US style='font-size:12.0pt;color:black'>), which is as intended.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>However, in the destination pattern declared in the *.td file, there is no information pertaining to which of the results should be used by the parent node. Since only tree-shaped patterns are allowed, SelectionIDAG must somehow decide which of the results are to be used by the parent node. And this decision is taken at lines 869-870 in </span><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>DAGISelMatcherGen.cpp</span><span lang=EN-US style='font-size:12.0pt;color:black'>: <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>    ...<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>    unsigned FinalNumOps = InstOps.size() + NumSubOps;<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>    while (InstOps.size() < FinalNumOps) {<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      const TreePatternNode *Child = N->getChild(ChildNo);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      unsigned BeforeAddingNumOps = InstOps.size();<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      EmitResultOperand(Child, InstOps);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      assert(InstOps.size() > BeforeAddingNumOps && "Didn't add any operands");<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      // If the operand is an instruction and it produced multiple results, just<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      // take the first one.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      if (!Child->isLeaf() && Child->getOperator()->isSubClassOf("Instruction"))<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>        InstOps.resize(BeforeAddingNumOps+1);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>      ++ChildNo;<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>    }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;font-family:"Courier New",serif;color:black'>    ...<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>In other words, if a child produces more than one result SelectionIDAG always takes the first result. Those two lines originate from a patch by Chris Lattner (r99725), so presumably this is the correct way of doing it. If GlobalISel were to do the same, it would solve the issue I'm having with our patterns.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>Best regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'>Gabriel<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:black'><o:p> </o:p></span></p></div><div class=MsoNormal align=center style='text-align:center'><hr size=2 width="98%" align=center></div><div id=divRplyFwdMsg><p class=MsoNormal><b><span lang=EN-US style='color:black'>From:</span></b><span lang=EN-US style='color:black'> Daniel Sanders <daniel_l_sanders@apple.com><br><b>Sent:</b> Friday, June 5, 2020 9:02 PM<br><b>To:</b> Quentin Colombet <qcolombet@apple.com><br><b>Cc:</b> Dominik Montada <dominik.montada@hightec-rt.com>; Gabriel Hjort Åkerlund <gabriel.hjort.akerlund@ericsson.com>; llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br><b>Subject:</b> Re: [llvm-dev] Nested instruction patterns rejected by GlobalISel when having registers in Defs</span><span lang=EN-US> <o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div></div><div><div><p class=MsoNormal><span lang=EN-US>The implicit defs don't participate much in the patterns. For the most part it's just read into CodeGenInstruction::ImplicitDefs and then GlobalISel gathers and adds them all at the end. I think I do see the code Gabriel is referring to though.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>GetNumNodeResults() has:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>    if (InstInfo.HasOneImplicitDefWithKnownVT(CDP.getTargetInfo()) !=MVT::Other)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>      ++NumDefsToAdd;<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>and ultimately this VT gets into Types via UpdateNodeType(). I have no idea why this code does this as I don't really see why the VT matters to how you treat an implicit def. This code dates back to 2010 (r99726) and that commit called it 'funky logic' so it's unlikely that we'll find someone that remembers it.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Does your CCReg need to have a specific type? If not, then you could make it MVT::Other and the problem should go away.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Have you looked into how DAGISel supports these patterns? This code is common between DAGISel and GlobalISel so given that DAGISel works it must be doing something to handle this that's missing from GlobalISel.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US><br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span lang=EN-US>On 5 Jun 2020, at 11:02, Quentin Colombet <</span><a href="mailto:qcolombet@apple.com"><span lang=EN-US>qcolombet@apple.com</span></a><span lang=EN-US>> wrote:<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><div><div><p class=MsoNormal><span lang=EN-US>+ Daniel who knows the most about the table gen importer<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-US><br><br><o:p></o:p></span></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span lang=EN-US>On Jun 5, 2020, at 12:48 AM, Dominik Montada via llvm-dev <</span><a href="mailto:llvm-dev@lists.llvm.org"><span lang=EN-US>llvm-dev@lists.llvm.org</span></a><span lang=EN-US>> wrote:<o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><div><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Hi Gabriel,<o:p></o:p></span></p><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Your comment made me take a look at our instruction definitions and patterns in a little bit more detail. And while we do use nested patterns with INSERT_SUBREG, apparently none of those patterns use instructions with implicit-defs. Sorry for misleading you there by a wrong assumption on my part.<o:p></o:p></span></p><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>However, I still find it strange that TableGen should reject such a pattern. I'm really not sure if this is simply an overlooked use-case or if there is some real reasoning behind this logic. If it were an actual output register I could understand it, but since this is an implicit one it should not impact the pattern in my opinion.<o:p></o:p></span></p><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Sorry for not being able to help out with the actual problem after all!<o:p></o:p></span></p><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Cheers,<o:p></o:p></span></p><p class=MsoNormal style='font-variant-caps:normal;text-align:start;word-spacing:0px'><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Dominik<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Am 04.06.20 um 15:06 schrieb Gabriel Hjort Åkerlund:<o:p></o:p></span></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt;font-variant-caps:normal;orphans:auto;text-align:start;widows:auto;word-spacing:0px'><div><div><p class=MsoNormal><span lang=EN-US>Hi Dominik,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Thanks for your reply.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>In my case, the<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-family:"Courier New",serif'>Defs</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>is the cause of the problem. Or rather, it is part of the problem, because when I remove it from the instruction TableGen gives me a different error message which concerns a part which is deeper into the pattern tree, so at least it is able to proceed beyond that part of the pattern. I have also stepped TableGen inside<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-family:"Courier New",serif'>gdb</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>and verified that having Defs causes GlobalISel to include<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-family:"Courier New",serif'>CCReg</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>in the<span class=xapple-converted-space> </span></span><span lang=EN-US>Types</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>field of the<span class=xapple-converted-space> </span></span><span lang=EN-US>TreePatternNode</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>corresponding to the instruction, which is what GlobalISel looks at to subsequently reject the pattern on basis that the instruction produces multiple results.</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>But from your comment, I take it that the<span class=xapple-converted-space> </span>Defs</span><span class=xapple-converted-space><span lang=EN-US style='font-family:"Ericsson Hilda",serif'> </span></span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>field should never be considered actual output, is that correct? If so, I find it strange that<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-family:"Courier New",serif'>CodeGenDAGPatterns</span><span lang=EN-US style='font-family:"Ericsson Hilda",serif'>, which parses the patterns, takes the CCReg into consideration as additional results. I am tempted to modify that part of the code, but maybe I’m missing some invariant that’s not immediately evident…</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Cheers,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>Gabriel<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><div><p class=MsoNormal><b><span lang=EN-US>From:</span></b><span class=xapple-converted-space><span lang=EN-US> </span></span><span lang=EN-US>Dominik Montada<span class=xapple-converted-space> </span><a href="mailto:dominik.montada@hightec-rt.com"><span style='color:#954F72'><dominik.montada@hightec-rt.com></span></a><span class=xapple-converted-space> </span><br><b>Sent:</b><span class=xapple-converted-space> </span>den 4 juni 2020 14:51<br><b>To:</b><span class=xapple-converted-space> </span><a href="mailto:llvm-dev@lists.llvm.org"><span style='color:#954F72'>llvm-dev@lists.llvm.org</span></a><br><b>Cc:</b><span class=xapple-converted-space> </span>Gabriel Hjort Åkerlund<span class=xapple-converted-space> </span><a href="mailto:gabriel.hjort.akerlund@ericsson.com"><span style='color:#954F72'><gabriel.hjort.akerlund@ericsson.com></span></a><br><b>Subject:</b><span class=xapple-converted-space> </span>Re: [llvm-dev] Nested instruction patterns rejected by GlobalISel when having registers in Defs<o:p></o:p></span></p></div></div></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Hi Gabriel,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>I'm working on a downstream target which uses GlobalISel and we have many patterns with instructions that also define a system register as a side-effect and use them without any problem. Since CCReg is not an actual output of the instruction, but an implicit definition, GlobalISel should have no trouble with it, so I'm guessing your problem lies somewhere. Have you tried running the tablegen command manually and looked at the output there?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>The command is<span class=xapple-converted-space> </span></span><tt><span lang=EN-US style='font-size:10.0pt'>llvm-tblgen -gen-global-isel <couple of -I flags> <your_target>.td --write-if-changed --warn-on-skipped-patterns</span></tt><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>I can't tell you exactly what -I flags you'll need but if you run ninja in verbose mode or look at the ninja build log, you should be able to see what is being used.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Word of caution however: sometimes TableGen gives you a very clear error message indicating what is wrong, sometimes it gives you a very cryptic error message. And sometimes it doesn't even give you that and behave as if everything is a-ok while it still hasn't included your pattern. I have lost countless hours trying to debug TableGen patterns with GlobalISel and there's still a lot of stuff that GlobalISel unfortunately does not support yet in TableGen. So be prepared to write some C++ code for the unsupported cases for the moment.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Cheers,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>Dominik<o:p></o:p></span></p><div><div><p class=MsoNormal>Am 04.06.20 um 14:34 schrieb Gabriel Hjort Åkerlund via llvm-dev:<o:p></o:p></p></div></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span lang=EN-US>Hi,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>I am in the process of porting our target to GlobalISel, and have encountered a problem. Nearly all instructions in our instruction set make modifications to a CC register, and hence are defined as follows:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US> <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>let ..., Defs = [CCReg] in<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US>def shfts_a32_imm7: Instruction<(outs OurRC:$dst), ...>;<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>What’s more, many of these instructions have patterns where the instruction itself appears inside a nested tree, e.g.:</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt'>def Pat<(source pattern ...),</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt'>       <span class=xapple-converted-space> </span>(sext_a32 (INSERT_SUBREG (...), (shfts_a32_imm7 OurRC:$src, Imm7:$imm), ...>;</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>Now to the problem: When TableGen processes the instruction above, it includes the<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>CCReg</span><span class=xapple-converted-space><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span></span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>in the<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>Defs</span><span class=xapple-converted-space><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span></span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>field along with the registers appearing in<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>outs</span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>, thereby indicating that shfts_a32_imm7 produces two results. Currently, the GlobalISel-backend in TableGen requires that nested instructions appearing in the output pattern produce exactly one result. Consequently, TableGen rejects many of our patterns. But in reality, the instruction really only produces a single result and therefore this pattern should be allowed.</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>So I wonder, how should registers appear in<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>Defs</span><span class=xapple-converted-space><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span></span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>be treated? Are they equal to those appearing in<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>outs</span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>, and therefore interchangeable, or is it valid to disambiguate between them and therefore modify TableGen to only consider<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt'>outs<span class=xapple-converted-space> </span></span><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>as the result of interest when processing the patterns?</span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'>Gabriel Hjort Åkerlund</span></b><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#181818'> </span><span lang=EN-US><o:p></o:p></span></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US><o:p> </o:p></span></p></div><pre><span lang=EN-US>_______________________________________________<o:p></o:p></span></pre><pre><span lang=EN-US>LLVM Developers mailing list<o:p></o:p></span></pre><pre><a href="mailto:llvm-dev@lists.llvm.org"><span lang=EN-US style='color:#954F72'>llvm-dev@lists.llvm.org</span></a><span lang=EN-US><o:p></o:p></span></pre><pre><a href="https://protect2.fireeye.com/v1/url?k=52e18446-0c413e28-52e1c4dd-86b1886cfa64-f424e731a80348bd&q=1&e=238953c8-f0ec-4510-8c97-620bfb03d5be&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev"><span lang=EN-US style='color:#954F72'>https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><span lang=EN-US><o:p></o:p></span></pre></blockquote><pre>-- <o:p></o:p></pre><pre>----------------------------------------------------------------------<o:p></o:p></pre><pre>Dominik Montada                   Email: <a href="mailto:dominik.montada@hightec-rt.com"><span style='color:#954F72'>dominik.montada@hightec-rt.com</span></a><o:p></o:p></pre><pre><span lang=EN-US>HighTec EDV-Systeme GmbH          Phone: +49 681 92613 19<o:p></o:p></span></pre><pre>Europaallee 19                    Fax:   +49-681-92613-26<o:p></o:p></pre><pre>D-66113 Saarbrücken               WWW: <a href="https://protect2.fireeye.com/v1/url?k=a0228059-fe823a37-a022c0c2-86b1886cfa64-48b7aa6978940111&q=1&e=238953c8-f0ec-4510-8c97-620bfb03d5be&u=http%3A%2F%2Fwww.hightec-rt.com%2F"><span style='color:#954F72'>http://www.hightec-rt.com</span></a><o:p></o:p></pre><pre> <o:p></o:p></pre><pre><span lang=EN-US>Managing Director: Vera Strothmann<o:p></o:p></span></pre><pre><span lang=EN-US>Register Court: Saarbrücken, HRB 10445, VAT ID: DE 138344222<o:p></o:p></span></pre><pre><span lang=EN-US> <o:p></o:p></span></pre><pre><span lang=EN-US>This e-mail may contain confidential and/or privileged information. If<o:p></o:p></span></pre><pre><span lang=EN-US>you are not the intended recipient please notify the sender immediately<o:p></o:p></span></pre><pre><span lang=EN-US>and destroy this e-mail. Any unauthorised copying, disclosure or<o:p></o:p></span></pre><pre><span lang=EN-US>distribution of the material in this e-mail is strictly forbidden.<o:p></o:p></span></pre><pre>--- <o:p></o:p></pre></div></blockquote><pre style='font-variant-caps:normal;text-align:start;word-spacing:0px'>-- <o:p></o:p></pre><pre>----------------------------------------------------------------------<o:p></o:p></pre><pre>Dominik Montada                   Email: <a href="mailto:dominik.montada@hightec-rt.com"><span style='color:#954F72'>dominik.montada@hightec-rt.com</span></a><o:p></o:p></pre><pre><span lang=EN-US>HighTec EDV-Systeme GmbH          Phone: +49 681 92613 19<o:p></o:p></span></pre><pre>Europaallee 19                    Fax:   +49-681-92613-26<o:p></o:p></pre><pre>D-66113 Saarbrücken               WWW: <a href="https://protect2.fireeye.com/v1/url?k=b7cd53d5-e96de9bb-b7cd134e-861d41abace8-5636b949d44c6f9b&q=1&e=9aff5cfa-72fd-4986-af7c-78b27f9ea1e8&u=http%3A%2F%2Fwww.hightec-rt.com%2F"><span style='color:#954F72'>http://www.hightec-rt.com</span></a><o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span lang=EN-US>Managing Director: Vera Strothmann<o:p></o:p></span></pre><pre><span lang=EN-US>Register Court: Saarbrücken, HRB 10445, VAT ID: DE 138344222<o:p></o:p></span></pre><pre><span lang=EN-US><o:p> </o:p></span></pre><pre><span lang=EN-US>This e-mail may contain confidential and/or privileged information. If<o:p></o:p></span></pre><pre><span lang=EN-US>you are not the intended recipient please notify the sender immediately<o:p></o:p></span></pre><pre><span lang=EN-US>and destroy this e-mail. Any unauthorised copying, disclosure or<o:p></o:p></span></pre><pre><span lang=EN-US>distribution of the material in this e-mail is strictly forbidden.<o:p></o:p></span></pre><pre><span lang=EN-US>--- <o:p></o:p></span></pre><p class=MsoNormal><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>_______________________________________________<br>LLVM Developers mailing list<br></span><a href="mailto:llvm-dev@lists.llvm.org"><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#954F72'>llvm-dev@lists.llvm.org</span></a><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif'><br></span><a href="https://protect2.fireeye.com/v1/url?k=b3d033f0-ed70899e-b3d0736b-861d41abace8-91f0c9908116c6fb&q=1&e=9aff5cfa-72fd-4986-af7c-78b27f9ea1e8&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev"><span lang=EN-US style='font-size:9.0pt;font-family:"Helvetica",sans-serif;color:#954F72'>https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><span lang=EN-US><o:p></o:p></span></p></div></blockquote></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></div></blockquote></div><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></div></body></html>