From 5da80974c0926813ed45fb51cf42392e74755d89 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 3 Apr 2004 00:45:16 +0000 Subject: Implement test/Regression/Transforms/GCSE/undefined_load.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12641 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LoadValueNumbering.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/Analysis/LoadValueNumbering.cpp') diff --git a/lib/Analysis/LoadValueNumbering.cpp b/lib/Analysis/LoadValueNumbering.cpp index b67aaddde3..97a57562bd 100644 --- a/lib/Analysis/LoadValueNumbering.cpp +++ b/lib/Analysis/LoadValueNumbering.cpp @@ -22,6 +22,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoadValueNumbering.h" +#include "llvm/Constant.h" #include "llvm/Function.h" #include "llvm/iMemory.h" #include "llvm/iOther.h" @@ -283,10 +284,14 @@ void LoadVN::getEqualNumberNodes(Value *V, // std::map > CandidateLoads; std::map > CandidateStores; + std::set Allocations; while (!PointerSources.empty()) { Value *Source = PointerSources.back(); PointerSources.pop_back(); // Get a source pointer... + + if (AllocationInst *AI = dyn_cast(Source)) + Allocations.insert(AI); for (Value::use_iterator UI = Source->use_begin(), UE = Source->use_end(); UI != UE; ++UI) @@ -329,6 +334,15 @@ void LoadVN::getEqualNumberNodes(Value *V, if (isa(I) && Instrs.count(I)) { RetVals.push_back(I); Instrs.erase(I); + } else if (AllocationInst *AI = dyn_cast(I)) { + // If we run into an allocation of the value being loaded, then the + // contenxt are not initialized. We can return any value, so we will + // return a zero. + if (Allocations.count(AI)) { + LoadInvalidatedInBBBefore = true; + RetVals.push_back(Constant::getNullValue(LI->getType())); + break; + } } if (AA.getModRefInfo(I, LoadPtr, LoadSize) & AliasAnalysis::Mod) { -- cgit v1.2.3