> + // If MemCpyInst length is 1/2/4/8 bytes then replace memcpy with > load/store
Neat! > + ConstantInt *MemOpLength = dyn_cast<ConstantInt>(CI.getOperand(3)); > + if (isa<MemCpyInst>(MI)) > + if (MemOpLength) { Can you replace these two if statements with if (isa<MemCpyInst>(MI) && MemOpLength) { ? Then the indentation of what follows won't be wrong either :-) > + 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)); } ? > + if (NewPtrTy) > + { LLVM style. > + Value *Src = InsertCastBefore(Instruction::BitCast, > CI.getOperand(2), NewPtrTy, CI); > + Value *Dest = InsertCastBefore(Instruction::BitCast, > CI.getOperand(1), NewPtrTy, CI); This is more than 80 columns. > + Value *L = new LoadInst(Src, "tmp", false, Align, &CI); > + Value *NS = new StoreInst(L, Dest, false, Align, &CI); > + CI.replaceAllUsesWith(NS); > + Changed = true; > + return EraseInstFromFunction(CI); > + } > + } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits