summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/LoopUnroll
diff options
context:
space:
mode:
authorSerguei Katkov <serguei.katkov@azul.com>2019-08-02 04:29:23 +0000
committerSerguei Katkov <serguei.katkov@azul.com>2019-08-02 04:29:23 +0000
commitbbdcc8211111fa8e723a1754e0962e56141a2890 (patch)
treef3496e17cdf7667382d11d263014a40e166093e3 /llvm/test/Transforms/LoopUnroll
parent6fe00a21f2436490f1c05247c612866dd59c03a5 (diff)
downloadbcm5719-llvm-bbdcc8211111fa8e723a1754e0962e56141a2890.tar.gz
bcm5719-llvm-bbdcc8211111fa8e723a1754e0962e56141a2890.zip
[Loop Peeling] Do not close further unroll/peel if profile based peeling was not used.
Current peeling cost model can decide to peel off not all iterations but only some of them to eliminate conditions on phi. At the same time if any peeling happens the door for further unroll/peel optimizations on that loop closes because the part of the code thinks that if peeling happened it is profile based peeling and all iterations are peeled off. To resolve this inconsistency the patch provides the flag which states whether the full peeling basing on profile is enabled or not and peeling cost model is able to modify this field like it does not PeelCount. In a separate patch I will introduce an option to allow/disallow peeling basing on profile. To avoid infinite loop peeling the patch tracks the total number of peeled iteration through llvm.loop.peeled.count loop metadata. Reviewers: reames, fhahn Reviewed By: reames Subscribers: hiraditya, zzheng, dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D64972 llvm-svn: 367647
Diffstat (limited to 'llvm/test/Transforms/LoopUnroll')
-rw-r--r--llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-1.ll43
-rw-r--r--llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-2.ll43
-rw-r--r--llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll1
3 files changed, 87 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-1.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-1.ll
new file mode 100644
index 00000000000..0c56229d064
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-1.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -loop-unroll -loop-unroll -verify-dom-info -debug-only=loop-unroll -unroll-peel-max-count=7 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+declare void @f1()
+declare void @f2()
+
+; Check that we can peel off iterations that make conditions true.
+; The second invocation of loop-unroll will do profile based peeling of
+; remained iterations.
+define void @test1(i32 %k) !prof !4 {
+; CHECK: Loop Unroll: F[test1] Loop %for.body
+; CHECK: PEELING loop %for.body with iteration count 2!
+; CHECK: PEELING loop %for.body with iteration count 4!
+; CHECK: llvm.loop.unroll.disable
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
+ %cmp1 = icmp ult i32 %i.05, 2
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then:
+ call void @f1()
+ br label %for.inc
+
+if.else:
+ call void @f2()
+ br label %for.inc
+
+for.inc:
+ %inc = add nsw i32 %i.05, 1
+ %cmp = icmp slt i32 %inc, %k
+ br i1 %cmp, label %for.body, label %for.end, !llvm.loop !1, !prof !2
+
+for.end:
+ ret void
+}
+
+!1 = distinct !{!1}
+!2 = !{!"branch_weights", i32 6, i32 1}
+!4 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-2.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-2.ll
new file mode 100644
index 00000000000..6462283dfaf
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions-pgo-2.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -loop-unroll -loop-unroll -verify-dom-info -debug-only=loop-unroll -unroll-peel-max-count=7 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+declare void @f1()
+declare void @f2()
+
+; Check that we can peel off iterations that make conditions true.
+; The second invocation of loop-unroll will NOT do profile based peeling of
+; remained iterations because the total number of peeled iterations exceeds
+; threashold specified with -unroll-peel-max-count=7.
+define void @test2(i32 %k) !prof !4 {
+; CHECK: Loop Unroll: F[test2] Loop %for.body
+; CHECK: PEELING loop %for.body with iteration count 2!
+; CHECK-NOT: llvm.loop.unroll.disable
+for.body.lr.ph:
+ br label %for.body
+
+for.body:
+ %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
+ %cmp1 = icmp ult i32 %i.05, 2
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then:
+ call void @f1()
+ br label %for.inc
+
+if.else:
+ call void @f2()
+ br label %for.inc
+
+for.inc:
+ %inc = add nsw i32 %i.05, 1
+ %cmp = icmp slt i32 %inc, %k
+ br i1 %cmp, label %for.body, label %for.end, !llvm.loop !1, !prof !3
+
+for.end:
+ ret void
+}
+
+!1 = distinct !{!1}
+!3 = !{!"branch_weights", i32 8, i32 1}
+!4 = !{!"function_entry_count", i64 1}
diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll
index a9937d9db99..0217e9384f9 100644
--- a/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll
+++ b/llvm/test/Transforms/LoopUnroll/peel-loop-conditions.ll
@@ -643,3 +643,4 @@ for.inc:
for.end:
ret void
}
+; CHECK-NOT: llvm.loop.unroll.disable \ No newline at end of file
OpenPOWER on IntegriCloud