aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-11-14 20:50:30 +0000
committerChris Lattner <sabre@nondot.org>2004-11-14 20:50:30 +0000
commitbd38edfe236944ebecbbf84ef9ea75d5412737b5 (patch)
treefebd533c7460d76ee14bfb76fadcf49953aabc6a
parent826c47ea5bdb6c252e6d4db83b0bc0047b3acb2c (diff)
If a global is just loaded and restored, realize that it is not changing
value. This allows us to turn more globals into constants and eliminate them. This patch implements GlobalOpt/load-store-global.llx. Note that this patch speeds up 255.vortex from: Output/255.vortex.out-cbe.time:program 7.640000 Output/255.vortex.out-llc.time:program 9.810000 to: Output/255.vortex.out-cbe.time:program 7.250000 Output/255.vortex.out-llc.time:program 9.490000 Which isn't bad at all! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17746 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 054c5ee430..b8edc32f16 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -155,14 +155,20 @@ static bool AnalyzeGlobal(Value *V, GlobalStatus &GS,
// stores.
if (GS.StoredType != GlobalStatus::isStored)
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(SI->getOperand(1))){
- if (SI->getOperand(0) == GV->getInitializer()) {
+ Value *StoredVal = SI->getOperand(0);
+ if (StoredVal == GV->getInitializer()) {
+ if (GS.StoredType < GlobalStatus::isInitializerStored)
+ GS.StoredType = GlobalStatus::isInitializerStored;
+ } else if (isa<LoadInst>(StoredVal) &&
+ cast<LoadInst>(StoredVal)->getOperand(0) == GV) {
+ // G = G
if (GS.StoredType < GlobalStatus::isInitializerStored)
GS.StoredType = GlobalStatus::isInitializerStored;
} else if (GS.StoredType < GlobalStatus::isStoredOnce) {
GS.StoredType = GlobalStatus::isStoredOnce;
- GS.StoredOnceValue = SI->getOperand(0);
+ GS.StoredOnceValue = StoredVal;
} else if (GS.StoredType == GlobalStatus::isStoredOnce &&
- GS.StoredOnceValue == SI->getOperand(0)) {
+ GS.StoredOnceValue == StoredVal) {
// noop.
} else {
GS.StoredType = GlobalStatus::isStored;