[PATCH] D34707: Add zero-length check to memcpy/memset load store loop expansion
Teresa Johnson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 06:07:58 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306541: Add zero-length check to memcpy/memset load store loop expansion (authored by tejohnson).
Repository:
rL LLVM
https://reviews.llvm.org/D34707
Files:
llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll
Index: llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
+++ llvm/trunk/lib/Transforms/Utils/LowerMemIntrinsics.cpp
@@ -27,8 +27,11 @@
BasicBlock *LoopBB = BasicBlock::Create(F->getContext(), "loadstoreloop",
F, NewBB);
- OrigBB->getTerminator()->setSuccessor(0, LoopBB);
IRBuilder<> Builder(OrigBB->getTerminator());
+ Builder.CreateCondBr(
+ Builder.CreateICmpEQ(ConstantInt::get(TypeOfCopyLen, 0), CopyLen), NewBB,
+ LoopBB);
+ OrigBB->getTerminator()->eraseFromParent();
// SrcAddr and DstAddr are expected to be pointer types,
// so no check is made here.
@@ -167,32 +170,36 @@
static void createMemSetLoop(Instruction *InsertBefore,
Value *DstAddr, Value *CopyLen, Value *SetValue,
unsigned Align, bool IsVolatile) {
+ Type *TypeOfCopyLen = CopyLen->getType();
BasicBlock *OrigBB = InsertBefore->getParent();
Function *F = OrigBB->getParent();
BasicBlock *NewBB =
OrigBB->splitBasicBlock(InsertBefore, "split");
BasicBlock *LoopBB
= BasicBlock::Create(F->getContext(), "loadstoreloop", F, NewBB);
- OrigBB->getTerminator()->setSuccessor(0, LoopBB);
IRBuilder<> Builder(OrigBB->getTerminator());
+ Builder.CreateCondBr(
+ Builder.CreateICmpEQ(ConstantInt::get(TypeOfCopyLen, 0), CopyLen), NewBB,
+ LoopBB);
+ OrigBB->getTerminator()->eraseFromParent();
// Cast pointer to the type of value getting stored
unsigned dstAS = cast<PointerType>(DstAddr->getType())->getAddressSpace();
DstAddr = Builder.CreateBitCast(DstAddr,
PointerType::get(SetValue->getType(), dstAS));
IRBuilder<> LoopBuilder(LoopBB);
- PHINode *LoopIndex = LoopBuilder.CreatePHI(CopyLen->getType(), 0);
- LoopIndex->addIncoming(ConstantInt::get(CopyLen->getType(), 0), OrigBB);
+ PHINode *LoopIndex = LoopBuilder.CreatePHI(TypeOfCopyLen, 0);
+ LoopIndex->addIncoming(ConstantInt::get(TypeOfCopyLen, 0), OrigBB);
LoopBuilder.CreateStore(
SetValue,
LoopBuilder.CreateInBoundsGEP(SetValue->getType(), DstAddr, LoopIndex),
IsVolatile);
Value *NewIndex =
- LoopBuilder.CreateAdd(LoopIndex, ConstantInt::get(CopyLen->getType(), 1));
+ LoopBuilder.CreateAdd(LoopIndex, ConstantInt::get(TypeOfCopyLen, 1));
LoopIndex->addIncoming(NewIndex, LoopBB);
LoopBuilder.CreateCondBr(LoopBuilder.CreateICmpULT(NewIndex, CopyLen), LoopBB,
Index: llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll
===================================================================
--- llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll
+++ llvm/trunk/test/CodeGen/NVPTX/lower-aggr-copies.ll
@@ -17,6 +17,8 @@
ret i8* %dst
; IR-LABEL: @memcpy_caller
+; IR: [[CMPREG:%[0-9]+]] = icmp eq i64 0, %n
+; IR: br i1 [[CMPREG]], label %split, label %loadstoreloop
; IR: loadstoreloop:
; IR: [[LOADPTR:%[0-9]+]] = getelementptr inbounds i8, i8* %src, i64
; IR-NEXT: [[VAL:%[0-9]+]] = load i8, i8* [[LOADPTR]]
@@ -73,6 +75,8 @@
; IR-LABEL: @memset_caller
; IR: [[VAL:%[0-9]+]] = trunc i32 %c to i8
+; IR: [[CMPREG:%[0-9]+]] = icmp eq i64 0, %n
+; IR: br i1 [[CMPREG]], label %split, label %loadstoreloop
; IR: loadstoreloop:
; IR: [[STOREPTR:%[0-9]+]] = getelementptr inbounds i8, i8* %dst, i64
; IR-NEXT: store i8 [[VAL]], i8* [[STOREPTR]]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34707.104400.patch
Type: text/x-patch
Size: 3577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170628/84a5cf1a/attachment-0001.bin>
More information about the llvm-commits
mailing list