- // Load from the memory we are promoting...
- LoadInst *LI = new LoadInst(PromotedValues[i].second,
- PromotedValues[i].second->getName()+".promoted",
- LoopPredInst);
- // Store into the temporary alloca...
+ Value *Ptr = PromotedValues[i].second;
+
+ // If we are promoting a pointer value, update alias information for the
+ // inserted load.
+ Value *LoadValue = 0;
+ if (isa<PointerType>(cast<PointerType>(Ptr->getType())->getElementType())) {
+ // Locate a load or store through the pointer, and assign the same value
+ // to LI as we are loading or storing. Since we know that the value is
+ // stored in this loop, this will always succeed.
+ for (Value::use_iterator UI = Ptr->use_begin(), E = Ptr->use_end();
+ UI != E; ++UI)
+ if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
+ LoadValue = LI;
+ break;
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(*UI)) {
+ if (SI->getOperand(1) == Ptr) {
+ LoadValue = SI->getOperand(0);
+ break;
+ }
+ }
+ assert(LoadValue && "No store through the pointer found!");
+ PointerValueNumbers.push_back(LoadValue); // Remember this for later.
+ }
+
+ // Load from the memory we are promoting.
+ LoadInst *LI = new LoadInst(Ptr, Ptr->getName()+".promoted", LoopPredInst);
+
+ if (LoadValue) CurAST->copyValue(LoadValue, LI);
+
+ // Store into the temporary alloca.