aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2013-05-24 12:26:52 +0000
committerDiego Novillo <dnovillo@google.com>2013-05-24 12:26:52 +0000
commit77226a03dca98e6237c1068f2652fe41bea7b687 (patch)
tree3a8cb78a478d9e82735484091ae29647e3ec9002 /test
parent49a6a8d8f2994249c81b7914b07015714748a55c (diff)
downloadexternal_llvm-77226a03dca98e6237c1068f2652fe41bea7b687.zip
external_llvm-77226a03dca98e6237c1068f2652fe41bea7b687.tar.gz
external_llvm-77226a03dca98e6237c1068f2652fe41bea7b687.tar.bz2
Add a new function attribute 'cold' to functions.
Other than recognizing the attribute, the patch does little else. It changes the branch probability analyzer so that edges into blocks postdominated by a cold function are given low weight. Added analysis and code generation tests. Added documentation for the new attribute. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182638 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/BranchProbabilityInfo/basic.ll58
-rw-r--r--test/CodeGen/X86/block-placement.ll32
-rw-r--r--test/Feature/cold.ll9
3 files changed, 99 insertions, 0 deletions
diff --git a/test/Analysis/BranchProbabilityInfo/basic.ll b/test/Analysis/BranchProbabilityInfo/basic.ll
index 08adfa8..c6e1bde 100644
--- a/test/Analysis/BranchProbabilityInfo/basic.ll
+++ b/test/Analysis/BranchProbabilityInfo/basic.ll
@@ -115,3 +115,61 @@ return:
}
!2 = metadata !{metadata !"branch_weights", i32 7, i32 6, i32 4, i32 4, i32 64}
+
+declare void @coldfunc() cold
+
+define i32 @test5(i32 %a, i32 %b, i1 %flag) {
+; CHECK: Printing analysis {{.*}} for function 'test5'
+entry:
+ br i1 %flag, label %then, label %else
+; CHECK: edge entry -> then probability is 4 / 68
+; CHECK: edge entry -> else probability is 64 / 68
+
+then:
+ call void @coldfunc()
+ br label %exit
+; CHECK: edge then -> exit probability is 16 / 16 = 100%
+
+else:
+ br label %exit
+; CHECK: edge else -> exit probability is 16 / 16 = 100%
+
+exit:
+ %result = phi i32 [ %a, %then ], [ %b, %else ]
+ ret i32 %result
+}
+
+declare i32 @regular_function(i32 %i)
+
+define i32 @test_cold_call_sites(i32* %a) {
+; Test that edges to blocks post-dominated by cold call sites
+; are marked as not expected to be taken.
+; TODO(dnovillo) The calls to regular_function should not be merged, but
+; they are currently being merged. Convert this into a code generation test
+; after that is fixed.
+
+; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites'
+; CHECK: edge entry -> then probability is 4 / 68 = 5.88235%
+; CHECK: edge entry -> else probability is 64 / 68 = 94.1176% [HOT edge]
+
+entry:
+ %gep1 = getelementptr i32* %a, i32 1
+ %val1 = load i32* %gep1
+ %cond1 = icmp ugt i32 %val1, 1
+ br i1 %cond1, label %then, label %else
+
+then:
+ ; This function is not declared cold, but this call site is.
+ %val4 = call i32 @regular_function(i32 %val1) cold
+ br label %exit
+
+else:
+ %gep2 = getelementptr i32* %a, i32 2
+ %val2 = load i32* %gep2
+ %val3 = call i32 @regular_function(i32 %val2)
+ br label %exit
+
+exit:
+ %ret = phi i32 [ %val4, %then ], [ %val3, %else ]
+ ret i32 %ret
+}
diff --git a/test/CodeGen/X86/block-placement.ll b/test/CodeGen/X86/block-placement.ll
index 271fb42..be627e0 100644
--- a/test/CodeGen/X86/block-placement.ll
+++ b/test/CodeGen/X86/block-placement.ll
@@ -1089,3 +1089,35 @@ while.end:
store double %rra.0, double* %arrayidx34, align 8
br label %for.cond
}
+
+declare void @cold_function() cold
+
+define i32 @test_cold_calls(i32* %a) {
+; Test that edges to blocks post-dominated by cold calls are
+; marked as not expected to be taken. They should be laid out
+; at the bottom.
+; CHECK: test_cold_calls:
+; CHECK: %entry
+; CHECK: %else
+; CHECK: %exit
+; CHECK: %then
+
+entry:
+ %gep1 = getelementptr i32* %a, i32 1
+ %val1 = load i32* %gep1
+ %cond1 = icmp ugt i32 %val1, 1
+ br i1 %cond1, label %then, label %else
+
+then:
+ call void @cold_function()
+ br label %exit
+
+else:
+ %gep2 = getelementptr i32* %a, i32 2
+ %val2 = load i32* %gep2
+ br label %exit
+
+exit:
+ %ret = phi i32 [ %val1, %then ], [ %val2, %else ]
+ ret i32 %ret
+}
diff --git a/test/Feature/cold.ll b/test/Feature/cold.ll
new file mode 100644
index 0000000..dcf79c5
--- /dev/null
+++ b/test/Feature/cold.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; CHECK: @fun() #0
+define void @fun() #0 {
+ ret void
+}
+
+; CHECK: attributes #0 = { cold }
+attributes #0 = { cold }