From: Evan Cheng Date: Thu, 27 Nov 2008 01:16:00 +0000 (+0000) Subject: Avoid inserting noop's in the middle of a loop. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=df90841690c4c1c30aa9ea8cfd37c429bb1e9d0b;p=oota-llvm.git Avoid inserting noop's in the middle of a loop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60141 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/LoopAligner.cpp b/lib/CodeGen/LoopAligner.cpp index b8d00595d8a..b67f5c3bf91 100644 --- a/lib/CodeGen/LoopAligner.cpp +++ b/lib/CodeGen/LoopAligner.cpp @@ -64,8 +64,14 @@ bool LoopAligner::runOnMachineFunction(MachineFunction &MF) { for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { MachineBasicBlock *MBB = I; - if (MLI->isLoopHeader(MBB)) + if (MLI->isLoopHeader(MBB)) { + MachineBasicBlock *PredBB = prior(I); + if (MLI->getLoopFor(MBB) == MLI->getLoopFor(PredBB)) + // If previously BB is in the same loop, don't align this BB. We want + // to prevent adding noop's inside a loop. + continue; MBB->setAlignment(Align); + } } return true; diff --git a/test/CodeGen/X86/avoid-loop-align.ll b/test/CodeGen/X86/avoid-loop-align.ll new file mode 100644 index 00000000000..dfc58181d90 --- /dev/null +++ b/test/CodeGen/X86/avoid-loop-align.ll @@ -0,0 +1,32 @@ +; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin | grep align | count 1 + +@A = common global [100 x i32] zeroinitializer, align 32 ; <[100 x i32]*> [#uses=1] + +define i8* @test(i8* %Q, i32* %L) nounwind { +entry: + %tmp = tail call i32 (...)* @foo() nounwind ; [#uses=2] + %tmp1 = inttoptr i32 %tmp to i8* ; [#uses=1] + br label %bb1 + +bb: ; preds = %bb1, %bb1 + %indvar.next = add i32 %P.0.rec, 1 ; [#uses=1] + br label %bb1 + +bb1: ; preds = %bb, %entry + %P.0.rec = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; [#uses=2] + %P.0 = getelementptr i8* %tmp1, i32 %P.0.rec ; [#uses=3] + %tmp2 = load i8* %P.0, align 1 ; [#uses=1] + switch i8 %tmp2, label %bb4 [ + i8 12, label %bb + i8 42, label %bb + ] + +bb4: ; preds = %bb1 + %tmp3 = ptrtoint i8* %P.0 to i32 ; [#uses=1] + %tmp4 = sub i32 %tmp3, %tmp ; [#uses=1] + %tmp5 = getelementptr [100 x i32]* @A, i32 0, i32 %tmp4 ; [#uses=1] + store i32 4, i32* %tmp5, align 4 + ret i8* %P.0 +} + +declare i32 @foo(...)