[llvm-dev] Reassociation is blocking a vectorization

kamlesh kumar via llvm-dev
Sun, 10 Nov 2019 14:50:48 -0000

Please ignore above the mail.

Hi Devs,
I am looking at the bug
https://bugs.llvm.org/show_bug.cgi?id=43953

and found that following piece of ir

 %arrayidx = getelementptr inbounds float, float* %Vec0, i64 %idxprom
  %0 = load float, float* %arrayidx, align 4, !tbaa !2
  %arrayidx2 = getelementptr inbounds float, float* %Vec1, i64 %idxprom
  %1 = load float, float* %arrayidx2, align 4, !tbaa !2
  %sub = fsub fast float %0, %1
  %add = fadd fast float %sum.0, %sub

is transformed into

%arrayidx = getelementptr inbounds float, float* %Vec0, i64 %idxprom
  %0 = load float, float* %arrayidx, align 4, !tbaa !2
  %arrayidx2 = getelementptr inbounds float, float* %Vec1, i64 %idxprom
  %1 = load float, float* %arrayidx2, align 4, !tbaa !2
  %.neg = fsub fast float -0.000000e+00, %1
  %sub = fadd fast float %0, %sum.0
  %add = fadd fast float %sub, %.neg

which again by instcombiner transformed into

  %arrayidx = getelementptr inbounds float, float* %Vec0, i64 %idxprom
  %0 = load float, float* %arrayidx, align 4, !tbaa !2
  %arrayidx2 = getelementptr inbounds float, float* %Vec1, i64 %idxprom
  %1 = load float, float* %arrayidx2, align 4, !tbaa !2
  %sub = fadd fast float %0, %sum.012
  %add = fsub fast float %sub, %1


  Now at the time of SLP Vectorization for reported testcase

  SLP Vectorization visits instructions in bottom up fashion
  so this instruction is first one to be analyzed
    %add = fsub fast float %sub, %1

  When this piece of code is called  for the above instruction by
HorizontalReduction::matchAssociativeReduction(SLPVectorizer.cpp)
    /// Checks if the reduction operation can be vectorized.
    bool isVectorizable(Instruction *I) const {
      return isVectorizable() && isAssociative(I);
    }
  isAssociative returns false for the above instruction ans vectorization
fails.
  If we disable the reassociation the reported testcase is vectorized.
  Like to community thought on this whether reassociation is doing any good
here?

  ./Kamlesh



On Sun, Nov 10, 2019 at 8:03 PM kamlesh kumar <kamleshbhalui at gmail.com>
wrote:

> Hi Devs,
> I am looking at the bug
> https://bugs.llvm.org/show_bug.cgi?id=43953
>
> and found that following piece of ir
>
>  %arrayidx = getelementptr inbounds float, float* %Vec0, i64 %idxprom
>   %0 = load float, float* %arrayidx, align 4, !tbaa !2
>   %arrayidx2 = getelementptr inbounds float, float* %Vec1, i64 %idxprom
>   %1 = load float, float* %arrayidx2, align 4, !tbaa !2
>   %sub = fsub fast float %0, %1
>   %add = fadd fast float %sum.0, %sub
>
> is transformed into
>
> %arrayidx = getelementptr inbounds float, float* %Vec0, i64 %idxprom
>   %0 = load float, float* %arrayidx, align 4, !tbaa !2
>   %arrayidx2 = getelementptr inbounds float, float* %Vec1, i64 %idxprom
>   %1 = load float, float* %arrayidx2, align 4, !tbaa !2
>   %.neg = fsub fast float -0.000000e+00, %1
>   %sub = fadd fast float %0, %sum.0
>   %add = fadd fast float %sub, %.neg
>
> which again by instcombiner transformed into
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20191110/ff8b00df/attachment.html>