aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/LevelRaise.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-11-01 03:12:34 +0000
committerChris Lattner <sabre@nondot.org>2001-11-01 03:12:34 +0000
commit8d38e54c2f1b58ba617892801183836f0a7d2ca8 (patch)
tree1555ed425a8a4e3d4468177ca6da39f7a75cfc7c /lib/Transforms/LevelRaise.cpp
parentd32a96121b21257007baf990258788851d5a3265 (diff)
* Convert getelementptr/store pairs into a single store
* Convert getelementptr/load pairs into a single load git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1075 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/LevelRaise.cpp')
-rw-r--r--lib/Transforms/LevelRaise.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp
index 8074fdce04..db4e94e72e 100644
--- a/lib/Transforms/LevelRaise.cpp
+++ b/lib/Transforms/LevelRaise.cpp
@@ -438,7 +438,7 @@ static bool PeepholeMallocInst(BasicBlock *BB, BasicBlock::iterator &BI) {
static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
Instruction *I = *BI;
- if (I->use_size() == 0) return false;
+ if (I->use_size() == 0 && I->getType() != Type::VoidTy) return false;
if (CastInst *CI = dyn_cast<CastInst>(I)) {
Value *Src = CI->getOperand(0);
@@ -484,6 +484,31 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
} else if (MallocInst *MI = dyn_cast<MallocInst>(I)) {
if (PeepholeMallocInst(BB, BI)) return true;
+
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
+ Value *Val = SI->getOperand(0);
+ Value *Pointer = SI->getPtrOperand();
+
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Pointer)) {
+ PRINT_PEEPHOLE2("gep-store:in", GEP, SI);
+ ReplaceInstWithInst(BB->getInstList(), BI,
+ SI = new StoreInst(Val, GEP->getPtrOperand(),
+ GEP->getIndexVec()));
+ PRINT_PEEPHOLE1("gep-store:out", SI);
+ return true;
+ }
+
+ } else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
+ Value *Pointer = LI->getPtrOperand();
+
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Pointer)) {
+ PRINT_PEEPHOLE2("gep-load:in", GEP, LI);
+ ReplaceInstWithInst(BB->getInstList(), BI,
+ LI = new LoadInst(GEP->getPtrOperand(),
+ GEP->getIndexVec()));
+ PRINT_PEEPHOLE1("gep-load:out", LI);
+ return true;
+ }
} else if (I->getOpcode() == Instruction::Add &&
isa<CastInst>(I->getOperand(1))) {