aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-10-20 10:03:01 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-10-20 10:03:01 +0000
commita32038b006c67fb4c9b572133a24050b4c8d40cf (patch)
treedcf0a35509f00df56f7e431c4fa1dbb771ca4162 /llvm/lib/Analysis/Loads.cpp
parentd7c9cf8f8d291485883a368dc3e097509d623683 (diff)
downloadllvm-a32038b006c67fb4c9b572133a24050b4c8d40cf.zip
llvm-a32038b006c67fb4c9b572133a24050b4c8d40cf.tar.gz
llvm-a32038b006c67fb4c9b572133a24050b4c8d40cf.tar.bz2
Fix a miscompile introduced in r220178.
The original code had an implicit assumption that if the test for allocas or globals was reached, the two pointers were not equal. With my changes to make the pointer analysis more powerful here, I also had to guard against circumstances where the results weren't useful. That in turn violated the assumption and gave rise to a circumstance in which we could have a store with both the queried pointer and stored pointer rooted at *the same* alloca. Clearly, we cannot ignore such a store. There are other things we might do in this code to better handle the case of both pointers ending up at the same alloca or global, but it seems best to at least make the test explicit in what it intends to check. I've added tests for both the alloca and global case here. llvm-svn: 220190
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 65a30f2..bb0d60e 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -220,11 +220,12 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
return SI->getOperand(0);
}
- // If Ptr is an alloca and this is a store to a different alloca, ignore
- // the store. This is a trivial form of alias analysis that is important
- // for reg2mem'd code.
+ // If both StrippedPtr and StorePtr reach all the way to an alloca or
+ // global and they are different, ignore the store. This is a trivial form
+ // of alias analysis that is important for reg2mem'd code.
if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
- (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)))
+ (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
+ StrippedPtr != StorePtr)
continue;
// If we have alias analysis and it says the store won't modify the loaded