]> granicus.if.org Git - llvm/commitdiff
Adding test cases showing the behavior of LoopUnrollPass according to optnone and...
authorMarianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com>
Wed, 4 May 2016 17:45:40 +0000 (17:45 +0000)
committerMarianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com>
Wed, 4 May 2016 17:45:40 +0000 (17:45 +0000)
The unroll pass was disabled by clang in /Os. Those new test cases shows that the pass will behave correctly even if it is not fully disabled. This patch is related in some way to the clang commit (http://reviews.llvm.org/D19827), which re-enables the pass in /Os.

Differential Revision: http://reviews.llvm.org/D19870

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268524 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/LoopUnroll/unroll-opt-attribute.ll [new file with mode: 0644]

diff --git a/test/Transforms/LoopUnroll/unroll-opt-attribute.ll b/test/Transforms/LoopUnroll/unroll-opt-attribute.ll
new file mode 100644 (file)
index 0000000..334162f
--- /dev/null
@@ -0,0 +1,160 @@
+; RUN: opt < %s -S -loop-unroll -unroll-count=4 | FileCheck -check-prefix=CHECK_COUNT4 %s\r
+; RUN: opt < %s -S -loop-unroll | FileCheck -check-prefix=CHECK_NOCOUNT %s\r
+\r
+\r
+;///////////////////// TEST 1 //////////////////////////////\r
+\r
+; This test shows that with optsize attribute, the loop is unrolled\r
+; according to the specified unroll factor.\r
+\r
+define void @Test1() nounwind optsize {\r
+entry:\r
+  br label %loop\r
+\r
+loop:\r
+  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]\r
+  %inc = add i32 %iv, 1\r
+  %exitcnd = icmp uge i32 %inc, 1024\r
+  br i1 %exitcnd, label %exit, label %loop\r
+\r
+exit:\r
+  ret void\r
+}\r
+\r
+; CHECK_COUNT4-LABEL: @Test1\r
+; CHECK_COUNT4:      phi\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: icmp\r
+\r
+\r
+;///////////////////// TEST 2 //////////////////////////////\r
+\r
+; This test shows that with minsize attribute, the loop is unrolled\r
+; according to the specified unroll factor.\r
+\r
+define void @Test2() nounwind minsize {\r
+entry:\r
+  br label %loop\r
+\r
+loop:\r
+  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]\r
+  %inc = add i32 %iv, 1\r
+  %exitcnd = icmp uge i32 %inc, 1024\r
+  br i1 %exitcnd, label %exit, label %loop\r
+\r
+exit:\r
+  ret void\r
+}\r
+\r
+; CHECK_COUNT4-LABEL: @Test2\r
+; CHECK_COUNT4:      phi\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: icmp\r
+\r
+\r
+;///////////////////// TEST 3 //////////////////////////////\r
+\r
+; This test shows that with optnone attribute, the loop is not unrolled\r
+; even if an unroll factor was specified.\r
+\r
+define void @Test3() nounwind optnone noinline {\r
+entry:\r
+  br label %loop\r
+\r
+loop:\r
+  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]\r
+  %inc = add i32 %iv, 1\r
+  %exitcnd = icmp uge i32 %inc, 1024\r
+  br i1 %exitcnd, label %exit, label %loop\r
+\r
+exit:\r
+  ret void\r
+}\r
+\r
+; CHECK_COUNT4-LABEL: @Test3\r
+; CHECK_COUNT4:      phi\r
+; CHECK_COUNT4-NEXT: add\r
+; CHECK_COUNT4-NEXT: icmp\r
+\r
+\r
+;///////////////////// TEST 4 //////////////////////////////\r
+\r
+; This test shows that without any attribute, this loop is fully unrolled \r
+; by default.\r
+\r
+@tab = common global [24 x i32] zeroinitializer, align 4\r
+\r
+define i32 @Test4() {\r
+entry:\r
+  br label %for.body\r
+\r
+for.body:                                         ; preds = %for.body, %entry\r
+  %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]\r
+  %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05\r
+  store i32 %i.05, i32* %arrayidx, align 4\r
+  %inc = add nuw nsw i32 %i.05, 1\r
+  %exitcond = icmp eq i32 %inc, 24\r
+  br i1 %exitcond, label %for.end, label %for.body\r
+\r
+for.end:                                          ; preds = %for.body\r
+  ret i32 42\r
+}\r
+\r
+; CHECK_NOCOUNT-LABEL: @Test4\r
+; CHECK_NOCOUNT:      store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: store\r
+; CHECK_NOCOUNT-NEXT: ret\r
+\r
+\r
+;///////////////////// TEST 5 //////////////////////////////\r
+\r
+; This test shows that with optsize attribute, this loop is not unrolled \r
+; by default.\r
+\r
+define i32 @Test5() optsize {\r
+entry:\r
+  br label %for.body\r
+\r
+for.body:                                         ; preds = %for.body, %entry\r
+  %i.05 = phi i32 [ 0, %entry ], [ %inc, %for.body ]\r
+  %arrayidx = getelementptr inbounds [24 x i32], [24 x i32]* @tab, i32 0, i32 %i.05\r
+  store i32 %i.05, i32* %arrayidx, align 4\r
+  %inc = add nuw nsw i32 %i.05, 1\r
+  %exitcond = icmp eq i32 %inc, 24\r
+  br i1 %exitcond, label %for.end, label %for.body\r
+\r
+for.end:                                          ; preds = %for.body\r
+  ret i32 42\r
+}\r
+\r
+; CHECK_NOCOUNT-LABEL: @Test5\r
+; CHECK_NOCOUNT:      phi\r
+; CHECK_NOCOUNT:      icmp\r