[LLVMdev] test all ones/zeros in vector

Duncan Sands baldrick at free.fr
Tue May 15 00:34:20 PDT 2012


Hi Roland,

> is there a portable and effective way of emitting code which checks whether all vector elements are true or false?
>
> Currently, I'm doing this:
>
>    %sext = sext<4 x i1>  %my_cmp to<4 x i8>
>    %bcast = bitcast<4 x i8>  %sext to i32
>    %all_zeros = icmp ne i32 %bcast, 0
>    br i1 %all_zeros, label %A, label %B
>
>
> The emitted code works, but it's not great. I'd like to make use of movmask or ptest in the case of SSE.
>
> Of course, I could emit some intrinsic functions but I always consider these kind of things a hack; I'd rather like to emit some code which the back-end likes. So is there some llvm code sequence which does the trick?

the code generators can potentially be taught to recognize this pattern and turn
it into the appropriate instruction.  I suggest you open a bug report about it.

Ciao, Duncan.



More information about the llvm-dev mailing list