[llvm] r231630 - Run LICM pass after loop unrolling pass.

Kevin Qin kevinqindev at gmail.com
Mon Mar 9 00:23:19 PDT 2015


Hi,


I found this commit cause troubles when self-build llvm. I'm trying to
solve this right now, if it's not easy to fix by today, I will revert it
hours later.

Sorry about that,
Kevin

2015-03-09 14:14 GMT+08:00 Kevin Qin <Kevin.Qin at arm.com>:

> Author: kevinqin
> Date: Mon Mar  9 01:14:07 2015
> New Revision: 231630
>
> URL: http://llvm.org/viewvc/llvm-project?rev=231630&view=rev
> Log:
> Run LICM pass after loop unrolling pass.
>
> Runtime unrollng will introduce a runtime check in loop prologue.
> If the unrolled loop is a inner loop, then the proglogue will be inside
> the outer loop. LICM pass can help to promote the runtime check out if
> the checked value is loop invariant.
>
> Added:
>     llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll
> Modified:
>     llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
>     llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
>
> Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=231630&r1=231629&r2=231630&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Mon Mar  9
> 01:14:07 2015
> @@ -364,8 +364,14 @@ void PassManagerBuilder::populateModuleP
>    MPM.add(createCFGSimplificationPass());
>    MPM.add(createInstructionCombiningPass());
>
> -  if (!DisableUnrollLoops)
> +  if (!DisableUnrollLoops) {
>      MPM.add(createLoopUnrollPass());    // Unroll small loops
> +    // Runtime unrollng 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.
>
> Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp?rev=231630&r1=231629&r2=231630&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Mon Mar  9
> 01:14:07 2015
> @@ -142,7 +142,7 @@ static void CloneLoopBlocks(Loop *L, Val
>                              BasicBlock *InsertTop, BasicBlock *InsertBot,
>                              std::vector<BasicBlock *> &NewBlocks,
>                              LoopBlocksDFS &LoopBlocks, ValueToValueMapTy
> &VMap,
> -                            LoopInfo *LI) {
> +                            LoopInfo *LI, LPPassManager *LPM) {
>    BasicBlock *Preheader = L->getLoopPreheader();
>    BasicBlock *Header = L->getHeader();
>    BasicBlock *Latch = L->getLoopLatch();
> @@ -153,10 +153,7 @@ static void CloneLoopBlocks(Loop *L, Val
>    Loop *ParentLoop = L->getParentLoop();
>    if (!UnrollProlog) {
>      NewLoop = new Loop();
> -    if (ParentLoop)
> -      ParentLoop->addChildLoop(NewLoop);
> -    else
> -      LI->addTopLevelLoop(NewLoop);
> +    LPM->insertLoop(NewLoop, ParentLoop);
>    }
>
>    // For each block in the original loop, create a new copy,
> @@ -390,7 +387,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop
>    // the loop, otherwise we create a cloned loop to execute the extra
>    // iterations. This function adds the appropriate CFG connections.
>    CloneLoopBlocks(L, ModVal, UnrollPrologue, PH, PEnd, NewBlocks,
> LoopBlocks,
> -                  VMap, LI);
> +                  VMap, LI, LPM);
>
>    // Insert the cloned blocks into function just before the original loop
>    F->getBasicBlockList().splice(PEnd, F->getBasicBlockList(),
> NewBlocks[0],
>
> Added: llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll?rev=231630&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll (added)
> +++ llvm/trunk/test/Transforms/LoopUnroll/runtime-loop4.ll Mon Mar  9
> 01:14:07 2015
> @@ -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
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



-- 
Best Regards,

Kevin Qin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150309/b8bbed18/attachment.html>


More information about the llvm-commits mailing list