[cfe-commits] r130453 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/value-init.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Apr 28 15:57:55 PDT 2011


Author: akirtzidis
Date: Thu Apr 28 17:57:55 2011
New Revision: 130453

URL: http://llvm.org/viewvc/llvm-project?rev=130453&view=rev
Log:
Cut down unnecessary zero'ing when value-initializing arrays of C++ objects.

-C++ objects with user-declared constructor don't need zero'ing.
-We can zero-initialize arrays of C++ objects in "bulk" now, in which case don't zero-initialize each object again.

Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/value-init.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=130453&r1=130452&r2=130453&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Apr 28 17:57:55 2011
@@ -811,7 +811,16 @@
   // If the slot is already known to be zeroed, nothing to do.  Don't mess with
   // volatile stores.
   if (Slot.isZeroed() || Slot.isVolatile() || Slot.getAddr() == 0) return;
-  
+
+  // C++ objects with a user-declared constructor don't need zero'ing.
+  if (CGF.getContext().getLangOptions().CPlusPlus)
+    if (const RecordType *RT = CGF.getContext()
+                       .getBaseElementType(E->getType())->getAs<RecordType>()) {
+      const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+      if (RD->hasUserDeclaredConstructor())
+        return;
+    }
+
   // If the type is 16-bytes or smaller, prefer individual stores over memset.
   std::pair<CharUnits, CharUnits> TypeInfo =
     CGF.getContext().getTypeInfoInChars(E->getType());

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=130453&r1=130452&r2=130453&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu Apr 28 17:57:55 2011
@@ -370,8 +370,9 @@
   
   // If we require zero initialization before (or instead of) calling the
   // constructor, as can be the case with a non-user-provided default
-  // constructor, emit the zero initialization now.
-  if (E->requiresZeroInitialization())
+  // constructor, emit the zero initialization now, unless destination is
+  // already zeroed.
+  if (E->requiresZeroInitialization() && !Dest.isZeroed())
     EmitNullInitialization(Dest.getAddr(), E->getType());
   
   // If this is a call to a trivial default constructor, do nothing.

Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=130453&r1=130452&r2=130453&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Thu Apr 28 17:57:55 2011
@@ -101,23 +101,37 @@
 
 // CHECK: define void @_ZN6PR98011fEv
 void f() {
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ei
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ev
   Test partial[3] = { 1 };
 
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98014TestC1Ev
   Test empty[3] = {};
 
+  // CHECK: call void @llvm.memset.p0i8.i64
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test2C1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test2C1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test2C1Ev
   Test2 empty2[3] = {};
 
+  // CHECK: call void @llvm.memset.p0i8.i64
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test3C1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test3C1Ev
+  // CHECK-NOT: call void @llvm.memset.p0i8.i64
   // CHECK: call void @_ZN6PR98015Test3C1Ev
   Test3 empty3[3] = {};
 }





More information about the cfe-commits mailing list