[llvm-bugs] [Bug 37558] New: Nested loops not annotated with llvm.mem.parallel_loop_access

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 22 22:29:08 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37558

            Bug ID: 37558
           Summary: Nested loops not annotated with
                    llvm.mem.parallel_loop_access
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm at meinersbur.de
                CC: alexander.musman at gmail.com, hfinkel at anl.gov,
                    llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180523/ce2f5def/attachment-0001.html>


More information about the llvm-bugs mailing list