Index: include/llvm/Analysis/LoopInfo.h =================================================================== --- include/llvm/Analysis/LoopInfo.h +++ include/llvm/Analysis/LoopInfo.h @@ -561,11 +561,11 @@ /// Add llvm.loop.unroll.disable to this loop's loop id metadata. /// - /// Remove existing unroll metadata and add unroll disable metadata to + /// Remove existing Prefix metadata and add unroll disable metadata to /// indicate the loop has already been unrolled. This prevents a loop /// from being unrolled more than is directed by a pragma if the loop /// unrolling pass is run more than once (which it generally is). - void setLoopAlreadyUnrolled(); + void setLoopAlreadyUnrolled(StringRef Prefix = "llvm.loop.unroll."); void dump() const; void dumpVerbose() const; Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -269,7 +269,7 @@ } } -void Loop::setLoopAlreadyUnrolled() { +void Loop::setLoopAlreadyUnrolled(StringRef Prefix) { MDNode *LoopID = getLoopID(); // First remove any existing loop unrolling metadata. SmallVector MDs; @@ -282,7 +282,7 @@ MDNode *MD = dyn_cast(LoopID->getOperand(i)); if (MD) { const MDString *S = dyn_cast(MD->getOperand(0)); - IsUnrollMetadata = S && S->getString().startswith("llvm.loop.unroll."); + IsUnrollMetadata = S && S->getString().startswith(Prefix); } if (!IsUnrollMetadata) MDs.push_back(LoopID->getOperand(i)); Index: lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp =================================================================== --- lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp +++ lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp @@ -366,7 +366,7 @@ // If loop has an unroll count pragma or unrolled by explicitly set count // mark loop as unrolled to prevent unrolling beyond that requested. if (UnrollResult != LoopUnrollResult::FullyUnrolled && IsCountSetExplicitly) - L->setLoopAlreadyUnrolled(); + L->setLoopAlreadyUnrolled("llvm.loop.unroll_and_jam."); return UnrollResult; } Index: test/Transforms/LoopUnrollAndJam/pragma.ll =================================================================== --- test/Transforms/LoopUnrollAndJam/pragma.ll +++ test/Transforms/LoopUnrollAndJam/pragma.ll @@ -51,6 +51,7 @@ ; #pragma nounroll_and_jam define void @nounroll_and_jam(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ] +; CHECK: br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop ![[NOUNROLLANDJAM:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -94,6 +95,7 @@ ; #pragma unroll_and_jam(8) define void @unroll_and_jam_count(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us.7, %for.latch ], [ 0, %for.outer.preheader.new ] +; CHECK: br i1 %niter.ncmp.7, label %for.end.loopexit.unr-lcssa.loopexit, label %for.outer, !llvm.loop ![[NOUNROLL1:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -138,6 +140,7 @@ define void @unroll_and_jam(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ] ; CHECK-LOWTHRES: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ] +; CHECK: br i1 %niter.ncmp.7, label %for.end.loopexit.unr-lcssa.loopexit, label %for.outer, !llvm.loop ![[NOUNROLL2:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -181,6 +184,7 @@ ; #pragma nounroll (which we take to mean disable unroll and jam too) define void @nounroll(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ] +; CHECK: br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop ![[NOUNROLL3:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -224,6 +228,7 @@ ; #pragma unroll (which we take to mean disable unroll and jam) define void @unroll(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us, %for.latch ], [ 0, %for.outer.preheader ] +; CHECK: br i1 %exitcond25, label %for.end.loopexit, label %for.outer, !llvm.loop ![[UNROLL:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -267,6 +272,7 @@ ; #pragma clang loop nounroll, unroll_and_jam (which we take to mean do unroll_and_jam) define void @nounroll_plus_unroll_and_jam(i32 %I, i32 %J, i32* noalias nocapture %A, i32* noalias nocapture readonly %B) { ; CHECK: %i.us = phi i32 [ %add8.us.{{[1-9]*}}, %for.latch ], [ 0, %for.outer.preheader.new ] +; CHECK: br i1 %niter.ncmp.7, label %for.end.loopexit.unr-lcssa.loopexit, label %for.outer, !llvm.loop ![[NOUNROLLNOUNROLL:.*]] entry: %cmp = icmp ne i32 %J, 0 %cmp122 = icmp ne i32 %I, 0 @@ -305,15 +311,24 @@ ret void } - -!1 = distinct !{!1, !2} -!2 = distinct !{!"llvm.loop.unroll_and_jam.disable"} -!3 = distinct !{!3, !4} -!4 = distinct !{!"llvm.loop.unroll_and_jam.count", i32 8} -!5 = distinct !{!5, !6} -!6 = distinct !{!"llvm.loop.unroll_and_jam.enable"} -!7 = distinct !{!7, !8} -!8 = distinct !{!"llvm.loop.unroll.disable"} -!9 = distinct !{!9, !10} -!10 = distinct !{!"llvm.loop.unroll.enable"} -!11 = distinct !{!11, !8, !6} \ No newline at end of file +!1 = !{!1, !2} +!2 = !{!"llvm.loop.unroll_and_jam.disable"} +!3 = !{!3, !4} +!4 = !{!"llvm.loop.unroll_and_jam.count", i32 8} +!5 = !{!5, !6} +!6 = !{!"llvm.loop.unroll_and_jam.enable"} +!7 = !{!7, !8} +!8 = !{!"llvm.loop.unroll.disable"} +!9 = !{!9, !10} +!10 = !{!"llvm.loop.unroll.enable"} +!11 = !{!11, !8, !6} + +;CHECK: ![[NOUNROLL_DATA:.*]] = !{!"llvm.loop.unroll.disable"} +;CHECK: ![[NOUNROLLANDJAM]] = distinct !{![[NOUNROLLANDJAM]], ![[NOUNROLLANDJAM_DATA:.*]]} +;CHECK: ![[NOUNROLLANDJAM_DATA]] = !{!"llvm.loop.unroll_and_jam.disable"} +;CHECK: ![[NOUNROLL1]] = distinct !{![[NOUNROLL1]], ![[NOUNROLL_DATA]]} +;CHECK: ![[NOUNROLL2]] = distinct !{![[NOUNROLL2]], ![[NOUNROLL_DATA]]} +;CHECK: ![[NOUNROLL3]] = distinct !{![[NOUNROLL3]], ![[NOUNROLL_DATA]]} +;CHECK: ![[UNROLL]] = distinct !{![[UNROLL]], ![[UNROLL_DATA:.*]]} +;CHECK: ![[UNROLL_DATA]] = !{!"llvm.loop.unroll.enable"} +;CHECK: ![[NOUNROLLNOUNROLL]] = distinct !{![[NOUNROLLNOUNROLL]], ![[NOUNROLL_DATA]], ![[NOUNROLL_DATA]]}