[LLVMdev] Simple question on sign

Duncan Sands baldrick at free.fr
Thu Feb 23 02:05:55 PST 2012

Hi Sam,

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

there is no difference between signed and unsigned addition when viewed as a
bunch of bits.  Suppose you take a collection of 32 bits; call this A.  In C,
you can view A as a signed or unsigned 32 bit integer; call these Asigned and
Aunsigned.  Take another collection B of 32 bits, and Bsigned/Bunsigned as the
signed and unsigned 32 bit C integers.  Do the two additions: Asigned+Bsigned
and Aunsigned+Bunsigned.  If you look at the bits making up the results you will
discover that they are exactly the same in the signed and unsigned cases.  This
is why LLVM doesn't distinguish between signed and unsigned addition.

For loads: when you load a 32 bit quantity from memory you just get those same
32 bits in a register.  There is no notion of signed/unsigned here, you are just
moving bunches of bits around.

Ciao, Duncan.

More information about the llvm-dev mailing list