Floating point number format in .ll files changed?

Hi,

after upgrading to 2.1 I noticed that the format for floating point numbers in .ll files apparently changed. I now get errors like

"llvm-as: var.ll:48,0: Floating point constant invalid for type"

for such code:

"@gmFloat = constant float 0.3".

I checked with llvm-gcc and it now generates code for the hexadecimal floating point representation. The documentation at http://llvm.org/docs/LangRef.html#simpleconstants still says

"Floating point constants use standard decimal notation (e.g. 123.421), exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal notation (see below)".

I tried some numbers and llvm-as accepted "1.000000e+00", "1.0", "1." while it rejected "0.3", ".3", "0.1", "0.300000e+00" and "0.3000000e+00". It accepts more numbers for variables of type double (like 0.1). I think the pattern I can spot is to use hexadecimal notation if the decimal number cannot be represented as a float. Does LLVM provide any help converting floats to hexadecimal representation?

Which formats are accepted for floating point numbers in 2.1?

greetings,
Jan

Hi,

after upgrading to 2.1 I noticed that the format for floating point
numbers in .ll files apparently changed. I now get errors like

"llvm-as: var.ll:48,0: Floating point constant invalid for type"

for such code:

"@gmFloat = constant float 0.3".

I checked with llvm-gcc and it now generates code for the hexadecimal
floating point representation. The documentation at http://llvm.org/
docs/LangRef.html#simpleconstants still says

"Floating point constants use standard decimal notation (e.g.
123.421), exponential notation (e.g. 1.23421e+2), or a more precise
hexadecimal notation (see below)".

Farther down it says:

"The only time hexadecimal floating point constants are required (and the only time that they are generated by the disassembler) is when a floating point constant must be emitted but it cannot be represented as a decimal floating point number."

Represented means represented exactly, with no loss of information.

I tried some numbers and llvm-as accepted "1.000000e+00", "1.0", "1."
while it rejected "0.3", ".3", "0.1", "0.300000e+00" and "0.3000000e
+00". It accepts more numbers for variables of type double (like
0.1). I think the pattern I can spot is to use hexadecimal notation
if the decimal number cannot be represented as a float.

Right.

Does LLVM
provide any help converting floats to hexadecimal representation?

Sure, there are internal conversion routines. Most constants are held in APFloat objects these days, you might want to look at that. What are you trying to do?

Does LLVM
provide any help converting floats to hexadecimal representation?

Sure, there are internal conversion routines. Most constants are
held in APFloat objects these days, you might want to look at that.
What are you trying to do?

I'm writing a front-end for a custom language. Currently my compiler is implemented in OCaml and generates .ll files by emitting text. I notices floating point constants stopped working and will now need to upgrade. I guess I will have a look at the OCaml bindings in the SVN version now :slight_smile:

Dale Johannesen wrote:-

> Does LLVM
> provide any help converting floats to hexadecimal representation?

Sure, there are internal conversion routines. Most constants are
held in APFloat objects these days, you might want to look at that.

As far as I know APFloat doesn't provide this yet, if we're talking
about strings (which is the only way I can make sense of conversions
to hexadecimal representations).

However, I wrote most of it yesterday, and if it passes testing
I'll be pushing soon.

Neil.