<div dir="ltr"><div>I believe that the idea of simm16 and uimm16 was taken over from MipsInstrInfo.td. It's entirely possible that the concepts were misunderstood then.</div><div> </div><div>So, a broader question, what is the best way to map down to an unsigned/signed sub/add (is this even possible)? How to add signed/unsigned immediates?</div><div><br></div><div>Thanks.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 15, 2017 at 3:14 PM, Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On 2/15/2017 11:37 AM, Ryan Taylor via llvm-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I see. If I put simm16 and immSExt16x in place of uimm16 and immZExt16x respectively, the imm matches but it prints out -32768 (which is invalid for sub16u). We are using uimm16 not match unsigned but for PrintMethod, effectively uimm16 and simm16 are both Operand<i16>. I'm still unclear why simm16 matches and uimm16 does not. Here is the pattern if that helps at all.<br>
<br>
So just as a reference:<br>
<br>
def simm16      : Operand<i16> {<br>
  let DecoderMethod= "DecodeSimm16";<br>
  let OperandType = "OPERAND_IMMEDIATE";<br>
}<br>
<br>
def uimm16      : Operand<i16> {<br>
  let PrintMethod = "printUnsignedImm";<br>
  let OperandType = "OPERAND_IMMEDIATE";<br>
}<br>
<br>
def immSExt16x : ImmLeaf<i16, [{ return isInt<16>(Imm); }]>;<br>
def immZExt16x : ImmLeaf<i16, [{ return isUInt<16>(Imm); }]>;<br>
</blockquote>
<br></span>
"Imm" in ImmLeaf is an int64_t, sign-extended from your immediate type (in this case, int16_t).  You'd need to insert an explicit cast to uint16_t to get the behavior you want.<br>
<br>
I'm not sure why you're doing this, though; every 16-bit integer immediate fits into a 16-bit integer, so a correctly implemented "immZExt16x" is just equivalent to "imm".<div class="HOEnZb"><div class="h5"><br>
<br>
-Eli<br>
<br>
-- <br>
Employee of Qualcomm Innovation Center, Inc.<br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br>
<br>
</div></div></blockquote></div><br></div>