[LLVMdev] Vector cast

Eli Friedman eli.friedman at gmail.com
Sat Jun 21 17:18:49 PDT 2008


On Sat, Jun 21, 2008 at 4:24 PM, Nicolas Capens <nicolas at capens.net> wrote:
> I seem to be unable to cast a vector of integers to a vector of floats
> (uitofp [4 x i8] to [4 x float], to be exact). It hits an assert in
> LegalizeDAG.cpp line 5433: "Unknown int value type". The Assembly Language
> Reference Manual's definition of uitofp doesn't indicate that this is
> unsupported, so it looks like a bug to me. I'm on an x86 system by the way.

I assume you mean something like "uitofp <4 x i8> %0 to <4 x float>"?
It's supposed to be supported, I think, but that sort of thing isn't
reliable at the moment. AFAIK, baldrick is working on a replacement
for LegalizeDAG that should handle that sort of thing better.

In the meantime, the following should perform the operation you want
efficiently on X86:
define <4 x float> @charvectofloatvec(i32) nounwind {
insertelement <4 x i32> undef, i32 %0, i32 0
bitcast <4 x i32> %2 to <16 x i8>
shufflevector <16 x i8> %3, <16 x i8> zeroinitializer, <16 x i32> <i32
0, i32 16, i32 1, i32 17, i32 2, i32 18, i32 3, i32 19, i32 4, i32 20,
i32 5, i32 21, i32 6, i32 22, i32 7, i32 23>
shufflevector <16 x i8> %4, <16 x i8> zeroinitializer, <16 x i32> <i32
0, i32 16, i32 1, i32 17, i32 2, i32 18, i32 3, i32 19, i32 4, i32 20,
i32 5, i32 21, i32 6, i32 22, i32 7, i32 23>
bitcast <16 x i8> %5 to <4 x i32>
sitofp <4 x i32> %6 to <4 x float>
ret <4 x float> %7
}

At least for the moment, the trick to getting high-quality,
predictable output for vector operations in LLVM is to make sure the
operations are natively available on the underlying architecture...
note that all the operations here directly map to a single X86
instruction. The backend is getting smarter, but it'll be a while
before it's really good at generating high-quality vector code.

-Eli



More information about the llvm-dev mailing list