Index: lib/Transforms/Scalar/LoopRotation.cpp =================================================================== --- lib/Transforms/Scalar/LoopRotation.cpp +++ lib/Transforms/Scalar/LoopRotation.cpp @@ -82,6 +82,9 @@ if (skipOptnoneFunction(L)) return false; + // Save Loop MD. + MDNode *LoopMD = L->getLoopID(); + LI = &getAnalysis(); TTI = &getAnalysis(); @@ -96,6 +99,12 @@ MadeChange = true; SimplifiedLatch = false; } + + // Restore the loop metadata. + // NB! We presume LoopRotation DOESN'T ADD its own metadata. + if (MadeChange && LoopMD) + L->setLoopID(LoopMD); + return MadeChange; } Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1096,6 +1096,13 @@ LoopVectorizeHints Hints(L, DisableUnrolling); + DEBUG(dbgs() << "LV: Loop hints:" + << " force=" << (Hints.Force == 0 + ? "disabled" + : (Hints.Force == 1 ? "enabled" : "?")) + << " width=" << Hints.Width << " unroll=" << Hints.Unroll + << "\n"); + if (Hints.Force == 0) { DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n"); return false; @@ -5095,7 +5102,7 @@ } } - DEBUG(dbgs() << "LV: Selecting VF = : "<< Width << ".\n"); + DEBUG(dbgs() << "LV: Selecting VF: "<< Width << ".\n"); Factor.Width = Width; Factor.Cost = Width * Cost; return Factor; Index: test/Transforms/LoopVectorize/vect.omp.persistence.ll =================================================================== --- /dev/null +++ test/Transforms/LoopVectorize/vect.omp.persistence.ll @@ -0,0 +1,54 @@ +; RUN: opt < %s -O2 -force-vector-unroll=2 -force-vector-width=4 -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s + +; CHECK: LV: Loop hints: force=enabled +; CHECK: 1 loop-rotate + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Ensure that "llvm.vectorizer.enable" metadata was not lost prior to LoopVectorize pass. +; In past LoopRotate was clearing that metadata. +; +; The source C code is: +; void foo(float *a, int size) +; { +; int t = 0; +; #pragma omp simd +; for (int i = 0; i < size; ++i) { +; a[i] = a[i-5] * a[i+2]; +; ++t; +; } +;} + +; Function Attrs: nounwind uwtable +define void @foo(float* nocapture %a, i64 %size) { +entry: + %cmp1 = icmp sgt i64 %size, 0 + br i1 %cmp1, label %for.header, label %for.end + +for.header: + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] + %cmp2 = icmp sgt i64 %indvars.iv, %size + br i1 %cmp2, label %for.end, label %for.body + +for.body: + + %0 = add nsw i64 %indvars.iv, -5 + %arrayidx = getelementptr inbounds float* %a, i64 %0 + %1 = load float* %arrayidx, align 4, !llvm.mem.parallel_loop_access !1 + %2 = add nsw i64 %indvars.iv, 2 + %arrayidx2 = getelementptr inbounds float* %a, i64 %2 + %3 = load float* %arrayidx2, align 4, !llvm.mem.parallel_loop_access !1 + %mul = fmul float %1, %3 + %arrayidx4 = getelementptr inbounds float* %a, i64 %indvars.iv + store float %mul, float* %arrayidx4, align 4, !llvm.mem.parallel_loop_access !1 + + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + br label %for.header, !llvm.loop !1 + +for.end: + ret void +} + +!1 = metadata !{metadata !1, metadata !2} +!2 = metadata !{metadata !"llvm.vectorizer.enable", i1 true}