We noticed with Julia/Metal.jl that this approach is not legal. From the langref:
The ‘bitcast’ instruction takes a value to cast, which must be a non-aggregate first class value, and a type to cast it to, which must also be a non-aggregate first class type.
We switched to running some IR rewrite passes before invoking the bitcode writer, simply replacing the freeze by its operands: JuliaGPU@9c518c4