[llvm-dev] LoopVectorize fails to vectorize code with condition on reduction

Florian Hahn via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 11 02:53:25 PDT 2018


Hi,

On 11/06/2018 10:40, Alex Susu via llvm-dev wrote:
>    Hello.
>      I'm not able to vectorize this simple C loop doing basically what 
> could be called predicated sum-reduction:
>        #define NMAX 1000
>        int colOccupied[NMAX];
>        void Func(int N) {
>          int numSol = 0;
>          for (int c = 0; c < N; c++) {
>              if (colOccupied[c] == 0)
>                  numSol++;
>          }
>          return numSol;
>        }
> 
>      The compiler command I used was:
>          clang -O3 -emit-llvm -S -mllvm -debug -ffast-math A.cpp 
> -fvectorize -mllvm -force-vector-width=16
> 
>      Following is the output of LLVM's opt explaining why it fails to 
> vectorize:
>         LV: Checking a loop in "_Z6Queensi" from 
> A_DFS_last_level_wo_rec.cpp
>         LV: Loop hints: force=? width=16 unroll=0
>         LV: Found a loop: for.body
>         LV: PHI is not a poly recurrence.
>         LV: PHI is not a poly recurrence.
>         LV: Found an unidentified PHI.  %2 = phi i32 [ 0, 
> %for.body.lr.ph ], [ %4, %for.inc ]
>         LV: Can't vectorize the instructions or CFG
>         LV: Not vectorizing: Cannot prove legality.
> 
>    This was obtained with the latest LLVM - SVN rev 334367, from Jun 10 
> 2018.
> 
>    Could you please tell me why do you think LoopVectorize is not being 
> able to vectorize the above C code.
> 

For me, a recent build of LLVM/Clang vectorizes the loop in Func on X86. 
The debug output you posted indicates that the loop comes from function 
called Queens. Is this the same function/loop as in Func?

Cheers,
Florian


More information about the llvm-dev mailing list