[llvm-dev] Unsigned int displaying as negative

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 15 12:14:13 PST 2017


On 2/15/2017 11:37 AM, Ryan Taylor via llvm-dev wrote:
> 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.
>
> So just as a reference:
>
> def simm16      : Operand<i16> {
>   let DecoderMethod= "DecodeSimm16";
>   let OperandType = "OPERAND_IMMEDIATE";
> }
>
> def uimm16      : Operand<i16> {
>   let PrintMethod = "printUnsignedImm";
>   let OperandType = "OPERAND_IMMEDIATE";
> }
>
> def immSExt16x : ImmLeaf<i16, [{ return isInt<16>(Imm); }]>;
> def immZExt16x : ImmLeaf<i16, [{ return isUInt<16>(Imm); }]>;

"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.

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".

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list