From a935db8ea28ee73be647e8aa46ce59baf9279306 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 28 May 2008 05:30:41 +0000 Subject: [PATCH] Implement PR2370: memmove(x,x,size) -> noop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51636 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 4 ++++ test/Transforms/InstCombine/memmove.ll | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 20204154d0e..8c2dc3e92f4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9131,6 +9131,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { CI.setOperand(0, Intrinsic::getDeclaration(M, MemCpyID)); Changed = true; } + + // memmove(x,x,size) -> noop. + if (MMI->getSource() == MMI->getDest()) + return EraseInstFromFunction(CI); } // If we can determine a pointer alignment that is bigger than currently diff --git a/test/Transforms/InstCombine/memmove.ll b/test/Transforms/InstCombine/memmove.ll index 2cb346f1123..09ec67d2654 100644 --- a/test/Transforms/InstCombine/memmove.ll +++ b/test/Transforms/InstCombine/memmove.ll @@ -34,3 +34,9 @@ define i32 @test3() { ret i32 0 } +; PR2370 +define void @test4(i8* %a) { + tail call void @llvm.memmove.i32( i8* %a, i8* %a, i32 100, i32 1 ) + ret void +} + -- 2.34.1