Skip to content

Commit

Permalink
[LowerMemIntrinsics] Explicitly use i8 type in memmove lowering
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Feb 16, 2022
1 parent 8f7f3c1 commit c9032f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
Expand Up @@ -297,7 +297,13 @@ static void createMemMoveLoop(Instruction *InsertBefore, Value *SrcAddr,
Function *F = OrigBB->getParent();
const DataLayout &DL = F->getParent()->getDataLayout();

Type *EltTy = SrcAddr->getType()->getPointerElementType();
// TODO: Use different element type if possible?
IRBuilder<> CastBuilder(InsertBefore);
Type *EltTy = CastBuilder.getInt8Ty();
Type *PtrTy =
CastBuilder.getInt8PtrTy(SrcAddr->getType()->getPointerAddressSpace());
SrcAddr = CastBuilder.CreateBitCast(SrcAddr, PtrTy);
DstAddr = CastBuilder.CreateBitCast(DstAddr, PtrTy);

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

0 comments on commit c9032f1

Please sign in to comment.