[LLVMdev] bitcast and bitwise operations on floating point numbers

Simon Byrne
Tue, 20 Jan 2015 17:08:16 -0000

There are some occasions where it is useful to perform bitwise AND/OR
on floating point numbers (e.g. when working with extended precision).

An easy way to do this is to bitcast to an unsigned integer, do your
operation, then bitcast back to a float, which will generate IR along
the lines of:

%1 = bitcast double %0 to i64
%2 = and i64 %1, -4294967296
%3 = bitcast i64 %2 to double
ret double %3

Is LLVM able translate this to use the relevant floating point
instructions when available (i.e. ANDPD/VANDPD on x86)?

(this originally came up on julia-dev:
https://groups.google.com/d/topic/julia-dev/5y1y6Uj8T1A/discussion)

Simon