Skip to content

Commit c9032f1

Browse files
committed
[LowerMemIntrinsics] Explicitly use i8 type in memmove lowering
By convention, memcpy/memmove intrinsics are always used with i8 pointers (though this is not enforced), so in practice this code was always using an i8 type. Make that explicit. Of course, i8 is not a very profitable choice, and this code could be more performant by picking an appropriate larger type. But that would require additional test coverage and correctness review, and certainly shouldn't be a decision based on the pointer element type.
1 parent 8f7f3c1 commit c9032f1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ static void createMemMoveLoop(Instruction *InsertBefore, Value *SrcAddr,
297297
Function *F = OrigBB->getParent();
298298
const DataLayout &DL = F->getParent()->getDataLayout();
299299

300-
Type *EltTy = SrcAddr->getType()->getPointerElementType();
300+
// TODO: Use different element type if possible?
301+
IRBuilder<> CastBuilder(InsertBefore);
302+
Type *EltTy = CastBuilder.getInt8Ty();
303+
Type *PtrTy =
304+
CastBuilder.getInt8PtrTy(SrcAddr->getType()->getPointerAddressSpace());
305+
SrcAddr = CastBuilder.CreateBitCast(SrcAddr, PtrTy);
306+
DstAddr = CastBuilder.CreateBitCast(DstAddr, PtrTy);
301307

302308
// Create the a comparison of src and dst, based on which we jump to either
303309
// the forward-copy part of the function (if src >= dst) or the backwards-copy

0 commit comments

Comments
 (0)