From f6651d4d9438e185ae92c55978c11700dce45cee Mon Sep 17 00:00:00 2001 From: Daniel Neilson Date: Fri, 11 May 2018 20:04:50 +0000 Subject: [InstCombine] Handle atomic memset in the same way as regular memset Summary: This change adds handling of the atomic memset intrinsic to the code path that simplifies the regular memset. In practice this means that we will now also expand a small constant-length atomic memset into a single unordered atomic store. Reviewers: apilipenko, skatkov, mkazantsev, anna, reames Reviewed By: reames Subscribers: reames, llvm-commits Differential Revision: https://reviews.llvm.org/D46660 llvm-svn: 332132 --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 8 +++++--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index e11d49251ad..82a26f348cd 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -199,7 +199,7 @@ Instruction *InstCombiner::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) { return MI; } -Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { +Instruction *InstCombiner::SimplifyAnyMemSet(AnyMemSetInst *MI) { unsigned Alignment = getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT); if (MI->getDestAlignment() < Alignment) { MI->setDestAlignment(Alignment); @@ -232,6 +232,8 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { StoreInst *S = Builder.CreateStore(ConstantInt::get(ITy, Fill), Dest, MI->isVolatile()); S->setAlignment(Alignment); + if (isa(MI)) + S->setOrdering(AtomicOrdering::Unordered); // Set the size of the copy to 0, it will be deleted on the next iteration. MI->setLength(Constant::getNullValue(LenC->getType())); @@ -1758,8 +1760,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (auto *MTI = dyn_cast(MI)) { if (Instruction *I = SimplifyAnyMemTransfer(MTI)) return I; - } else if (MemSetInst *MSI = dyn_cast(MI)) { - if (Instruction *I = SimplifyMemSet(MSI)) + } else if (auto *MSI = dyn_cast(MI)) { + if (Instruction *I = SimplifyAnyMemSet(MSI)) return I; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index b597957eeae..a3a485c2111 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -825,7 +825,7 @@ private: bool SimplifyStoreAtEndOfBlock(StoreInst &SI); Instruction *SimplifyAnyMemTransfer(AnyMemTransferInst *MI); - Instruction *SimplifyMemSet(MemSetInst *MI); + Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI); Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned); -- cgit v1.2.3