On Thu, Oct 11, 2007 at 05:08:55PM -0500, Dan Gohman wrote: > > + unsigned Size = MemOpLength->getZExtValue(); > > + unsigned Align = > > cast<ConstantInt>(CI.getOperand(4))->getZExtValue(); > > + const PointerType *PTy = > > cast<PointerType>(CI.getOperand(1)->getType()); > > + const Type *MTy = PTy->getElementType(); > > + PointerType *NewPtrTy = NULL; > > + if (MTy == Type::Int8Ty) { > > + if (Size == 8) > > + NewPtrTy = PointerType::get(Type::Int64Ty); > > + else if (Size == 4) > > + NewPtrTy = PointerType::get(Type::Int32Ty); > > + else if (Size == 2) > > + NewPtrTy = PointerType::get(Type::Int16Ty); > > + else if (Size == 1) > > + NewPtrTy = PointerType::get(Type::Int8Ty); > > + } else if (MTy == Type::Int16Ty) { > > + if (Size == 4) > > + NewPtrTy = PointerType::get(Type::Int64Ty); > > + else if (Size == 2) > > + NewPtrTy = PointerType::get(Type::Int32Ty); > > + else if (Size == 1) > > + NewPtrTy = PointerType::get(Type::Int16Ty); > > + } else if (MTy == Type::Int32Ty) { > > + if (Size == 2) > > + NewPtrTy = PointerType::get(Type::Int64Ty); > > + else if (Size == 1) > > + NewPtrTy = PointerType::get(Type::Int32Ty); > > + } else if (MTy == Type::Int64Ty) { > > + if (Size == 1) > > + NewPtrTy = PointerType::get(Type::Int64Ty); > > + } > > It'd be great it this worked for non-scalar-integer types as well. > > Maybe you could do something like (warning, untested): > > if (Size == 1 && MTy->isFirstClassType()) > NewPtrTy = PointerType::get(MTy) > else { > CopySize = Size * TD->getABITypeSizeInBits(MTy); > if (CopySize == 8 || CopySize == 4 || CopySize == 2 || CopySize == 1) > NewPtrTy = PointerType::get(IntegerType::get(CopySize)); > } > > ?
Oops, looking at this a little more, isn't the Size operand always in straight bytes, and MTy always i8, just because of how llvm.memcpy is declared? Also, this code can be used for memmove as well as memcpy; since the load grabs the entire source before anything is stored, overlap cases would work correctly. Dan -- Dan Gohman, Cray Inc. _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits