<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 http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (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:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* 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;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.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="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">It seems that the checks performed at the beginning of WalkChainUsers() make the hypothesis that at least one parameters.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">These  checks make use of ChainedNode->use_begin. If parameters are used this iterator points to CopyToReg node of the first parameter.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">If no parameter, this iterator points to the call node and return InducesCycle error code.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Here is a source code with no parameter that reproduces the problem.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">declare void @foo32_2()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">define i32 @calli32_stack() {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">    call void @foo32_2()<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">    ret i32 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">In using LLVM version 3.8, this problem affects most the architecture that I’ve investigated.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Dominique Torette
<br>
<b>Sent:</b> mercredi 6 septembre 2017 18:15<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Cc:</b> Roel Jordans (r.jordans@tue.nl)<br>
<b>Subject:</b> OPC_EmitMergeInputChains1_0 failed while lowering callseq_start<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m lowering the ‘callseq_start’ and ‘callseq_end’ using nodes/patterns and the SelectCodeCommon().<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">‘callseq_end’ is well morphed into an architecture specific ADJCALLSTACKUP PseudoInstruction.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ISEL: Starting pattern match on root node: t9: ch,glue = callseq_end t8, TargetConstant:i16<0>, TargetConstant:i16<0>, t8:1<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">  <span style="background:lime;mso-highlight:lime">Morphed node: t9: ch,glue = ADJCALLSTACKUP TargetConstant:i16<0>, TargetConstant:i16<0>, t8, t8:1</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">‘callseq_start’ failed to be morphed into ADJCALLSTACKDOWN :-/<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="background:yellow;mso-highlight:yellow">LLVM ERROR: Cannot select: t6: ch,glue = callseq_start t0, TargetConstant:i16<0><o:p></o:p></span></p>
<p class="MsoNormal"><span style="background:yellow;mso-highlight:yellow">  t5: i16 = TargetConstant<0></span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here is the debug trace of the matching. It should match at 280, but failed at 279 on
<u><span style="font-size:10.0pt;font-family:"Courier New";color:black;background:yellow;mso-highlight:yellow">OPC_EmitMergeInputChains1_0</span></u><u><span style="font-size:10.0pt;font-family:"Courier New";color:black">.</span></u><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">ISEL: Starting pattern match on root node: t6: ch,glue = callseq_start t0, TargetConstant:i16<0><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">  Skipped scope entry (due to false predicate) at index 2, continuing at 30<o:p></o:p></p>
<p class="MsoNormal">  Skipped scope entry (due to false predicate) at index 31, continuing at 104<o:p></o:p></p>
<p class="MsoNormal">  Skipped scope entry (due to false predicate) at index 105, continuing at 183<o:p></o:p></p>
<p class="MsoNormal">  Skipped scope entry (due to false predicate) at index 184, continuing at 225<o:p></o:p></p>
<p class="MsoNormal">  Skipped scope entry (due to false predicate) at index 226, continuing at 267<o:p></o:p></p>
<p class="MsoNormal">  <span style="background:yellow;mso-highlight:yellow">Match failed at index 279</span><o:p></o:p></p>
<p class="MsoNormal">  Continuing at 287<o:p></o:p></p>
<p class="MsoNormal">  Match failed at index 288<o:p></o:p></p>
<p class="MsoNormal">  Continuing at 311<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*267*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">    
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*Scope*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> 19,
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*->287*/</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*268*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_CheckOpcode</u>, TARGET_VAL(ISD::</span><i><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0">CALLSEQ_START</span></i><span style="font-size:10.0pt;font-family:"Courier New";color:black">),</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*271*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_RecordNode</u>, </span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// #0 = 'callseq_start' chained node</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*272*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_RecordChild1</u>, </span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// #1 = $<u>amt</u></span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*273*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_MoveChild</u>, 1,</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*275*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_CheckOpcode</u>, TARGET_VAL(ISD::</span><i><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0">TargetConstant</span></i><span style="font-size:10.0pt;font-family:"Courier New";color:black">),</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*278*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">      
<u>OPC_MoveParent</u>,</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F;background:yellow;mso-highlight:yellow">/*279*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black;background:yellow;mso-highlight:yellow">      
<u>OPC_EmitMergeInputChains1_0</u>,</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F;background:lime;mso-highlight:lime">/*280*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black;background:lime;mso-highlight:lime">      
<u>OPC_MorphNodeTo</u></span><span style="font-size:10.0pt;font-family:"Courier New";color:black">, TARGET_VAL(<u>CLP::ADJCALLSTACKDOWN</u>), 0|<u>OPFL_Chain</u>|<u>OPFL_GlueOutput</u>,</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">                  0</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*#VTs*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">,
 1</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*#<u>Ops</u>*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">, 1,
</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">              </span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">//
<u>Src</u>: (callseq_start (timm:i16):$<u>amt</u>) - Complexity = 6</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">             
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// <u>
Dst</u>: (ADJCALLSTACKDOWN (timm:i16):$<u>amt</u>)</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*287*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">    
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*Scope*/</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> 23,
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">/*->311*/</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Using GDB, I’ve traced the reason of the failure:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:black">SelectCodeCommon() failed because Case OPC_EmitMergeInputChains1_0 ‘Failed to merge’ because HandleMergeInputChains() returns CR_InducesCycle because  WalkChainUsers()
 returns CR_InducesCycle;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">     
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// Because we structurally match the load/store as a read/modify/write,</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">     
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// but the call is chained between them.  We cannot fold in this case</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">     
</span><span style="font-size:10.0pt;font-family:"Courier New";color:#3F7F5F">// because it would induce a cycle in the graph.</span><span style="font-size:10.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What’s the meaning of such status? How to fix the following pattern or the Instruction Selection Graph?
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here are the pattern/nodes definitions:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">           
<u><span style="color:#1A1A1A">def</span></u> SDT_CLPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i16> ]>;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">                           <o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><u><span style="font-size:10.0pt;font-family:"Courier New";color:#1A1A1A">def</span></u><span style="font-size:10.0pt;font-family:"Courier New""> callseq_start : SDNode<"ISD::CALLSEQ_START",
 SDT_CLPCallSeqStart,<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">                           [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>;<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><u><span style="font-size:10.0pt;font-family:"Courier New";color:#1A1A1A">def</span></u><span style="font-size:10.0pt;font-family:"Courier New""> ADJCALLSTACKDOWN       : CLPPseudoInst<(ins
 i16imm:$<u><span style="color:#1A1A1A">amt</span></u>), (outs), [],<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">                                   "# ADJCALLSTACKDOWN $<u><span style="color:#1A1A1A">amt</span></u>",<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New"">                                   [(callseq_start
<u><span style="color:#1A1A1A">timm</span></u>:$<u><span style="color:#1A1A1A">amt</span></u>)],NoItinerary>;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br>
<br>
<br>
<img width="825" height="805" id="Picture_x0020_3" src="cid:image001.png@01D3289B.AE202320"><br>
<br>
<o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="536" style="width:402.0pt">
<tbody>
<tr>
<td style="padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><img width="536" height="49" id="_x0000_i1026" src="http://www.spacebel.be/wp-content/uploads/2011/06/image-sign-sbp.jpg" alt="http://www.spacebel.be/wp-content/uploads/2011/06/image-sign-sbp.jpg"><o:p></o:p></span></p>
</td>
</tr>
<tr>
<td style="border:solid silver 1.0pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="center" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:center">
<b><span lang="FR-BE" style="font-size:10.0pt">Dominique Torette</span></b><span lang="FR-BE" style="font-size:10.0pt">
<br>
System Architect<br>
Rue des Chasseurs Ardennais - Liège Science Park - B-4031 Angleur <br>
Tel: +32 (0) 4 361 81 11 - Fax: +32 (0) 4 361 81 20 <br>
</span><span style="font-size:10.0pt"><a href="http://www.spacebel.be/"><span lang="FR-BE">www.spacebel.be</span></a></span><span lang="FR-BE" style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span lang="FR-BE"><o:p> </o:p></span></p>
</div>
<br clear="both">
 ------------------------------------------------------------------------------<BR>
<BR>
E-MAIL DISCLAIMER<BR>
<BR>
The present message may contain confidential and/or legally privileged information. If you are not the intended addressee and in case of a transmission error, please notify the sender immediately and destroy this E-mail. Disclosure, reproduction or distribution of this document and its possible attachments is strictly forbidden.<BR>
<BR>
SPACEBEL denies all liability for incomplete, improper, inaccurate, intercepted, (partly) destroyed, lost and/or belated transmission of the current information given that unencrypted electronic transmission cannot currently be guaranteed to be secure or error free.<BR>
Upon request or in conformity with formal, contractual agreements, an originally signed hard copy will be sent to you to confirm the information contained in this E-mail.<BR>
<BR>
SPACEBEL denies all liability where E-mail is used for private use.<BR>
<BR>
SPACEBEL cannot be held responsible for possible viruses that might corrupt this message and/or your computer system.<BR>
 -------------------------------------------------------------------------------<BR>
</body>
</html>