[llvm] c9032f1 - [LowerMemIntrinsics] Explicitly use i8 type in memmove lowering

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 07:32:07 PST 2022


Author: Nikita Popov
Date: 2022-02-16T16:31:55+01:00
New Revision: c9032f1a69ed2a5368a5ef783ff4a5c641e86565

URL: https://github.com/llvm/llvm-project/commit/c9032f1a69ed2a5368a5ef783ff4a5c641e86565
DIFF: https://github.com/llvm/llvm-project/commit/c9032f1a69ed2a5368a5ef783ff4a5c641e86565.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
index 3d75dd57456de..c43cb7d126cf3 100644
--- a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
+++ b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
@@ -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 
diff erent 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


        


More information about the llvm-commits mailing list