================ @@ -945,48 +950,77 @@ static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init, /// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit /// the scalar stores that would be required. -static void emitStoresForInitAfterBZero(CodeGenModule &CGM, - llvm::Constant *Init, Address Loc, - bool isVolatile, CGBuilderTy &Builder, - bool IsAutoInit) { +static size_t emitStoresForInitAfterBZero(CodeGenModule &CGM, + llvm::Constant *Init, Address Loc, + bool isVolatile, CGBuilderTy &Builder, + bool IsAutoInit) { assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) && "called emitStoresForInitAfterBZero for zero or undef value."); + auto const &DL = CGM.getDataLayout(); + if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) || isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || isa<llvm::ConstantExpr>(Init)) { auto *I = Builder.CreateStore(Init, Loc, isVolatile); if (IsAutoInit) I->addAnnotationMetadata("auto-init"); - return; + return DL.getTypeAllocSize(Init->getType()); } if (llvm::ConstantDataSequential *CDS = dyn_cast<llvm::ConstantDataSequential>(Init)) { + bool CountNonNullBytes = true; + size_t LeadingNonNullElementsCount = 0; for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { llvm::Constant *Elt = CDS->getElementAsConstant(i); // If necessary, get a pointer to the element and emit it. - if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt)) + if (!isNullOrUndef(Elt)) { emitStoresForInitAfterBZero( CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile, Builder, IsAutoInit); + LeadingNonNullElementsCount += CountNonNullBytes; ---------------- efriedma-quic wrote:
This is too clever; just write `if (CountNonNullBytes) ++LeadingNonNullElementsCount;` https://github.com/llvm/llvm-project/pull/79502 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits