From a56999c5decca0023e5ce481fc08571e227e3aa3 Mon Sep 17 00:00:00 2001 From: Kevin Qin Date: Thu, 12 Mar 2015 05:36:01 +0000 Subject: [PATCH] Reapply 'Run LICM pass after loop unrolling pass.' It's firstly committed at r231630, and reverted at r231635. Function pass InstructionSimplifier is inserted as barrier to make sure loop unroll pass won't affect on LICM pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232011 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/PassManagerBuilder.cpp | 13 ++++++- test/Transforms/LoopUnroll/runtime-loop4.ll | 43 +++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/LoopUnroll/runtime-loop4.ll diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index 9fd84d845d5..5928eb1d9c3 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -363,9 +363,20 @@ void PassManagerBuilder::populateModulePassManager( MPM.add(createCFGSimplificationPass()); MPM.add(createInstructionCombiningPass()); - if (!DisableUnrollLoops) + if (!DisableUnrollLoops) { MPM.add(createLoopUnrollPass()); // Unroll small loops + // This is a barrier pass to avoid combine LICM pass and loop unroll pass + // within same loop pass manager. + MPM.add(createInstructionSimplifierPass()); + + // Runtime unrolling will introduce runtime check in loop prologue. If the + // unrolled loop is a inner loop, then the prologue will be inside the + // outer loop. LICM pass can help to promote the runtime check out if the + // checked value is loop invariant. + MPM.add(createLICMPass()); + } + // After vectorization and unrolling, assume intrinsics may tell us more // about pointer alignments. MPM.add(createAlignmentFromAssumptionsPass()); diff --git a/test/Transforms/LoopUnroll/runtime-loop4.ll b/test/Transforms/LoopUnroll/runtime-loop4.ll new file mode 100644 index 00000000000..9be0ffd23d3 --- /dev/null +++ b/test/Transforms/LoopUnroll/runtime-loop4.ll @@ -0,0 +1,43 @@ +; RUN: opt < %s -S -O2 -unroll-runtime=true | FileCheck %s + +; Check runtime unrolling prologue can be promoted by LICM pass. + +; CHECK: entry: +; CHECK: %xtraiter +; CHECK: %lcmp.mod +; CHECK: loop1: +; CHECK: br i1 %lcmp.mod +; CHECK: loop2.prol: + +define void @unroll(i32 %iter, i32* %addr1, i32* %addr2) nounwind { +entry: + br label %loop1 + +loop1: + %iv1 = phi i32 [ 0, %entry ], [ %inc1, %loop1.latch ] + %offset1 = getelementptr i32, i32* %addr1, i32 %iv1 + store i32 %iv1, i32* %offset1, align 4 + br label %loop2.header + +loop2.header: + br label %loop2 + +loop2: + %iv2 = phi i32 [ 0, %loop2.header ], [ %inc2, %loop2 ] + %offset2 = getelementptr i32, i32* %addr2, i32 %iv2 + store i32 %iv2, i32* %offset2, align 4 + %inc2 = add i32 %iv2, 1 + %exitcnd2 = icmp uge i32 %inc2, %iter + br i1 %exitcnd2, label %exit2, label %loop2 + +exit2: + br label %loop1.latch + +loop1.latch: + %inc1 = add i32 %iv1, 1 + %exitcnd1 = icmp uge i32 %inc1, 1024 + br i1 %exitcnd1, label %exit, label %loop1 + +exit: + ret void +} -- 2.34.1