llvmlite icon indicating copy to clipboard operation
llvmlite copied to clipboard

string representations of special FP values work with DoubleType, but not FloatType or HalfType

Open jvesely opened this issue 3 years ago • 0 comments

simple reproducer:

from llvmlite import ir

fp = ir.DoubleType()
#fp = ir.FloatType()
#fp = ir.HalfType()
fnty = ir.FunctionType(fp, ())

module = ir.Module(name=__file__)
func = ir.Function(module, fnty, name="fpadd")
block = func.append_basic_block(name="entry")
builder = ir.IRBuilder(block)
x = fp("Inf")
builder.ret(x)

print(module)

The above only works with DoubleType. Both FloatType and HalfType produce the following error:

    return struct.unpack('f', struct.pack('f', value))[0]
struct.error: required argument is not a float

Using float("Inf") instead of just "Inf" works around the problem:

target triple = "unknown-unknown-unknown"
target datalayout = ""

define float @"fpadd"() 
{
entry:
  ret float 0x7ff0000000000000
}

jvesely avatar Apr 15 '22 01:04 jvesely