[llvm-commits] [llvm] r42864 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2007-10-10-EliminateMemCpy.ll

Dan Gohman djg at cray.com
Thu Oct 11 15:26:30 PDT 2007


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.



More information about the llvm-commits mailing list