vitalybuka updated this revision to Diff 209638. vitalybuka added a comment.
Remove single store Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D64675/new/ 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 @@ -1153,72 +1153,8 @@ if (!ConstantSize) return; - bool canDoSingleStore = Ty->isIntOrIntVectorTy() || - Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy(); - if (canDoSingleStore) { - Builder.CreateStore(constant, Loc, isVolatile); - return; - } - 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 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; - } - } - } - // Copy from a global. Builder.CreateMemCpy(Loc, createUnnamedGlobalForMemcpyFrom(
Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -1153,72 +1153,8 @@ if (!ConstantSize) return; - bool canDoSingleStore = Ty->isIntOrIntVectorTy() || - Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy(); - if (canDoSingleStore) { - Builder.CreateStore(constant, Loc, isVolatile); - return; - } - 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 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; - } - } - } - // Copy from a global. Builder.CreateMemCpy(Loc, createUnnamedGlobalForMemcpyFrom(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits