[llvm-commits] [llvm] r119686 - in /llvm/trunk: lib/Transforms/Scalar/ScalarReplAggregates.cpp test/Transforms/ScalarRepl/memcpy-from-global.ll

Chris Lattner sabre at nondot.org
Wed Nov 17 22:41:51 PST 2010


Author: lattner
Date: Thu Nov 18 00:41:51 2010
New Revision: 119686

URL: http://llvm.org/viewvc/llvm-project?rev=119686&view=rev
Log:
allow eliminating an alloca that is just copied from an constant global
if it is passed as a byval argument.  The byval argument will just be a
read, so it is safe to read from the original global instead.  This allows
us to promote away the %agg.tmp alloca in PR8582

Modified:
    llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
    llvm/trunk/test/Transforms/ScalarRepl/memcpy-from-global.ll

Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=119686&r1=119685&r2=119686&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Thu Nov 18 00:41:51 2010
@@ -1811,11 +1811,18 @@
       continue;
     }
     
-    // If this is a readonly/readnone call site, then we know it is just a load
-    // and we can ignore it.
-    if (CallSite CS = U)
+    if (CallSite CS = U) {
+      // If this is a readonly/readnone call site, then we know it is just a
+      // load and we can ignore it.
       if (CS.onlyReadsMemory())
         continue;
+      
+      // If this is being passed as a byval argument, the caller is making a
+      // copy, so it is only a read of the alloca.
+      unsigned ArgNo = CS.getArgumentNo(UI);
+      if (CS.paramHasAttr(ArgNo+1, Attribute::ByVal))
+        continue;
+    }
     
     // If this is isn't our memcpy/memmove, reject it as something we can't
     // handle.

Modified: llvm/trunk/test/Transforms/ScalarRepl/memcpy-from-global.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ScalarRepl/memcpy-from-global.ll?rev=119686&r1=119685&r2=119686&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ScalarRepl/memcpy-from-global.ll (original)
+++ llvm/trunk/test/Transforms/ScalarRepl/memcpy-from-global.ll Thu Nov 18 00:41:51 2010
@@ -81,3 +81,16 @@
 ; CHECK-NEXT: call void @bar(i8* %a)
   ret void
 }
+
+define void @test4() {
+  %A = alloca %T
+  %a = bitcast %T* %A to i8*
+  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* bitcast (%T* @G to i8*), i64 124, i32 4, i1 false)
+  call void @baz(i8* byval %a) 
+; CHECK: @test4
+; CHECK-NEXT: %a = bitcast %T* @G to i8*
+; CHECK-NEXT: call void @baz(i8* byval %a)
+  ret void
+}
+
+declare void @baz(i8* byval)





More information about the llvm-commits mailing list