2

How to check if a llvm::Value is signed or not (provided that it is either an integer or a float/double)?

My attempt: From docs for Value

Type* getType() const;

Can return a Type object containing the type information of a Value. It is easy to check whether Value is integer/float/double using it:

bool isFloatTy() const;
bool isDoubleTy() const;

But I am having trouble figuring out how to check whether Type is a signed number or not, since there is no method like bool isSignedTy() const; or anything like it.

How do I do the check?

tjysdsg
  • 656
  • 8
  • 19
  • Not quite sure if this is still true: https://stackoverflow.com/a/14723945/4181011 – Simon Kraemer Jan 21 '20 at 13:44
  • 3
    A quick search tells me that LLVM does not distinguish between signed and unsigned integer types. Different IR instructions interpret the data differently (`udiv` vs `sdiv`) but the data has only one type. See https://stackoverflow.com/questions/30519005/how-to-distinguish-signed-and-unsigned-integer-in-llvm and its references... – Max Langhof Jan 21 '20 at 13:44
  • 2
    Maybe if you include more info about your use case, someone could make a suggestion on how to appropriately handle the issue without adding extra data. – Braaedy Jan 21 '20 at 17:06

0 Answers0