Another load-peephole optimization: do gcse when two loads are next to
authorChris Lattner <sabre@nondot.org>
Mon, 12 Sep 2005 22:21:03 +0000 (22:21 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 12 Sep 2005 22:21:03 +0000 (22:21 +0000)
each other.  This implements InstCombine/load.ll:test9

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23322 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 67144b93cfe39471d79adc4c503ed0a07f1f2d37..b508977cf366247e7662372c2b5a11ff3351fa75 100644 (file)
@@ -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<StoreInst>(BBI))
       if (SI->getOperand(1) == LI.getOperand(0))
         return ReplaceInstUsesWith(LI, SI->getOperand(0));
+    if (LoadInst *LIB = dyn_cast<LoadInst>(BBI))
+      if (LIB->getOperand(0) == LI.getOperand(0))
+        return ReplaceInstUsesWith(LI, LIB);
   }
 
   if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op))