From 16295fc20b68f9a9318cada4e4d96e964b1cdd7e Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 16 Apr 2012 09:31:23 +0000 Subject: Tweak the loop rotation logic to check whether the loop is naturally laid out in a form with a fallthrough into the header and a fallthrough out of the bottom. In that case, leave the loop alone because any rotation will introduce unnecessary branches. If either side looks like it will require an explicit branch, then the rotation won't add any, do it to ensure the branch occurs outside of the loop (if possible) and maximize the benefit of the fallthrough in the bottom. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154806 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/X86/block-placement.ll | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'test/CodeGen/X86/block-placement.ll') diff --git a/test/CodeGen/X86/block-placement.ll b/test/CodeGen/X86/block-placement.ll index f3c9727605..9359fb8c12 100644 --- a/test/CodeGen/X86/block-placement.ll +++ b/test/CodeGen/X86/block-placement.ll @@ -122,14 +122,14 @@ define i32 @test_loop_early_exits(i32 %i, i32* %a) { ; Check that we sink early exit blocks out of loop bodies. ; CHECK: test_loop_early_exits: ; CHECK: %entry +; CHECK: %body1 ; CHECK: %body2 ; CHECK: %body3 ; CHECK: %body4 -; CHECK: %body1 +; CHECK: %exit ; CHECK: %bail1 ; CHECK: %bail2 ; CHECK: %bail3 -; CHECK: %exit entry: br label %body1 @@ -199,6 +199,36 @@ exit: ret i32 %base } +define i32 @test_no_loop_rotate(i32 %i, i32* %a) { +; Check that we don't try to rotate a loop which is already laid out with +; fallthrough opportunities into the top and out of the bottom. +; CHECK: test_no_loop_rotate: +; CHECK: %entry +; CHECK: %body0 +; CHECK: %body1 +; CHECK: %exit + +entry: + br label %body0 + +body0: + %iv = phi i32 [ 0, %entry ], [ %next, %body1 ] + %base = phi i32 [ 0, %entry ], [ %sum, %body1 ] + %arrayidx = getelementptr inbounds i32* %a, i32 %iv + %0 = load i32* %arrayidx + %sum = add nsw i32 %0, %base + %bailcond1 = icmp eq i32 %sum, 42 + br i1 %bailcond1, label %exit, label %body1 + +body1: + %next = add i32 %iv, 1 + %exitcond = icmp eq i32 %next, %i + br i1 %exitcond, label %exit, label %body0 + +exit: + ret i32 %base +} + define void @test_loop_rotate_reversed_blocks() { ; This test case (greatly reduced from an Olden bencmark) ensures that the loop ; rotate implementation doesn't assume that loops are laid out in a particular -- cgit v1.2.3