summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJin-Gu Kang <jaykang10@imrc.kist.re.kr>2011-03-12 12:18:44 +0000
committerJin-Gu Kang <jaykang10@imrc.kist.re.kr>2011-03-12 12:18:44 +0000
commitc5c03f90240e1d2bf9f1579ae14b5dc8f0547c33 (patch)
tree1d9f38cdbd8c86fdd171823dfd7d07ef2dbb6ea6
parentb1adbd1f67125668ef1a87be62553e0f95cbc4d9 (diff)
downloadllvm-c5c03f90240e1d2bf9f1579ae14b5dc8f0547c33.tar.gz
llvm-c5c03f90240e1d2bf9f1579ae14b5dc8f0547c33.tar.bz2
llvm-c5c03f90240e1d2bf9f1579ae14b5dc8f0547c33.tar.xz
This patch removes some of useless instructions generated by bitfield access.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127539 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 35c1d91d50..f233ca6af1 100644
--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -429,9 +429,19 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
// the pointer we're loading and is producing the pointer we're storing,
// then *this* store is dead (X = load P; store X -> P).
if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
- if (LI == Val && equivalentAddressValues(LI->getOperand(0), Ptr) &&
- !SI.isVolatile())
- return EraseInstFromFunction(SI);
+ if (equivalentAddressValues(LI->getOperand(0), Ptr) &&
+ !SI.isVolatile()) {
+ if (LI == Val)
+ return EraseInstFromFunction(SI);
+ if (Ptr->hasNUses(2)) {
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
+ if (isa<AllocaInst>(GEP->getOperand(0))) {
+ if (GEP->getOperand(0)->hasOneUse())
+ return EraseInstFromFunction(SI);
+ }
+ }
+ }
+ }
// Otherwise, this is a load from some other location. Stores before it
// may not be dead.