[clang] [clang] Avoid memcopy for small structure with padding under -ftrivial-auto-var-init (PR #71677)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 9 14:07:12 PST 2023
================
@@ -1244,29 +1244,28 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D,
// 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)),
- IsAutoInit);
- }
- return;
+ const llvm::StructLayout *Layout =
+ CGM.getDataLayout().getStructLayout(STy);
+ for (unsigned i = 0; i != constant->getNumOperands(); i++) {
+ CharUnits CurOff = CharUnits::fromQuantity(Layout->getElementOffset(i));
+ Address EltPtr = Builder.CreateConstInBoundsByteGEP(
----------------
serge-sans-paille wrote:
We cannot do that because we want to access padding, something `CreateStructGEP` cannot do.
https://github.com/llvm/llvm-project/pull/71677
More information about the cfe-commits
mailing list