diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 67144b93cfe..b508977cf36 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4926,13 +4926,16 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // None of the following transforms are legal for volatile loads. if (LI.isVolatile()) return 0; - // If the instruction immediately before this is a store to the same address, - // do a simple form of store->load forwarding. if (&LI.getParent()->front() != &LI) { BasicBlock::iterator BBI = &LI; --BBI; + // If the instruction immediately before this is a store to the same + // address, do a simple form of store->load forwarding. if (StoreInst *SI = dyn_cast(BBI)) if (SI->getOperand(1) == LI.getOperand(0)) return ReplaceInstUsesWith(LI, SI->getOperand(0)); + if (LoadInst *LIB = dyn_cast(BBI)) + if (LIB->getOperand(0) == LI.getOperand(0)) + return ReplaceInstUsesWith(LI, LIB); } if (GetElementPtrInst *GEPI = dyn_cast(Op))