[llvm] r320929 - [Memcpy Loop Lowering] Only calculate residual size/bytes copied when needed.

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 16 14:41:39 PST 2017


Author: sfertile
Date: Sat Dec 16 14:41:39 2017
New Revision: 320929

URL: http://llvm.org/viewvc/llvm-project?rev=320929&view=rev
Log:
[Memcpy Loop Lowering] Only calculate residual size/bytes copied when needed.

If the loop operand type is int8 then there will be no residual loop for the
unknown size expansion. Dont create the residual-size and bytes-copied values
when they are not needed.

Modified:
    llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
    llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll

Modified: llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp?rev=320929&r1=320928&r2=320929&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp Sat Dec 16 14:41:39 2017
@@ -168,11 +168,12 @@ void llvm::createMemCpyLoopUnknownSize(I
   IntegerType *ILengthType = dyn_cast<IntegerType>(CopyLenType);
   assert(ILengthType &&
          "expected size argument to memcpy to be an integer type!");
+  Type *Int8Type = Type::getInt8Ty(Ctx);
+  bool LoopOpIsInt8 = LoopOpType == Int8Type;
   ConstantInt *CILoopOpSize = ConstantInt::get(ILengthType, LoopOpSize);
-  Value *RuntimeLoopCount = PLBuilder.CreateUDiv(CopyLen, CILoopOpSize);
-  Value *RuntimeResidual = PLBuilder.CreateURem(CopyLen, CILoopOpSize);
-  Value *RuntimeBytesCopied = PLBuilder.CreateSub(CopyLen, RuntimeResidual);
-
+  Value *RuntimeLoopCount = LoopOpIsInt8 ?
+                            CopyLen :
+                            PLBuilder.CreateUDiv(CopyLen, CILoopOpSize);
   BasicBlock *LoopBB =
       BasicBlock::Create(Ctx, "loop-memcpy-expansion", ParentFunc, PostLoopBB);
   IRBuilder<> LoopBuilder(LoopBB);
@@ -189,8 +190,11 @@ void llvm::createMemCpyLoopUnknownSize(I
       LoopBuilder.CreateAdd(LoopIndex, ConstantInt::get(CopyLenType, 1U));
   LoopIndex->addIncoming(NewIndex, LoopBB);
 
-  Type *Int8Type = Type::getInt8Ty(Ctx);
-  if (LoopOpType != Int8Type) {
+  if (!LoopOpIsInt8) {
+   // Add in the
+   Value *RuntimeResidual = PLBuilder.CreateURem(CopyLen, CILoopOpSize);
+   Value *RuntimeBytesCopied = PLBuilder.CreateSub(CopyLen, RuntimeResidual);
+
     // Loop body for the residual copy.
     BasicBlock *ResLoopBB = BasicBlock::Create(Ctx, "loop-memcpy-residual",
                                                PreLoopBB->getParent(),

Modified: llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll?rev=320929&r1=320928&r2=320929&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll (original)
+++ llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll Sat Dec 16 14:41:39 2017
@@ -36,9 +36,7 @@ entry:
 
 ; WIR-LABEL:   @memcpy_caller
 ; WIR:         entry:
-; WIR:         [[LoopCount:%[0-9]+]] = udiv i64 %n, 1
-; WIR:         [[ResidualSize:%[0-9]+]] = urem i64 %n, 1
-; WIR:         [[Cond:%[0-9]+]] = icmp ne i64 [[LoopCount]], 0
+; WIR:         [[Cond:%[0-9]+]] = icmp ne i64 %n, 0
 ; WIR:         br i1 [[Cond]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
 
 ; WIR:         loop-memcpy-expansion:
@@ -48,7 +46,7 @@ entry:
 ; WIR:         [[DstGep:%[0-9]+]] = getelementptr inbounds i8, i8* %dst, i64 %loop-index
 ; WIR:         store i8 [[Load]], i8* [[DstGep]]
 ; WIR:         [[IndexInc]] = add i64 %loop-index, 1
-; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], [[LoopCount]]
+; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], %n
 ; WIR:         br i1 [[Cond2]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
 
 ; WIR-LABEL:   post-loop-memcpy-expansion:
@@ -74,9 +72,7 @@ entry:
 
 ; WIR-LABEL:   @memcpy_volatile_caller
 ; WIR:         entry:
-; WIR:         [[LoopCount:%[0-9]+]] = udiv i64 %n, 1
-; WIR:         [[ResidualSize:%[0-9]+]] = urem i64 %n, 1
-; WIR:         [[Cond:%[0-9]+]] = icmp ne i64 [[LoopCount]], 0
+; WIR:         [[Cond:%[0-9]+]] = icmp ne i64 %n, 0
 ; WIR:         br i1 [[Cond]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
 
 ; WIR:         loop-memcpy-expansion:
@@ -86,7 +82,7 @@ entry:
 ; WIR:         [[DstGep:%[0-9]+]] = getelementptr inbounds i8, i8* %dst, i64 %loop-index
 ; WIR:         store volatile i8 [[Load]], i8* [[DstGep]]
 ; WIR:         [[IndexInc]] = add i64 %loop-index, 1
-; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], [[LoopCount]]
+; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], %n
 ; WIR:         br i1 [[Cond2]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
 
 ; WIR-LABEL:   post-loop-memcpy-expansion:




More information about the llvm-commits mailing list