[llvm-dev] LLVM Vectorisation Bug

Renato Golin via llvm-dev llvm-dev at lists.llvm.org
Sun Aug 6 06:28:21 PDT 2017


On 5 August 2017 at 14:55, hameeza ahmed via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I have matrix multiplication and stencil code. I vectorise it through the
> following command.
>
> opt  -S -O3 -force-vector-width=2048 stencil.ll -o stencil_o3.ll
>
> in both the examples of matrix mult and stencil it vectorises fine when my
> loop iterations >2048. but if i keep both iterations and vector width=2048.
> it produces scalar code IR not vectorizes it.

Hi Ahmed,

Can you show us your code?

I tried this example:

void foo(int *a, int *b, int *c) {
  for (int i=0; i<2048; i++)
    a[i] = b[i] + c[i];
}

Then ran Clang to produce IR and your opt line above and got a vectorised loop:

vector.body:                                      ; preds =
%vector.body.preheader
  %0 = bitcast i32* %b to <2048 x i32>*
  %wide.load = load <2048 x i32>, <2048 x i32>* %0, align 4, !alias.scope !1
  %1 = bitcast i32* %c to <2048 x i32>*
  %wide.load17 = load <2048 x i32>, <2048 x i32>* %1, align 4, !alias.scope !4
  %2 = add nsw <2048 x i32> %wide.load17, %wide.load
  %3 = bitcast i32* %a to <2048 x i32>*
  store <2048 x i32> %2, <2048 x i32>* %3, align 4, !alias.scope !6, !noalias !8
  br label %for.end

So, this seems to be either a bug in your code (off-by-one, loop
dependencies, etc) or some missing optimisation in Clang, which we'll
only know when we can actually see the code.

cheers,
--renato


More information about the llvm-dev mailing list