Skip to content

Commit 3696968

Browse files
Work around LLVM's dickish undefined constant folding behavior.
LLVM's fptosi intrinsic is undefined for NaN, so LLVM obnoxiously and pointlessly does different things when it gets NaN as a run-time value than as a compile-time value. To avoid this shitty, pointless trap, we have to avoid calling fptosi on NaN by introducing a branch into the hashing function – even though for hashing, we don't care *what* value is produced, just as long as it's consistent. Unfortunately, this affects the performance of Float64 hashing pretty badly. I was not able to figure out any way to recover this lost performance. LLVM really needs to stop doing this.
1 parent f791029 commit 3696968

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

base/hashing.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ end
3030
## hashing small, built-in numeric types ##
3131

3232
hx(a::Uint64, b::Float64, h::Uint) = hash_uint((3a + reinterpret(Uint64,b)) - h)
33+
const hx_NaN = hx(uint(0), NaN, uint(0))
3334

3435
hash(x::Uint64, h::Uint) = hx(x, float64(x), h)
3536
hash(x::Int64, h::Uint) = hx(reinterpret(Uint64,x), float64(x), h)
36-
hash(x::Float64, h::Uint) = hx(box(Uint64,fptosi(unbox(Float64,x))), ifelse(isnan(x), NaN, x), h)
37+
hash(x::Float64, h::Uint) = isnan(x) ? (hx_NaN $ h) : hx(box(Uint64,fptosi(unbox(Float64,x))), x, h)
3738

3839
hash(x::Union(Int8,Uint8,Int16,Uint16,Int32,Uint32), h::Uint) = hash(int64(x), h)
3940
hash(x::Float32, h::Uint) = hash(float64(x), h)

0 commit comments

Comments
 (0)