[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [cfe-commits] r60270 - /cfe/trunk/lib/CodeGen/CGExprAgg.cpp
From:       Eli Friedman <eli.friedman () gmail ! com>
Date:       2008-11-30 2:11:09
Message-ID: 200811300211.mAU2B9KB005670 () zion ! cs ! uiuc ! edu
[Download RAW message or body]

Author: efriedma
Date: Sat Nov 29 20:11:09 2008
New Revision: 60270

URL: http://llvm.org/viewvc/llvm-project?rev=60270&view=rev
Log:
Fix for PR2969: generate a memcpy from a constant for constant 
initializers.  llvm-gcc appears to be more aggressive, but incorrect, 
for constructs like "const int a[] = {1,2,3};"; that said, current 
optimizers will do the appropriate optimizations when safe.


Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=60270&r1=60269&r2=60270&view=diff


==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sat Nov 29 20:11:09 2008
@@ -368,14 +368,23 @@
     CGF.ErrorUnsupported(E, "initializer list with designators");
     return;
   }
-  
-  // FIXME: For constant expressions, call into const expr emitter so
-  // that we can emit a memcpy instead of storing the individual
-  // members.  This is purely for perf; both codepaths lead to
-  // equivalent (although not necessarily identical) code.  It's worth
-  // noting that LLVM keeps on getting smarter, though, so it might
-  // not be worth bothering.
-  
+
+  // If we can, prefer a copy from a global; this is a lot less
+  // code for long globals, and it's easier for the current optimizers
+  // to analyze.
+  // FIXME: Should we really be doing this? Should we try to avoid
+  // cases where we emit a global with a lot of zeros?  Should
+  // we try to avoid short globals? 
+  if (E->isConstantExpr(CGF.getContext(), 0)) {
+    llvm::Constant* C = CGF.CGM.EmitConstantExpr(E, &CGF);
+    llvm::GlobalVariable* GV =
+    new llvm::GlobalVariable(C->getType(), true,
+                             llvm::GlobalValue::InternalLinkage,
+                             C, "", &CGF.CGM.getModule(), 0);
+    CGF.EmitAggregateCopy(DestPtr, GV, E->getType());
+    return;
+  }
+
   // Handle initialization of an array.
   if (E->getType()->isArrayType()) {
     const llvm::PointerType *APType =


_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic