https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95523

--- Comment #4 from z.zhanghaijian at huawei dot com <z.zhanghaijian at huawei 
dot com> ---
> Could you try setting DECL_USER_ALIGN on the FIELD_DECL?
> that should (hopefully) force the field to keep its
> natural alignment.

Do you mean to change the alignment to natural alignment when processing
arm_sve.h, and then change it back after handle_arm_sve_h?

I tracked the calculation process of TYPE_ALIGN (tuple_type), which is
determined by maximum_field_alignment in layout_decl, not from DECL_USER_ALIGN.

We can set maximum_field_alignment in sve_switcher to achieve the purpose of
natural alignment.

like:
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc
b/gcc/config/aarch64/aarch64-sve-builtins.cc
index bdb04e8170d..c49fcebcd43 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins.cc
@@ -878,6 +878,9 @@ sve_switcher::sve_switcher ()
   aarch64_isa_flags = (AARCH64_FL_FP | AARCH64_FL_SIMD | AARCH64_FL_F16
                       | AARCH64_FL_SVE);

+  m_old_maximum_field_alignment = maximum_field_alignment;
+  maximum_field_alignment = 0;
+
   m_old_general_regs_only = TARGET_GENERAL_REGS_ONLY;
   global_options.x_target_flags &= ~MASK_GENERAL_REGS_ONLY;

@@ -895,6 +898,7 @@ sve_switcher::~sve_switcher ()
   if (m_old_general_regs_only)
     global_options.x_target_flags |= MASK_GENERAL_REGS_ONLY;
   aarch64_isa_flags = m_old_isa_flags;
+  maximum_field_alignment = m_old_maximum_field_alignment;
 }

 function_builder::function_builder ()
diff --git a/gcc/config/aarch64/aarch64-sve-builtins.h
b/gcc/config/aarch64/aarch64-sve-builtins.h
index 526d9f55e7b..3ffe2516df9 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins.h
+++ b/gcc/config/aarch64/aarch64-sve-builtins.h
@@ -658,6 +658,7 @@ public:

 private:
   unsigned long m_old_isa_flags;
+  unsigned int m_old_maximum_field_alignment;
   bool m_old_general_regs_only;
   bool m_old_have_regs_of_mode[MAX_MACHINE_MODE];
 };

Reply via email to