Index: llvm/include/llvm/Transforms/Utils/LoopUtils.h =================================================================== --- llvm/include/llvm/Transforms/Utils/LoopUtils.h +++ llvm/include/llvm/Transforms/Utils/LoopUtils.h @@ -465,12 +465,7 @@ /// Utility that implements appending of loops onto a worklist given LoopInfo. /// Calls the templated utility taking a Range of loops, handing it the Loops /// in LoopInfo, iterated in reverse. This is because the loops are stored in -/// RPO w.r.t. the control flow graph in LoopInfo. For the purpose of unrolling, -/// loop deletion, and LICM, we largely want to work forward across the CFG so -/// that we visit defs before uses and can propagate simplifications from one -/// loop nest into the next. Calls appendReversedLoopsToWorklist with the -/// already reversed loops in LI. -/// FIXME: Consider changing the order in LoopInfo. +/// RPO w.r.t. the control flow graph in LoopInfo. void appendLoopsToWorklist(LoopInfo &, SmallPriorityWorklist &); /// Recursively clone the specified loop and all of its children, Index: llvm/lib/Transforms/Utils/LoopUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/LoopUtils.cpp +++ llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1543,7 +1543,7 @@ void llvm::appendLoopsToWorklist(LoopInfo &LI, SmallPriorityWorklist &Worklist) { - appendReversedLoopsToWorklist(LI, Worklist); + appendLoopsToWorklist(LI.getTopLevelLoopsVector(), Worklist); } Loop *llvm::cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM, 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/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"), _, _)); @@ -1311,13 +1318,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);