Implement PR2370: memmove(x,x,size) -> noop.
authorChris Lattner <sabre@nondot.org>
Wed, 28 May 2008 05:30:41 +0000 (05:30 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 28 May 2008 05:30:41 +0000 (05:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51636 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/memmove.ll

index 20204154d0e8006fad405f6b006833fd94570a77..8c2dc3e92f40db92cd3e7d46514ae0a119b572c7 100644 (file)
@@ -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
index 2cb346f11236d76a02b8035b4c8e41414451a1ab..09ec67d2654eadb947b6ee6739f47aa6443dab34 100644 (file)
@@ -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
+}
+