1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

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

llvm-svn: 320929
This commit is contained in:
Sean Fertile 2017-12-16 22:41:39 +00:00
parent 698be79b3e
commit 3ec9601025
2 changed files with 14 additions and 14 deletions

View File

@ -168,11 +168,12 @@ void llvm::createMemCpyLoopUnknownSize(Instruction *InsertBefore,
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(Instruction *InsertBefore,
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(),

View File

@ -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: