[llvm-commits] [llvm] r91621 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/memcpy.ll

Eli Friedman eli.friedman at gmail.com
Thu Dec 17 13:07:32 PST 2009


Author: efriedma
Date: Thu Dec 17 15:07:31 2009
New Revision: 91621

URL: http://llvm.org/viewvc/llvm-project?rev=91621&view=rev
Log:
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.)


Added:
    llvm/trunk/test/Transforms/InstCombine/memcpy.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=91621&r1=91620&r2=91621&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu Dec 17 15:07:31 2009
@@ -9896,9 +9896,11 @@
                         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);
     }
 

Added: llvm/trunk/test/Transforms/InstCombine/memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/memcpy.ll?rev=91621&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/memcpy.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/memcpy.ll Thu Dec 17 15:07:31 2009
@@ -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





More information about the llvm-commits mailing list