summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2014-03-17 19:57:04 +0000
committerDan Gohman <dan433584@gmail.com>2014-03-17 19:57:04 +0000
commit43873d4f73f85b434c0828fab5f956fd08ac3757 (patch)
treef0c307871f0aa702e4e07c1aff80026299c4f0db /test
parent92fca73d521758012e0e425eac33bb77e888112e (diff)
downloadllvm-43873d4f73f85b434c0828fab5f956fd08ac3757.tar.gz
llvm-43873d4f73f85b434c0828fab5f956fd08ac3757.tar.bz2
llvm-43873d4f73f85b434c0828fab5f956fd08ac3757.tar.xz
Use range metadata instead of introducing selects.
When GlobalOpt has determined that a GlobalVariable only ever has two values, it would convert the GlobalVariable to a boolean, and introduce SelectInsts at every load, to choose between the two possible values. These SelectInsts introduce overhead and other unpleasantness. This patch makes GlobalOpt just add range metadata to loads from such GlobalVariables instead. This enables the same main optimization (as seen in test/Transforms/GlobalOpt/integer-bool.ll), without introducing selects. The main downside is that it doesn't get the memory savings of shrinking such GlobalVariables, but this is expected to be negligible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204076 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Transforms/GlobalOpt/integer-bool.ll9
-rw-r--r--test/Transforms/GlobalOpt/twostore-gv-range.ll52
2 files changed, 57 insertions, 4 deletions
diff --git a/test/Transforms/GlobalOpt/integer-bool.ll b/test/Transforms/GlobalOpt/integer-bool.ll
index abf5fdd2ef..fc45c82935 100644
--- a/test/Transforms/GlobalOpt/integer-bool.ll
+++ b/test/Transforms/GlobalOpt/integer-bool.ll
@@ -1,20 +1,21 @@
; RUN: opt < %s -S -globalopt -instcombine | FileCheck %s
-;; check that global opt turns integers that only hold 0 or 1 into bools.
+;; check that global opt annotates loads from global variales that only hold 0 or 1
+;; such that instcombine can optimize accordingly.
@G = internal addrspace(1) global i32 0
; CHECK: @G
; CHECK: addrspace(1)
-; CHECK: global i1 false
+; CHECK: global i32 0
define void @set1() {
store i32 0, i32 addrspace(1)* @G
-; CHECK: store i1 false
+; CHECK: store i32 0
ret void
}
define void @set2() {
store i32 1, i32 addrspace(1)* @G
-; CHECK: store i1 true
+; CHECK: store i32 1
ret void
}
diff --git a/test/Transforms/GlobalOpt/twostore-gv-range.ll b/test/Transforms/GlobalOpt/twostore-gv-range.ll
new file mode 100644
index 0000000000..84629ddb71
--- /dev/null
+++ b/test/Transforms/GlobalOpt/twostore-gv-range.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -S -globalopt | FileCheck %s
+;; check that global opt annotates loads from global variales that have
+;; constant values stored to them.
+
+@G = internal global i32 5
+@H = internal global i32 7
+@I = internal global i32 17
+@J = internal global i32 29
+@K = internal global i32 31
+
+define void @set() {
+ store i32 6, i32* @G
+ store i32 13, i32* @H
+ store i32 16, i32* @I
+ store i32 29, i32* @J
+ store i32 -37, i32* @K
+ ret void
+}
+
+define i32 @getG() {
+; CHECK: %t = load i32* @G, !range [[G:![0-9]+]]
+ %t = load i32* @G
+ ret i32 %t
+}
+define i32 @getH() {
+; CHECK: %t = load i32* @H, !range [[H:![0-9]+]]
+ %t = load i32* @H
+ ret i32 %t
+}
+
+define i32 @getI() {
+; CHECK: %t = load i32* @I, !range [[I:![0-9]+]]
+ %t = load i32* @I
+ ret i32 %t
+}
+
+define i32 @getJ() {
+; CHECK: ret i32 29
+ %t = load i32* @J
+ ret i32 %t
+}
+
+define i32 @getK() {
+; CHECK: %t = load i32* @K, !range [[K:![0-9]+]]
+ %t = load i32* @K
+ ret i32 %t
+}
+
+; CHECK: [[G]] = metadata !{i32 5, i32 7}
+; CHECK: [[H]] = metadata !{i32 7, i32 8, i32 13, i32 14}
+; CHECK: [[I]] = metadata !{i32 16, i32 18}
+; CHECK: [[K]] = metadata !{i32 -37, i32 -36, i32 31, i32 32}