[LLVMdev] branch on vector compare?

Duncan Sands baldrick at free.fr
Mon Sep 3 01:12:49 PDT 2012


Hi Stephen,

> Hi all, llvm newbie here.

welcome!

> I'm trying to branch based on a vector compare. I've found a slow way (below)
> which goes through memory. Is there some idiom I'm missing so that it would use
> for instance movmsk for SSE or vcmpgt & cr6 for altivec?

I don't think you are missing anything: LLVM IR has no support for horizontal
operations like or'ing the elements of a vector of boolean together.  The code
generators do try to recognize a few idioms and synthesize horizontal
operations from them, but I think only addition is currently recognized, and
it expects the addition to be done (IIRC) by using shufflevector to split the
vector into two, followed by an addition of the two halves, repeatedly.  In
fact for your case you could do something similar:
   %lo1 = shufflevector <4 x i1> %16, <4 x i1> undef, <2 x i32> <i32 0, i32 1>
   %hi1 = shufflevector <4 x i1> %16, <4 x i1> undef, <2 x i32> <i32 2, i32 3>
   %join = or <2 x i1> %lo1, %hi1
   %lo2 = extractelement <2 x i1> %join, i32 0
   %hi2 = extractelement <2 x i1> %join, i32 1
   %final = or i1 %lo2, %hi2
Currently I would expect the code generators to produce something nasty for
this.  Feel free to open a bugreport requesting that the code generators do
something better.

Ciao, Duncan.

>
> Or do I need to resort to calling the intrinsic directly?
>
> Thanks,
> Stephen.
>
>    %16 = fcmp ogt <4 x float> %15, %cr
>    %17 = extractelement <4 x i1> %16, i32 0
>    %18 = extractelement <4 x i1> %16, i32 1
>    %19 = extractelement <4 x i1> %16, i32 2
>    %20 = extractelement <4 x i1> %16, i32 3
>    %21 = or i1 %17, %18
>    %22 = or i1 %19, %20
>    %23 = or i1 %21, %22
>    br i1 %23, label %true1, label %false2
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list