summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2014-11-18 17:46:32 +0000
committerPhilip Reames <listmail@philipreames.com>2014-11-18 17:46:32 +0000
commit018dbf18c4b0c3ee0f93b2da0901ba7f8246ac4f (patch)
treef31541558a61573d7790ea9c8dd9e2a3f47626d2
parentf127a2d77fe735446f59a97e316636db33ffc52b (diff)
downloadbcm5719-llvm-018dbf18c4b0c3ee0f93b2da0901ba7f8246ac4f.tar.gz
bcm5719-llvm-018dbf18c4b0c3ee0f93b2da0901ba7f8246ac4f.zip
Tweak EarlyCSE to recognize series of dead stores
EarlyCSE is giving up on the current instruction immediately when it recognizes that the current instruction makes a previous store trivially dead. There's no reason to do this. Once the previous store has been deleted, it's perfectly legal to remember the value of the current store (for value forwarding) and the fact the store occurred (it could be dead too!). Reviewed by: Hal Differential Revision: http://reviews.llvm.org/D6301 llvm-svn: 222241
-rw-r--r--llvm/lib/Transforms/Scalar/EarlyCSE.cpp2
-rw-r--r--llvm/test/Transforms/EarlyCSE/basic.ll38
2 files changed, 39 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 6f166b8ee7f..cd2ecad4a18 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -546,7 +546,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
Changed = true;
++NumDSE;
LastStore = nullptr;
- continue;
+ // fallthrough - we can exploit information about this store
}
// Okay, we just invalidated anything we knew about loaded values. Try
diff --git a/llvm/test/Transforms/EarlyCSE/basic.ll b/llvm/test/Transforms/EarlyCSE/basic.ll
index 9f3e474aff9..155d36f60e2 100644
--- a/llvm/test/Transforms/EarlyCSE/basic.ll
+++ b/llvm/test/Transforms/EarlyCSE/basic.ll
@@ -154,4 +154,42 @@ define i32 @test8(i32 *%P) {
; CHECK: ret i32 0
}
+;; Trivial DSE can't be performed across a readonly call. The call
+;; can observe the earlier write.
+; CHECK-LABEL: @test9(
+define i32 @test9(i32 *%P) {
+ store i32 4, i32* %P
+ %V1 = call i32 @func(i32* %P) readonly
+ store i32 5, i32* %P
+ ret i32 %V1
+ ; CHECK: store i32 4, i32* %P
+ ; CHECK-NEXT: %V1 = call i32 @func(i32* %P)
+ ; CHECK-NEXT: store i32 5, i32* %P
+ ; CHECK-NEXT: ret i32 %V1
+}
+
+;; Trivial DSE can be performed across a readnone call.
+; CHECK-LABEL: @test10
+define i32 @test10(i32 *%P) {
+ store i32 4, i32* %P
+ %V1 = call i32 @func(i32* %P) readnone
+ store i32 5, i32* %P
+ ret i32 %V1
+ ; CHECK-NEXT: %V1 = call i32 @func(i32* %P)
+ ; CHECK-NEXT: store i32 5, i32* %P
+ ; CHECK-NEXT: ret i32 %V1
+}
+
+;; Trivial dead store elimination - should work for an entire series of dead stores too.
+; CHECK-LABEL: @test11(
+define void @test11(i32 *%P) {
+ store i32 42, i32* %P
+ store i32 43, i32* %P
+ store i32 44, i32* %P
+ store i32 45, i32* %P
+ ret void
+ ; CHECK-NEXT: store i32 45
+ ; CHECK-NEXT: ret void
+}
+
OpenPOWER on IntegriCloud