diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-12-17 21:07:31 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-12-17 21:07:31 +0000 |
commit | 0c826d98b39e941fad96ffaf32c23d3fae447a19 (patch) | |
tree | c50a958058ab16b54ef987519cb3358a3bd01da0 | |
parent | 88cd3582b6cb70c0283e4c5d6d783114323a1ce1 (diff) | |
download | external_llvm-0c826d98b39e941fad96ffaf32c23d3fae447a19.zip external_llvm-0c826d98b39e941fad96ffaf32c23d3fae447a19.tar.gz external_llvm-0c826d98b39e941fad96ffaf32c23d3fae447a19.tar.bz2 |
Slightly generalize transformation of memmove(a,a,n) so that it also applies
to memcpy. (Such a memcpy is technically illegal, but in practice is safe
and is generated by struct self-assignment in C code.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91621 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 4 | ||||
-rw-r--r-- | test/Transforms/InstCombine/memcpy.ll | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index b9c536f..c7359c4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9896,9 +9896,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { Intrinsic::getDeclaration(M, MemCpyID, Tys, 1)); Changed = true; } + } + if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI)) { // memmove(x,x,size) -> noop. - if (MMI->getSource() == MMI->getDest()) + if (MTI->getSource() == MTI->getDest()) return EraseInstFromFunction(CI); } diff --git a/test/Transforms/InstCombine/memcpy.ll b/test/Transforms/InstCombine/memcpy.ll new file mode 100644 index 0000000..2e7b2c0 --- /dev/null +++ b/test/Transforms/InstCombine/memcpy.ll @@ -0,0 +1,10 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +declare void @llvm.memcpy.i32(i8*, i8*, i32, i32) + +define void @test4(i8* %a) { + tail call void @llvm.memcpy.i32( i8* %a, i8* %a, i32 100, i32 1 ) + ret void +} +; CHECK: define void @test4 +; CHECK-NEXT: ret void |