vitalybuka created this revision.
vitalybuka added reviewers: glider, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Not rely a review, but removing this code I see slight improvements in
binary size on CTMark. Looks like with "ptr" patches MemCpyOptPass is
capable to handle this.

WDYT?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64675

Files:
  clang/lib/CodeGen/CGDecl.cpp

Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1162,62 +1162,62 @@
 
   auto *SizeVal = llvm::ConstantInt::get(CGM.IntPtrTy, ConstantSize);
 
-  // If the initializer is all or mostly the same, codegen with bzero / memset
-  // then do a few stores afterward.
-  if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
-    Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
-                         isVolatile);
-
-    bool valueAlreadyCorrect =
-        constant->isNullValue() || isa<llvm::UndefValue>(constant);
-    if (!valueAlreadyCorrect) {
-      Loc = Builder.CreateBitCast(Loc, Ty->getPointerTo(Loc.getAddressSpace()));
-      emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
-    }
-    return;
-  }
-
-  // If the initializer is a repeated byte pattern, use memset.
-  llvm::Value *Pattern =
-      shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
-  if (Pattern) {
-    uint64_t Value = 0x00;
-    if (!isa<llvm::UndefValue>(Pattern)) {
-      const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->getValue();
-      assert(AP.getBitWidth() <= 8);
-      Value = AP.getLimitedValue();
-    }
-    Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal,
-                         isVolatile);
-    return;
-  }
+  // // If the initializer is all or mostly the same, codegen with bzero / memset
+  // // then do a few stores afterward.
+  // if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
+  //   Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0), SizeVal,
+  //                        isVolatile);
+
+  //   bool valueAlreadyCorrect =
+  //       constant->isNullValue() || isa<llvm::UndefValue>(constant);
+  //   if (!valueAlreadyCorrect) {
+  //     Loc = Builder.CreateBitCast(Loc, Ty->getPointerTo(Loc.getAddressSpace()));
+  //     emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder);
+  //   }
+  //   return;
+  // }
+
+  // // If the initializer is a repeated byte pattern, use memset.
+  // llvm::Value *Pattern =
+  //     shouldUseMemSetToInitialize(constant, ConstantSize, CGM.getDataLayout());
+  // if (Pattern) {
+  //   uint64_t Value = 0x00;
+  //   if (!isa<llvm::UndefValue>(Pattern)) {
+  //     const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->getValue();
+  //     assert(AP.getBitWidth() <= 8);
+  //     Value = AP.getLimitedValue();
+  //   }
+  //   Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal,
+  //                        isVolatile);
+  //   return;
+  // }
 
   // If the initializer is small, use a handful of stores.
-  if (shouldSplitConstantStore(CGM, ConstantSize)) {
-    if (auto *STy = dyn_cast<llvm::StructType>(Ty)) {
-      // FIXME: handle the case when STy != Loc.getElementType().
-      if (STy == Loc.getElementType()) {
-        for (unsigned i = 0; i != constant->getNumOperands(); i++) {
-          Address EltPtr = Builder.CreateStructGEP(Loc, i);
-          emitStoresForConstant(
-              CGM, D, EltPtr, isVolatile, Builder,
-              cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
-        }
-        return;
-      }
-    } else if (auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
-      // FIXME: handle the case when ATy != Loc.getElementType().
-      if (ATy == Loc.getElementType()) {
-        for (unsigned i = 0; i != ATy->getNumElements(); i++) {
-          Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
-          emitStoresForConstant(
-              CGM, D, EltPtr, isVolatile, Builder,
-              cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
-        }
-        return;
-      }
-    }
-  }
+  // if (shouldSplitConstantStore(CGM, ConstantSize)) {
+  //   if (auto *STy = dyn_cast<llvm::StructType>(Ty)) {
+  //     // FIXME: handle the case when STy != Loc.getElementType().
+  //     if (STy == Loc.getElementType()) {
+  //       for (unsigned i = 0; i != constant->getNumOperands(); i++) {
+  //         Address EltPtr = Builder.CreateStructGEP(Loc, i);
+  //         emitStoresForConstant(
+  //             CGM, D, EltPtr, isVolatile, Builder,
+  //             cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
+  //       }
+  //       return;
+  //     }
+  //   } else if (auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
+  //     // FIXME: handle the case when ATy != Loc.getElementType().
+  //     if (ATy == Loc.getElementType()) {
+  //       for (unsigned i = 0; i != ATy->getNumElements(); i++) {
+  //         Address EltPtr = Builder.CreateConstArrayGEP(Loc, i);
+  //         emitStoresForConstant(
+  //             CGM, D, EltPtr, isVolatile, Builder,
+  //             cast<llvm::Constant>(Builder.CreateExtractValue(constant, i)));
+  //       }
+  //       return;
+  //     }
+  //   }
+  // }
 
   // Copy from a global.
   Builder.CreateMemCpy(Loc,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to