<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
You might give OutPatFrag a try:<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// OutPatFrag is a pattern fragment that is used as part of an output pattern
<div>// (not an input pattern). These do not have predicates or transforms, but are</div>
<div>// used to avoid repeated subexpressions in output patterns.</div>
<div>class OutPatFrag<dag ops, dag frag></div>
<span> : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Cyril Six via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> Monday, November 8, 2021 6:37 AM<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [llvm-dev] Re-using a node in a DAG output pattern in TableGen</font>
<div> </div>
</div>
<div>
<table bgcolor="#FFEB9C" border="1">
<tbody>
<tr>
<td><font face="verdana" color="black" size="1"><b>External email: Use caution opening links or attachments</b>
</font></td>
</tr>
</tbody>
</table>
<br>
<div>
<div style="font-family:arial,helvetica,sans-serif; font-size:12pt; color:#000000">
<div>Hello,<br>
</div>
<div><br>
</div>
<div>I currently have an instruction selection pattern that looks like this :<br>
</div>
<div><br>
</div>
<blockquote>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif">def : Pat<myinputop type:$v0 type:$v1,</span><br>
</div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (COMPNHQ</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (ADDHQrr</span><br>
</div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (SLLHQSri $v0, 8),<br>
</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (SLLHQSri $v1, 8),<br>
</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> ),<br>
</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (SLLHQSri $v0, 8),<br>
</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> comparison_ltu<br>
</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> )>;</span></div>
</blockquote>
<div><span style="font-family:arial,helvetica,sans-serif">This output pattern is supposed to be a DAG: the node (SLLHQSri $v0, 8) is used two times.<br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">Experimentally, TableGen seems to recognize it as such (the node `(SLLHQSri $v0, 8)` will not be duplicated).<br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">I am wondering if there is a way to avoid having to repeat (SLLHQSri $v0, 8) in the syntax of TableGen, something like:</span><span style="font-family:arial,helvetica,sans-serif"></span></div>
<div>
<blockquote>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif">def : Pat<inputpattern type:$v0 type:$v1,</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (COMPNHQ</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (ADDHQrr</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (SLLHQSri $v0, 8):$myvar,</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> (SLLHQSri $v1, 8),</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> ),</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> $myvar,</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> comparison_ltu</span></div>
<div><span style="font-family:courier new,courier,monaco,monospace,sans-serif"> )>;</span></div>
</blockquote>
</div>
<div>If I try this, I get the error "Node 'myvar' in output pattern but not input pattern".<br>
</div>
<div><br>
</div>
<div>Does anyone know if there is a way to name nodes from an output pattern to produce a non-tree output DAG?<br>
</div>
<div><br>
</div>
<div>Do you know of any existing pattern featuring output DAG that are not trees?</div>
<div><br>
</div>
<div>Thanks<br>
</div>
<div>
<div><br>
</div>
<div style="font-size:9pt; font-family:'arial' ,'helvetica' ,sans-serif"><span style="color:#144444; font-size:9pt"><strong>Cyril Six</strong></span><br>
<span style="color:#144444; font-size:9pt"><strong>Compiler Engineer • Kalray</strong></span><br>
<span style="color:#144444; font-size:8pt">Phone: </span><br>
<span style="color:#11588f; font-size:8pt"><u>csix@kalrayinc.com</u> • <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kalrayinc.com%2F&data=04%7C01%7Cjeckhardt%40nvidia.com%7C1bf04ec61fbb4f4958a908d9a2b48d7d%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637719718619602934%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=RtINTAlB1bxfjgh9PqVW7J%2FZ6pXFOUPPlAWtyK70t2U%3D&reserved=0" originalsrc="https://www.kalrayinc.com/" shash="Us3gImta82J2kh7FAvjrZl22C9XQRc6MtdOLZU9LLOchz1zpHVfqijCPvAWZj9KBNiQ2cwRCg7Xgq4FovovC2p7C4RIStRnd40O2CKE2lJ2hi9PeYXSpP8DC7/xWQvHmnHN1KHwYelQZSFChiJLq05f1Ydri4HAt5WCbJhGqfgw=" target="_blank" rel="nofollow noopener noreferrer" style="color:#11588f">
<u>www.kalrayinc.com</u></a></span> </div>
<br>
<table cellpadding="0px" border="0px">
<tbody>
<tr>
<td>
<div><a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.kalrayinc.com%2F&data=04%7C01%7Cjeckhardt%40nvidia.com%7C1bf04ec61fbb4f4958a908d9a2b48d7d%7C43083d15727340c1b7db39efd9ccc17a%7C0%7C0%7C637719718619612928%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=9kPWz9fpnv2ZIP%2Fg6CVNCevmc141CEV2ZdG9EtDsxcU%3D&reserved=0" originalsrc="https://www.kalrayinc.com/" shash="hchLisOgOrv4/CQiVO+m0JBPA+fXG1FtUSWnGOmpmml6nSwjBgRaeR59muhF3hhYqwwCvCwoO9iV/QCP+gQMqqzhnQ96ZFZTwiZnzs9m5lfqMz55Cxwqx1CL7IrOOy3PLiA1da3uddWJQJ7KuQqmsJ0dLksfEmn1RiGCTXpvNWE=" target="_blank" rel="nofollow noopener noreferrer"><img alt="Kalray logo" src="https://www.kalrayinc.com/IMG/png/Logo_Kalray_141x39.png"></a>
</div>
</td>
<td>
<div style="padding-left:10px; border-left:1px solid #58585a"><span style="color:#144444; font-size:8pt; font-family:'arial' ,'helvetica' ,sans-serif; display:block; line-height:120%">Intelligent Data Processing<br>
>From Cloud to Edge</span></div>
</td>
</tr>
</tbody>
</table>
<br>
<span style="color:#7db621; font-size:8pt; font-family:'arial' ,'helvetica' ,sans-serif"><strong>Please consider the environment before printing this e-mail.</strong></span>
<div><span style="color:#144444; font-size:8pt; font-family:'arial' ,'helvetica' ,sans-serif; display:block; line-height:100%">This message contains information that may be privileged or confidential and is the property of Kalray S.A. It is intended only for
the person to whom it is addressed. If you are not the intended recipient, you are not authorized to print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately
and delete all copies of this message.</span></div>
<br>
</div>
</div>
<div id="x_content_out_csix_kalrayinc.com"></div>
</div>
</div>
</body>
</html>