<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Nested loops not annotated with llvm.mem.parallel_loop_access"
   href="https://bugs.llvm.org/show_bug.cgi?id=37558">37558</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Nested loops not annotated with llvm.mem.parallel_loop_access
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>llvm@meinersbur.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>alexander.musman@gmail.com, hfinkel@anl.gov, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang r333027

LoopInfoStack::InsertHelper (added in r209411) only annotates memory accesses
using the top of the loop stack, hence missing out if an access is parallel for
another loop in the stack.

Reproducer:
The loop is not vectorized even though annotated with #pragma omp simd since
not all memory accesses are annotated (inner loop is likely unrolled).  Runtime
conditions also cannot be generated because of the conditional index.

$ cat parallel_access.c
void func(double *A, double *B, int N) {
  #pragma omp simd
  for (int i = 0; i < N; i+=1) {
    double sum = 0;
    for (int j = 0; j < 2; j+=1)
      sum += B[j];
    int idx = (i < N/2 ? i : N+i); 
    A[idx] = sum;
  }
}

$ clang -cc1 parallel_access.c -emit-llvm  -o - -O3 -fopenmp
parallel_access.c:2:6: warning: loop not vectorized: failed explicitly
specified loop vectorization
void func(double *A, double *B, int N) {
     ^
; ModuleID = 'parallel_access.c'
source_filename = "parallel_access.c"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

; Function Attrs: norecurse nounwind
define dso_local void @func(double* nocapture %A, double* nocapture readonly
%B, i32 %N) local_unnamed_addr #0 {
entry:
  %cmp = icmp sgt i32 %N, 0
  br i1 %cmp, label %for.cond.preheader.lr.ph, label %simd.if.end

for.cond.preheader.lr.ph:                         ; preds = %entry
  %div1146 = lshr i32 %N, 1
  %arrayidx.1 = getelementptr inbounds double, double* %B, i64 1
  br label %for.cond.preheader

for.cond.preheader:                               ; preds =
%for.cond.preheader, %for.cond.preheader.lr.ph
  %.omp.iv.045 = phi i32 [ 0, %for.cond.preheader.lr.ph ], [ %add16,
%for.cond.preheader ]
  %0 = load double, double* %B, align 8, !tbaa !2
  %add9 = fadd double %0, 0.000000e+00
  %1 = load double, double* %arrayidx.1, align 8, !tbaa !2
  %add9.1 = fadd double %add9, %1
  %cmp12 = icmp ult i32 %.omp.iv.045, %div1146
  %add13 = select i1 %cmp12, i32 0, i32 %N
  %cond = add nsw i32 %add13, %.omp.iv.045
  %idxprom14 = sext i32 %cond to i64
  %arrayidx15 = getelementptr inbounds double, double* %A, i64 %idxprom14
  store double %add9.1, double* %arrayidx15, align 8, !tbaa !2,
!llvm.mem.parallel_loop_access !6
  %add16 = add nuw nsw i32 %.omp.iv.045, 1
  %exitcond = icmp eq i32 %add16, %N
  br i1 %exitcond, label %simd.if.end, label %for.cond.preheader, !llvm.loop !6

simd.if.end:                                      ; preds =
%for.cond.preheader, %entry
  ret void
}

attributes #0 = { norecurse nounwind
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="false"
"no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{!"clang version 7.0.0 (trunk 331768)"}
!2 = !{!3, !3, i64 0}
!3 = !{!"double", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.vectorize.enable", i1 true}
1 warning generated.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>