]> granicus.if.org Git - llvm/commitdiff
[Memcpy Loop Lowering] Insert loop BB inbetween the split BB.
authorSean Fertile <sfertile@ca.ibm.com>
Fri, 15 Dec 2017 19:29:12 +0000 (19:29 +0000)
committerSean Fertile <sfertile@ca.ibm.com>
Fri, 15 Dec 2017 19:29:12 +0000 (19:29 +0000)
The original memcpy expansion inserted the loop basic block inbetween
the 2 new basic blocks created by splitting the original block the memcpy
call was in. This commit makes the new memcpy expansion do the same to keep the
layout of the IR matching between the old and new implementations.

Differential Review: https://reviews.llvm.org/D41197

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320848 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/LowerMemIntrinsics.cpp
test/CodeGen/NVPTX/lower-aggr-copies.ll

index 900450b4006125aabe0a4ffb37519c1fb0b1cd9a..33b8f62ea891dd4e66f15844b17f8840a816bc2c 100644 (file)
@@ -174,7 +174,7 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
   Value *RuntimeBytesCopied = PLBuilder.CreateSub(CopyLen, RuntimeResidual);
 
   BasicBlock *LoopBB =
-      BasicBlock::Create(Ctx, "loop-memcpy-expansion", ParentFunc, nullptr);
+      BasicBlock::Create(Ctx, "loop-memcpy-expansion", ParentFunc, PostLoopBB);
   IRBuilder<> LoopBuilder(LoopBB);
 
   PHINode *LoopIndex = LoopBuilder.CreatePHI(CopyLenType, 2, "loop-index");
@@ -193,7 +193,8 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
   if (LoopOpType != Int8Type) {
     // Loop body for the residual copy.
     BasicBlock *ResLoopBB = BasicBlock::Create(Ctx, "loop-memcpy-residual",
-                                               PreLoopBB->getParent(), nullptr);
+                                               PreLoopBB->getParent(),
+                                               PostLoopBB);
     // Residual loop header.
     BasicBlock *ResHeaderBB = BasicBlock::Create(
         Ctx, "loop-memcpy-residual-header", PreLoopBB->getParent(), nullptr);
index 4298442157e23396b9a68de81fe731f5a700bcab..3465491061310ec604d7a0a3ed877aa06153a591 100644 (file)
@@ -50,6 +50,9 @@ entry:
 ; WIR:         [[IndexInc]] = add i64 %loop-index, 1
 ; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], [[LoopCount]]
 ; WIR:         br i1 [[Cond2]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
+
+; WIR-LABEL:   post-loop-memcpy-expansion:
+; WIR:         ret i8* %dst
 }
 
 define i8* @memcpy_volatile_caller(i8* %dst, i8* %src, i64 %n) #0 {
@@ -85,6 +88,9 @@ entry:
 ; WIR:         [[IndexInc]] = add i64 %loop-index, 1
 ; WIR:         [[Cond2:%[0-9]+]] = icmp ult i64 [[IndexInc]], [[LoopCount]]
 ; WIR:         br i1 [[Cond2]], label %loop-memcpy-expansion, label %post-loop-memcpy-expansion
+
+; WIR-LABEL:   post-loop-memcpy-expansion:
+; WIR:         ret i8* %dst
 }
 
 define i8* @memcpy_casting_caller(i32* %dst, i32* %src, i64 %n) #0 {