[llvm-branch-commits] [llvm-branch] r73896 - in /llvm/branches/Apple/Bender/lib/Transforms/Scalar: InstructionCombining.cpp ScalarReplAggregates.cpp

Bill Wendling isanbard at gmail.com
Mon Jun 22 12:48:39 PDT 2009


Author: void
Date: Mon Jun 22 14:48:38 2009
New Revision: 73896

URL: http://llvm.org/viewvc/llvm-project?rev=73896&view=rev
Log:
Second half or r73891.

Modified:
    llvm/branches/Apple/Bender/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/branches/Apple/Bender/lib/Transforms/Scalar/ScalarReplAggregates.cpp

Modified: llvm/branches/Apple/Bender/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender/lib/Transforms/Scalar/InstructionCombining.cpp?rev=73896&r1=73895&r2=73896&view=diff

==============================================================================
--- llvm/branches/Apple/Bender/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/branches/Apple/Bender/lib/Transforms/Scalar/InstructionCombining.cpp Mon Jun 22 14:48:38 2009
@@ -9487,7 +9487,13 @@
     return 0;  // If not 1/2/4/8 bytes, exit.
   
   // Use an integer load+store unless we can find something better.
-  Type *NewPtrTy = PointerType::getUnqual(IntegerType::get(Size<<3));
+  unsigned SrcAddrSp =
+     cast<PointerType>(MI->getOperand(2)->getType())->getAddressSpace();
+  unsigned DstAddrSp =
+     cast<PointerType>(MI->getOperand(1)->getType())->getAddressSpace();
+
+  Type *NewSrcPtrTy = PointerType::get(IntegerType::get(Size<<3), SrcAddrSp);
+  Type *NewDstPtrTy = PointerType::get(IntegerType::get(Size<<3), DstAddrSp);
   
   // Memcpy forces the use of i8* for the source and destination.  That means
   // that if you're using memcpy to move one double around, you'll get a cast
@@ -9515,8 +9521,10 @@
           break;
       }
       
-      if (SrcETy->isSingleValueType())
-        NewPtrTy = PointerType::getUnqual(SrcETy);
+      if (SrcETy->isSingleValueType()) {
+        NewSrcPtrTy = PointerType::get(SrcETy, SrcAddrSp);
+        NewDstPtrTy = PointerType::get(SrcETy, DstAddrSp);
+      }
     }
   }
   
@@ -9526,8 +9534,8 @@
   SrcAlign = std::max(SrcAlign, CopyAlign);
   DstAlign = std::max(DstAlign, CopyAlign);
   
-  Value *Src = InsertBitCastBefore(MI->getOperand(2), NewPtrTy, *MI);
-  Value *Dest = InsertBitCastBefore(MI->getOperand(1), NewPtrTy, *MI);
+  Value *Src = InsertBitCastBefore(MI->getOperand(2), NewSrcPtrTy, *MI);
+  Value *Dest = InsertBitCastBefore(MI->getOperand(1), NewDstPtrTy, *MI);
   Instruction *L = new LoadInst(Src, "tmp", false, SrcAlign);
   InsertNewInstBefore(L, *MI);
   InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI);

Modified: llvm/branches/Apple/Bender/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=73896&r1=73895&r2=73896&view=diff

==============================================================================
--- llvm/branches/Apple/Bender/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/branches/Apple/Bender/lib/Transforms/Scalar/ScalarReplAggregates.cpp Mon Jun 22 14:48:38 2009
@@ -752,9 +752,18 @@
     
     // If the pointer is not the right type, insert a bitcast to the right
     // type.
-    if (OtherPtr->getType() != AI->getType())
-      OtherPtr = new BitCastInst(OtherPtr, AI->getType(), OtherPtr->getName(),
-                                 MI);
+
+    if (OtherPtr->getType() != AI->getType()) {
+      // Preserve address space of OtherPtrTy
+      const PointerType* OtherPtrTy = cast<PointerType>(OtherPtr->getType());
+      const PointerType* AIPtrTy = cast<PointerType>(AI->getType());
+      if (OtherPtrTy->getElementType() != AIPtrTy->getElementType()) {
+        Type *NewOtherPtrTy = PointerType::get(AIPtrTy->getElementType(),
+                                               OtherPtrTy->getAddressSpace());
+        OtherPtr = new BitCastInst(OtherPtr, NewOtherPtrTy, OtherPtr->getName(),
+                                   MI);
+      }
+    }
   }
   
   // Process each element of the aggregate.
@@ -861,10 +870,17 @@
       EltPtr = new BitCastInst(EltPtr, BytePtrTy, EltPtr->getNameStr(), MI);
     
     // Cast the other pointer (if we have one) to BytePtrTy. 
-    if (OtherElt && OtherElt->getType() != BytePtrTy)
-      OtherElt = new BitCastInst(OtherElt, BytePtrTy,OtherElt->getNameStr(),
-                                 MI);
-    
+    if (OtherElt && OtherElt->getType() != BytePtrTy) {
+      // Preserve address space of OtherElt
+      const PointerType* OtherPTy = cast<PointerType>(OtherElt->getType());
+      const PointerType* PTy = cast<PointerType>(BytePtrTy);
+      if (OtherPTy->getElementType() != PTy->getElementType()) {
+        Type *NewOtherPTy = PointerType::get(PTy->getElementType(),
+                                             OtherPTy->getAddressSpace());
+        OtherElt = new BitCastInst(OtherElt, NewOtherPTy,
+                                   OtherElt->getNameStr(), MI);
+      }
+    }
     unsigned EltSize = TD->getTypePaddedSize(EltTy);
     
     // Finally, insert the meminst for this element.
@@ -875,6 +891,14 @@
         ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
         ConstantInt::get(Type::Int32Ty, OtherEltAlign)  // Align
       };
+      if (MI->getIntrinsicID() == Intrinsic::memcpyany) {
+        // In case we fold a memcpyany of A to B with memcpyany of B to C,
+        // we will need to change the function to be a memcpyany of A to C.
+        const Type *Tys[] = { Ops[0]->getType(), Ops[1]->getType(),
+                         Ops[2]->getType(), Ops[3]->getType() };
+        Module *M = MI->getParent()->getParent()->getParent();
+        TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpyany, Tys, 4);
+      }
       CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
     } else {
       assert(isa<MemSetInst>(MI));





More information about the llvm-branch-commits mailing list