//===- LoadValueNumbering.cpp - Load Value #'ing Implementation -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file implements a value numbering pass that value #'s load instructions.
// To do this, it finds lexically identical load instructions, and uses alias
void LoadVN::getEqualNumberNodes(Value *V,
std::vector<Value*> &RetVals) const {
// If the alias analysis has any must alias information to share with us, we
- // can definately use it.
+ // can definitely use it.
if (isa<PointerType>(V->getType()))
getAnalysis<AliasAnalysis>().getMustAliases(V, RetVals);
if (LoadInst *LI = dyn_cast<LoadInst>(V)) {
+ // Volatile loads cannot be replaced with the value of other loads.
+ if (LI->isVolatile())
+ return getAnalysis<ValueNumbering>().getEqualNumberNodes(V, RetVals);
+
// If we have a load instruction, find all of the load and store
// instructions that use the same source operand. We implement this
// recursively, because there could be a load of a load of a load that are
Function *F = LI->getParent()->getParent();
// Now that we know the set of equivalent source pointers for the load
- // instruction, look to see if there are any load or store candiates that
+ // instruction, look to see if there are any load or store candidates that
// are identical.
//
std::vector<LoadInst*> CandidateLoads;
UI != UE; ++UI)
if (LoadInst *Cand = dyn_cast<LoadInst>(*UI)) {// Is a load of source?
if (Cand->getParent()->getParent() == F && // In the same function?
- Cand != LI) // Not LI itself?
+ Cand != LI && !Cand->isVolatile()) // Not LI itself?
CandidateLoads.push_back(Cand); // Got one...
} else if (StoreInst *Cand = dyn_cast<StoreInst>(*UI)) {
- if (Cand->getParent()->getParent() == F &&
+ if (Cand->getParent()->getParent() == F && !Cand->isVolatile() &&
Cand->getOperand(1) == Source) // It's a store THROUGH the ptr...
CandidateStores.push_back(Cand);
}
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
DominatorSet &DomSetInfo = getAnalysis<DominatorSet>();
- // Loop over all of the candindate loads. If they are not invalidated by
+ // Loop over all of the candidate loads. If they are not invalidated by
// stores or calls between execution of them and LI, then add them to
// RetVals.
for (unsigned i = 0, e = CandidateLoads.size(); i != e; ++i)