<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Peter via llvm-dev Lawerence" <llvm-dev@lists.llvm.org><br><b>To: </b>"llvm-dev@lists.llvm.org" <llvm-dev@lists.llvm.org><br><b>Sent: </b>Wednesday, November 25, 2015 12:33:21 AM<br><b>Subject: </b>Re: [llvm-dev] Qs about TwoOperandAliasConstraint and TIED_TO<br><br>


<style><!--

@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:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}

p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        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:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>

<div class="WordSection1">
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I think I have answered my own question again,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I will use a CustomInserter to create my own MachineInstruction for my LEA instruction,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">that way I can call BuildMI myself, and add whatever operands are needed,</span></p>
<p class="MsoNormal"><span id="DWT929" style="color: rgb(31, 73, 125);">with whatever TiedTo information is needed.</span></p></div></blockquote>That shouldn't be necessary. PowerPC, for example, uses tired register constraints on its pre-increment load/store instructions, and this works correctly.<br><br>Also, as far as I can tell, nothing in CodeGen makes use of the OPERAND_REGISTER vs. OPERAND_MEMORY distinction. Those are provided for use by the targets when implementing their assembly parsing and printing. In fact, if you look at lib/Target/PowerPC/PPCGenInstrInfo.inc, a lot of the corresponding operands are tagged OPERAND_UNKNOWN (I should probably fix that, but that's another story).<br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div class="WordSection1"><p class="MsoNormal"><span style="color: rgb(31, 73, 125);"></span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I have looked into the register allocator’s “TwoOperandInstructionPass.cpp”,
</span></p>
<p class="MsoNormal"><span id="DWT930" style="color: rgb(31, 73, 125);">and it does not look up any information in the “XyzGenInstrInfo.inc” OperandInfo tables,</span></p></div></blockquote><br>This is not the right place to look. Tied register operands are handled as part of the generic register allocation infrastructure TwoAddressInstructionPass is an additional set of optimizations implemented with the help of target callbacks (convertToThreeAddress, etc.).<span style="color: rgb(31, 73, 125);"></span><br><br>When you say that you're still seeing problems, can you be more specific?<br><br>Also, you probably also want to add:<br><br>  let DisableEncoding = "$dst"<br><br>to your definition.<br><br> -Hal<br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div class="WordSection1"><p class="MsoNormal"><span style="color: rgb(31, 73, 125);"></span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">rather CodeGen (or in my case my CustomInserter) puts the necessary info into the</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">MachineOperand, and RA gets it from there.</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">so the fact that the generated OperandInfo table has the wrong operand type</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">(Memory, when Register is needed) won’t matter.</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">-Peter Lawrence.</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<div>
<div style="border-right: medium none; border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0in 0in;">
<p class="MsoNormal"><b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";">From:</span></b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";"> Lawerence, Peter
<br>
<b>Sent:</b> Tuesday, November 24, 2015 11:27 AM<br>
<b>To:</b> 'llvm-dev@lists.llvm.org'<br>
<b>Subject:</b> RE: Qs about TwoOperandAliasConstraint and TIED_TO</span></p>
</div>
</div>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I think I have answered my own questions below, but now have additional questions,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I am now using :      let Constraints = “$src = $dst”;       following examples from X86,
</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">rather than TwoOperandAliasConstraint  that I had been following from Mips,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">and I am now seeing TIED_TO in my  GenInstrInfo.inc  for the appropriate OperandInfo’s,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">but I am still seeing assembly code emitted that violates this constraint,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">what else am I missing ?</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">thanks, Peter Lawrence.</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">the only thing I see that is out-of-the-ordinary in my GenInstrInfo.inc is</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">the OPERAND_MEMORY rather than OPERAND_REGISTER for my base-register operand</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">and OPERAND_MEMORY rather than OPERAND_IMMEDIATE for my offset operand,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">but am still not sure how that happens or what to do to fix it ?</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">static const MCOperandInfo OperandInfo25[] = {</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">     { Xmc::AddrRegsRegClassID, 0, MCOI::OPERAND_REGISTER, 0 },</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">     { Xmc::AddrRegsRegClassID, 0, MCOI::OPERAND_MEMORY, ((0 << 16) | (1 << MCOI::TIED_TO)) },</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">     { -1, 0, MCOI::OPERAND_MEMORY, 0 }, };</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">I seem to be between a rock and a hard place:</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">let OperandType = "OPERAND_MEMORY" in {                           <----- I suspect my MEMORY_OPERAND comes from this</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">def memri     : Operand<iPTR> {</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">  let MIOperandInfo = (ops addrreg:$base, i16imm:$offset); }</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">}</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">def LEA : FMT_I6 <0x4c00, (outs addrreg:$dst), (ins memri:$addr), <----- I suspect the fix would be to split the memri</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">                                                                   ----- into separate reg and imm “ins” operands,</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">                "lea $dst, ${addr:arith}",</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">               [(set iPTR:$dst, addrri:$addr)]> {                 <----- but then I would not be able to write this pattern</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">                                                                   ----- and ISel would fail ?????</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">  let Constraints = "$addr.base = $dst";</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">  let isCodeGenOnly = 1;</span></p>
<p class="MsoNormal"><span style="font-family: "Courier New"; color: rgb(31, 73, 125);">}</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">-- Sleepless in Silicon Valley...</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<div>
<div style="border-right: medium none; border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0in 0in;">
<p class="MsoNormal"><b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";">From:</span></b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";"> Lawerence, Peter
<br>
<b>Sent:</b> Monday, November 23, 2015 3:37 PM<br>
<b>To:</b> 'llvm-dev@lists.llvm.org'<br>
<b>Subject:</b> Qs about TwoOperandAliasConstraint and TIED_TO</span></p>
</div>
</div>
<p class="MsoNormal"> </p>
<p class="MsoNormal">in  llvm-3.6.2.src</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">1.   when I put this around one of my instruction definitions in my target “InstrInfo.td” file,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">let TwoOperandAliasConstraint = "$dst = $rs1" in {</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I do not see any TIED_TO in the generated GenInstrInfo.inc file for the OperandInfo used by the instruction,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">the question is what am I doing wrong ?</p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> you are doing nothing wrong, the same thing happens for Mips,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> all its’ ArithLogicR and ArithLogicI instructions have    let TwoOperandAliasConstraint = “$rd = $rs”;</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> but if you look at MipsGenInstrInfo.inc</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> AND, OR, XOR, ADD, SUB, ADDu, SUBu, etc..., use OperandInfo14 does not contain any TIED_TO</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> ANDi, ORi, XORi, ADDi, SUBi, ADDui, SUBui, etc..., use OperandInfo29 does not contain any TIED_TO</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> there is probably a bug somewhere in utils/TableGen/</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> this is probably working for Mips in the case of ArithLogicR, since those instructions really are 3-operand</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> but it is mysterious how RA gets it right for the ArithLogicI case, since those instructions really are 2-operand</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> IMHO, from a Software Engineering point of view TwoOperandAliasConstraint should either be fixed or deleted,</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> currently it is misleading, and in a target-description that should be usable as a reference design</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> (as Mips can be viewed as the quintessential RISC instruction set),  at least I tried to use it as such.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">2.    I’ve noticed that TwoOperandAliasConstraint does not appear anywhere in   source/lib/Target/X86/*</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">yet  TIED_TO occurs in 162 of the  OperandInfo’s in   build/lib/Target/X86/X86GenInstrInfo.inc</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">the question is how does TIED_TO happen if not by  TwoOperandAliasConstraint  ?</p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> searching X86InstrInfo.td and X86GenInstrInfo.inc it is seems that</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">--->     let Constraints = “$src = $dst”;</span></p>
<p class="MsoNormal"><span style="color: rgb(31, 73, 125);">---> gets recognized by TableGen and converted into a TIED_TO constraint</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">thanks, Peter Lawrence.</p>
<p class="MsoNormal"> </p>
</div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>