[LLVMdev] convert integer to double "uitofp" or "sitofp" ?

167 views
Skip to first unread message

Jimborean Alexandra

unread,
Oct 21, 2011, 5:59:07 AM10/21/11
to llv...@cs.uiuc.edu
Hello,

As I understand, in LLVM IR it cannot be determined whether a register of type int is signed or unsigned.
If one wants to convert an integer to a double, which instruction should be used:  "uitofp" or "sitofp" ?


We track the values taken by all load instructions and we process them using a function. If the value is a pointer, we use int64 as the type of the function argument.
But in case the load instruction loads from a scalar, we need to convert it to a unique type, which we chose to be DoubleTy and use a function that expects a double as parameter.
Hence, we need to convert integers of various sizes to double. Is it possible to detect which instruction should be  used ("uitofp" or "sitofp" ) ?

Thank you,
Alexandra


Duncan Sands

unread,
Oct 21, 2011, 7:00:01 AM10/21/11
to llv...@cs.uiuc.edu
Hi Jimborean,

> As I understand, in LLVM IR it cannot be determined whether a register of type
> int is signed or unsigned.
> If one wants to convert an integer to a double, which instruction should be
> used: "uitofp" or "sitofp" ?

LLVM integers are just bags of bits, so this can't be answered without more
information about what you plan to do with the double. Using an uitofp is no
more or less sensible than using sitofp in general. What if your integer can't
be accurately represented by a double? For example i64 -> double -> i64
(Xitofp followed by fptoXi) may not get you your original integer back. Do
you care? You can also bitcast an i64 to a double, getting a double that has
the same bit pattern. But then does converting to a double win you anything?

> We track the values taken by all load instructions and we process them using a
> function.

What does the function do?

Ciao, Duncan.
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Anton Korobeynikov

unread,
Oct 21, 2011, 7:33:22 AM10/21/11
to Jimborean Alexandra, llv...@cs.uiuc.edu
Hi Alexandra,

> Hence, we need to convert integers of various sizes to double. Is it
> possible to detect which instruction should be  used ("uitofp" or "sitofp" )

Unfortunately, no, this information is lost.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

Reply all
Reply to author
Forward
0 new messages