Skip to content

trunc with Float16 is broken on FreeBSD with LLVM 15 #49768

@ararslan

Description

@ararslan

After #48700, we're getting this and similar errors during testing on FreeBSD:

Error During Test at /usr/home/julia/.buildkite-agent/builds/freebsd12-amdci6-2/julialang/julia-master/julia-6618d4416d/share/julia/test/rounding.jl:225
  Test threw exception
  Expression: round(Ti, Tf(-0.0)) == 0
  InexactError: trunc(UInt64, -0.0)
  Stacktrace:
   [1] trunc(::Type{UInt64}, x::Float16)
     @ Base ./float.jl:874 [inlined]
   [2] round(::Type{UInt64}, x::Float16)
     @ Base ./float.jl:385
   [3] macro expansion
     @ /usr/home/julia/.buildkite-agent/builds/freebsd12-amdci6-2/julialang/julia-master/julia-6618d4416d/share/julia/stdlib/v1.10/Test/src/Test.jl:512 [inlined]
   [4] macro expansion
     @ /usr/home/julia/.buildkite-agent/builds/freebsd12-amdci6-2/julialang/julia-master/julia-6618d4416d/share/julia/test/rounding.jl:225 [inlined]
   [5] macro expansion
     @ /usr/home/julia/.buildkite-agent/builds/freebsd12-amdci6-2/julialang/julia-master/julia-6618d4416d/share/julia/stdlib/v1.10/Test/src/Test.jl:1546 [inlined]
   [6] top-level scope
     @ /usr/home/julia/.buildkite-agent/builds/freebsd12-amdci6-2/julialang/julia-master/julia-6618d4416d/share/julia/test/rounding.jl:146

@gbaraldi has looked into this a bit and found the following oddity.

Linux:

julia> @code_lowered trunc(UInt64, Float16(-0.0))
CodeInfo(
1 ─ %1  = Float16(-1.0) < x
└──       goto #3 if not %1
2 ─       @_4 = x < Inf16
└──       goto #4
3 ─       @_4 = false
4 ┄       goto #6 if not @_4
5 ─ %7  = Base.unsafe_trunc(UInt64, x)
└──       return %7
6 ─ %9  = Base.InexactError(:trunc, UInt64, x)
│   %10 = Base.throw(%9)
└──       return %10
)

FreeBSD:

julia> @code_lowered trunc(UInt64, Float16(-0.0))
CodeInfo(
1 ─ %1  = Float16(-1.0) < x
└──       goto #3 if not %1
2 ─       @_4 = x < -Inf16
└──       goto #4
3 ─       @_4 = false
4 ┄       goto #6 if not @_4
5 ─ %7  = Base.unsafe_trunc(UInt64, x)
└──       return %7
6 ─ %9  = Base.InexactError(:trunc, UInt64, x)
│   %10 = Base.throw(%9)
└──       return %10
)

Note the flipped sign on Inf16.

Metadata

Metadata

Labels

float16regressionRegression in behavior compared to a previous versionsystem:freebsdAffects only FreeBSD

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions