Slightly generalize transformation of memmove(a,a,n) so that it also applies
authorEli Friedman <eli.friedman@gmail.com>
Thu, 17 Dec 2009 21:07:31 +0000 (21:07 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 17 Dec 2009 21:07:31 +0000 (21:07 +0000)
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

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/memcpy.ll [new file with mode: 0644]

index b9c536fe1e5045058cd82baafb39d64b15dd9ed8..c7359c4de762f1da2aa925dd464c3d030e858dcb 100644 (file)
@@ -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 (file)
index 0000000..2e7b2c0
--- /dev/null
@@ -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