Index: llvm/lib/Transforms/Utils/LoopUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/LoopUtils.cpp +++ llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1501,7 +1501,7 @@ // We walk the initial sequence of loops in reverse because we generally want // to visit defs before uses and the worklist is LIFO. - for (Loop *RootL : Loops) { + for (Loop *RootL : reverse(Loops)) { assert(PreOrderLoops.empty() && "Must start with an empty preorder walk."); assert(PreOrderWorklist.empty() && "Must start with an empty preorder walk worklist."); Index: llvm/test/Analysis/LoopNestAnalysis/infinite.ll =================================================================== --- llvm/test/Analysis/LoopNestAnalysis/infinite.ll +++ llvm/test/Analysis/LoopNestAnalysis/infinite.ll @@ -2,9 +2,9 @@ ; Test that the loop nest analysis is able to analyze an infinite loop in a loop nest. define void @test1(i32** %A, i1 %cond) { +; CHECK-LABEL: IsPerfect=true, Depth=1, OutermostLoop: for.infinite, Loops: ( for.infinite ) ; CHECK-LABEL: IsPerfect=true, Depth=1, OutermostLoop: for.inner, Loops: ( for.inner ) ; CHECK-LABEL: IsPerfect=false, Depth=2, OutermostLoop: for.outer, Loops: ( for.outer for.inner ) -; CHECK-LABEL: IsPerfect=true, Depth=1, OutermostLoop: for.infinite, Loops: ( for.infinite ) entry: br label %for.outer Index: llvm/test/CodeGen/AArch64/loop-micro-op-buffer-size-t99.ll =================================================================== --- llvm/test/CodeGen/AArch64/loop-micro-op-buffer-size-t99.ll +++ llvm/test/CodeGen/AArch64/loop-micro-op-buffer-size-t99.ll @@ -3,18 +3,18 @@ target triple = "aarch64-unknown-linux-gnu" -; CHECK: Loop Unroll: F[foo] Loop %loop.header -; CHECK: Loop Size = 18 -; CHECK: Trip Count = 512 -; CHECK: Trip Multiple = 512 -; CHECK: UNROLLING loop %loop.header by 4 with a breakout at trip 0 -; CHECK: Merging: ; CHECK: Loop Unroll: F[foo] Loop %loop.2.header ; CHECK: Loop Size = 19 ; CHECK: Trip Count = 512 ; CHECK: Trip Multiple = 512 ; CHECK: UNROLLING loop %loop.2.header by 4 with a breakout at trip 0 ; CHECK: Merging: +; CHECK: Loop Unroll: F[foo] Loop %loop.header +; CHECK: Loop Size = 18 +; CHECK: Trip Count = 512 +; CHECK: Trip Multiple = 512 +; CHECK: UNROLLING loop %loop.header by 4 with a breakout at trip 0 +; CHECK: Merging: ; CHECK: %counter = phi i32 [ 0, %entry ], [ %inc.3, %loop.inc.3 ] ; CHECK: %val = add nuw nsw i32 %counter, 5 ; CHECK: %val1 = add nuw nsw i32 %counter, 6 Index: llvm/test/Other/loop-pass-ordering.ll =================================================================== --- llvm/test/Other/loop-pass-ordering.ll +++ llvm/test/Other/loop-pass-ordering.ll @@ -8,11 +8,11 @@ ; / \ \ ; loop.0.0 loop.0.1 loop.1.0 ; +; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.1.0 +; CHECK: Running pass: NoOpLoopPass on Loop at depth 1 containing: %loop.1 ; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.0.0 ; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.0.1 ; CHECK: Running pass: NoOpLoopPass on Loop at depth 1 containing: %loop.0 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 2 containing: %loop.1.0 -; CHECK: Running pass: NoOpLoopPass on Loop at depth 1 containing: %loop.1 define void @f() { entry: Index: llvm/test/Transforms/IndVarSimplify/loop-order-on-new-loop-pass-manager.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/IndVarSimplify/loop-order-on-new-loop-pass-manager.ll @@ -0,0 +1,46 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -O2 -S < %s | FileCheck %s + +%0 = type { i8*, %1*, i16, [256 x i8], [256 x %2], i32, i32, i32, i32, i32, i32, i32, i8, i32, i32, %4, %5, i32, i32 } +%1 = type { i16, i16 } +%2 = type { %3*, i32, i32 } +%3 = type { i32, i32 } +%4 = type { i32 } +%5 = type { i32 } + +; Function Attrs: norecurse nounwind readonly +define dso_local void @test(%0* nocapture readonly %0) { +; CHECK-LABEL: @test( +; CHECK-NEXT: .preheader.preheader: +; CHECK-NEXT: ret void +; + %2 = getelementptr inbounds %0, %0* %0, i64 0, i32 11 + %3 = load i32, i32* %2, align 8 + %4 = icmp eq i32 %3, 0 + br label %5 + +5: ; preds = %5, %1 + %6 = phi i8 [ 0, %1 ], [ %9, %5 ] + %7 = phi i32 [ 1, %1 ], [ %8, %5 ] + %8 = add nuw nsw i32 %7, 1 + %9 = select i1 %4, i8 1, i8 %6 + %10 = and i8 %9, 1 + %11 = icmp eq i8 %10, 0 + br i1 %11, label %5, label %12, !llvm.loop !0 + +12: ; preds = %5 + %13 = phi i32 [ %8, %5 ] + br label %14 + +14: ; preds = %14, %12 + %15 = phi i32 [ %16, %14 ], [ %13, %12 ] + %16 = add nsw i32 %15, -1 + %17 = icmp sgt i32 %15, 0 + br i1 %17, label %14, label %18 + +18: ; preds = %14 + ret void +} + +!0 = distinct !{!0, !1} +!1 = !{!"llvm.loop.mustprogress"} Index: llvm/test/Transforms/IndVarSimplify/scev-expander-preserve-lcssa.ll =================================================================== --- llvm/test/Transforms/IndVarSimplify/scev-expander-preserve-lcssa.ll +++ llvm/test/Transforms/IndVarSimplify/scev-expander-preserve-lcssa.ll @@ -113,10 +113,13 @@ ; CHECK: for.body84.preheader: ; CHECK-NEXT: br label [[FOR_BODY84:%.*]] ; CHECK: for.body84: +; CHECK-NEXT: [[I_144:%.*]] = phi i32 [ [[INC:%.*]], [[IF_END106:%.*]] ], [ 0, [[FOR_BODY84_PREHEADER]] ] ; CHECK-NEXT: [[C_2:%.*]] = call i1 @cond() -; CHECK-NEXT: br i1 [[C_2]], label [[IF_END106:%.*]], label [[RETURN_LOOPEXIT:%.*]] +; CHECK-NEXT: br i1 [[C_2]], label [[IF_END106]], label [[RETURN_LOOPEXIT:%.*]] ; CHECK: if.end106: -; CHECK-NEXT: br i1 false, label [[FOR_BODY84]], label [[RETURN_LOOPEXIT]] +; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_144]], 1 +; CHECK-NEXT: [[CMP82:%.*]] = icmp slt i32 [[INC]], [[I_0_LCSSA2]] +; CHECK-NEXT: br i1 [[CMP82]], label [[FOR_BODY84]], label [[RETURN_LOOPEXIT]] ; CHECK: return.loopexit: ; CHECK-NEXT: br label [[RETURN]] ; CHECK: return.loopexit1: Index: llvm/test/Transforms/LoopUnroll/X86/store_cost.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/X86/store_cost.ll +++ llvm/test/Transforms/LoopUnroll/X86/store_cost.ll @@ -3,12 +3,12 @@ target triple = "x86_64-unknown-linux-gnu" -; CHECK: Loop Unroll: F[foo] Loop %loop.header -; CHECK: Loop Size = 25 -; CHECK: UNROLLING loop %loop.header by 2 ; CHECK: Loop Unroll: F[foo] Loop %loop.2.header ; CHECK: Loop Size = 27 ; CHECK-NOT: UNROLLING loop %loop.2.header +; CHECK: Loop Unroll: F[foo] Loop %loop.header +; CHECK: Loop Size = 25 +; CHECK: UNROLLING loop %loop.header by 2 define void @foo(i32 * %out) { entry: Index: llvm/test/Transforms/LoopUnroll/revisit.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/revisit.ll +++ llvm/test/Transforms/LoopUnroll/revisit.ll @@ -59,13 +59,13 @@ ; ; Unrolling occurs, so we visit what were the inner loops twice over. First we ; visit their clones, and then we visit the original loops re-parented. -; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.1.1
-; CHECK-NOT: LoopFullUnrollPass -; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0.1
+; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0
; CHECK-NOT: LoopFullUnrollPass ; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.1
; CHECK-NOT: LoopFullUnrollPass -; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0
+; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0.1
+; CHECK-NOT: LoopFullUnrollPass +; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.1.1
; CHECK-NOT: LoopFullUnrollPass l0.latch: @@ -125,13 +125,13 @@ ; ; Partial unrolling occurs which introduces both new child loops and new sibling ; loops. We only visit the child loops in a special mode, not by default. -; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.0
-; CHECK-CHILDREN-NOT: LoopFullUnrollPass -; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.1
+; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.1.1
; CHECK-CHILDREN-NOT: LoopFullUnrollPass ; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.0.1
; CHECK-CHILDREN-NOT: LoopFullUnrollPass -; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.1.1
+; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.1
+; CHECK-CHILDREN-NOT: LoopFullUnrollPass +; CHECK-CHILDREN: LoopFullUnrollPass on Loop at depth 3 containing: %l0.0.0
; CHECK-CHILDREN-NOT: LoopFullUnrollPass ; ; When we revisit children, we also revisit the current loop. @@ -140,10 +140,10 @@ ; ; Revisit the children of the outer loop that are part of the epilogue. ; -; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0.epil
-; CHECK-NOT: LoopFullUnrollPass ; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.1.epil
; CHECK-NOT: LoopFullUnrollPass +; CHECK: LoopFullUnrollPass on Loop at depth 2 containing: %l0.0.0.epil
+; CHECK-NOT: LoopFullUnrollPass l0.latch: br label %l0 ; CHECK: LoopFullUnrollPass on Loop at depth 1 containing: %l0
Index: llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll +++ llvm/test/Transforms/LoopUnroll/unroll-loop-invalidation.ll @@ -27,15 +27,15 @@ ; CHECK-NOT: Invalidating analysis: LoopAccessAnalysis on inner1.header.1 ; CHECK: Starting Loop pass manager run. ; CHECK: Running pass: LoopAccessInfoPrinterPass -; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 1 containing: %inner1.header +; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 1 containing: %inner1.header.1 ; CHECK: Loop access info in function 'test': -; CHECK: inner1.header: +; CHECK: inner1.header.1: ; CHECK: Finished Loop pass manager run. ; CHECK: Starting Loop pass manager run. ; CHECK: Running pass: LoopAccessInfoPrinterPass -; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 1 containing: %inner1.header.1 +; CHECK: Running analysis: LoopAccessAnalysis on Loop at depth 1 containing: %inner1.header ; CHECK: Loop access info in function 'test': -; CHECK: inner1.header.1: +; CHECK: inner1.header: ; CHECK: Finished Loop pass manager run. target triple = "x86_64-unknown-linux-gnu" Index: llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp =================================================================== --- llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp +++ llvm/unittests/Transforms/Scalar/LoopPassManagerTest.cpp @@ -1154,6 +1154,13 @@ ::testing::InSequence MakeExpectationsSequenced; // We run loop passes three times over each of the loops. + EXPECT_CALL(MLPHandle, run(HasName("loop.2"), _, _, _)) + .WillOnce(Invoke(getLoopAnalysisResult)); + EXPECT_CALL(MLAHandle, run(HasName("loop.2"), _, _)); + EXPECT_CALL(MLPHandle, run(HasName("loop.2"), _, _, _)) + .Times(2) + .WillRepeatedly(Invoke(getLoopAnalysisResult)); + EXPECT_CALL(MLPHandle, run(HasName("loop.0.0"), _, _, _)) .WillOnce(Invoke(getLoopAnalysisResult)); EXPECT_CALL(MLAHandle, run(HasName("loop.0.0"), _, _)); @@ -1253,15 +1260,6 @@ return PreservedAnalyses::all(); })); - EXPECT_CALL(MLPHandle, run(HasName("loop.0.3"), _, _, _)) - .WillOnce(Invoke(getLoopAnalysisResult)); - EXPECT_CALL(MLAHandle, run(HasName("loop.0.3"), _, _)); - EXPECT_CALL(MLPHandle, run(HasName("loop.0.3"), _, _, _)) - .Times(2) - .WillRepeatedly(Invoke(getLoopAnalysisResult)); - - // Note that we need to visit the inner loop of this added sibling before the - // sibling itself! EXPECT_CALL(MLPHandle, run(HasName("loop.0.4.0"), _, _, _)) .WillOnce(Invoke(getLoopAnalysisResult)); EXPECT_CALL(MLAHandle, run(HasName("loop.0.4.0"), _, _)); @@ -1276,6 +1274,13 @@ .Times(2) .WillRepeatedly(Invoke(getLoopAnalysisResult)); + EXPECT_CALL(MLPHandle, run(HasName("loop.0.3"), _, _, _)) + .WillOnce(Invoke(getLoopAnalysisResult)); + EXPECT_CALL(MLAHandle, run(HasName("loop.0.3"), _, _)); + EXPECT_CALL(MLPHandle, run(HasName("loop.0.3"), _, _, _)) + .Times(2) + .WillRepeatedly(Invoke(getLoopAnalysisResult)); + // And only now do we visit the outermost loop of the nest. EXPECT_CALL(MLPHandle, run(HasName("loop.0"), _, _, _)) .WillOnce(Invoke(getLoopAnalysisResult)); @@ -1311,13 +1316,6 @@ .Times(2) .WillRepeatedly(Invoke(getLoopAnalysisResult)); - EXPECT_CALL(MLPHandle, run(HasName("loop.2"), _, _, _)) - .WillOnce(Invoke(getLoopAnalysisResult)); - EXPECT_CALL(MLAHandle, run(HasName("loop.2"), _, _)); - EXPECT_CALL(MLPHandle, run(HasName("loop.2"), _, _, _)) - .Times(2) - .WillRepeatedly(Invoke(getLoopAnalysisResult)); - // Now that all the expected actions are registered, run the pipeline over // our module. All of our expectations are verified when the test finishes. MPM.run(*M, MAM);