[LLVMdev] Simple question on sign

sam parker S.Parker3 at lboro.ac.uk
Thu Feb 23 02:35:35 PST 2012


Thanks for the replies guys but I think I should have phrased my question
better... looking at the Mips backend there are machine instructions that
operate on signed and unsigned data, such as add and addu. And like Mips, I
need to specify unsigned specific instructions, so how do these get chosen
between if the LLVM IR does not carry type data? A very general point in the
right direction is all i need and would most appreciate it. sorry if i'm
being dense.

sam


James Molloy-3 wrote:
> 
> Hi Sam,
> 
> Whereas most languages track signedness on the variable/value level, LLVM
> IR
> takes a more machine-like approach of having the sign apply to the
> instruction rather than the value.
> 
> It is therefore the frontend (or whatever is initially producing the LLVM
> IR) that should know whether an operation should be signed or unsigned.
> 
> Hopefully that makes sense,
> 
> Cheers,
> 
> James
> 
> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
> Behalf Of sam parker
> Sent: 23 February 2012 09:45
> To: llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] Simple question on sign
> 
> 
> how does llvm decide when to use unsigned instructions then? such as
> unsigned
> adds and loads? I'm trying to describe some multiply shift ops and getting
> a
> bit stuck differentiating between signed and unsigned.
> 
> sam
>  
> 
> Eli Friedman-2 wrote:
>> 
>> On Wed, Feb 22, 2012 at 4:28 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
>> On Wed, Feb 22, 2012 at 4:28 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
>>> How do you determine if a shift is signed or not?
>>>
>>> ashr = always signed?
>> 
>> Essentially, yes.
>> 
>>> lshr = always unsigned?
>> 
>> Essentially, yes.
>> 
>>> shl = always signed?
>> 
>> Signed left shift and unsigned left shift are both shl.
>> 
>> http://llvm.org/docs/LangRef.html#i_shl describes the semantics of
>> shifts.
>> 
>>> The CmpInst has the "isSigned()" function, but it appears that every
>>> other
>>> Instruction I've looked at doesn't seem to have this.
>> 
>> There isn't an isSigned() function because the query doesn't really
>> make sense.  LLVM IR doesn't in general track whether a value is
>> signed or unsigned.
>> 
>> -Eli
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>> 
>> 
> 
> -- 
> View this message in context:
> http://old.nabble.com/Simple-question-on-sign-tp33375005p33376706.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 

-- 
View this message in context: http://old.nabble.com/Simple-question-on-sign-tp33375005p33376946.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list