[flang-commits] [flang] [llvm] [Flang][Fir] Set default alignment of array globals to 64 bytes (PR #194969)

Jason Van Beusekom via flang-commits flang-commits at lists.llvm.org
Wed Apr 29 14:59:08 PDT 2026


https://github.com/Jason-Van-Beusekom created https://github.com/llvm/llvm-project/pull/194969

This commit implements the proposal from the RFC:
https://discourse.llvm.org/t/rfc-alignment-of-global-arrays/90397/13

This PR sets the alignment of all global arrays to 64 bytes (except for BIND(C) and common blocks). This Mirrors the execution of other fortran compilers (CCE, gfortran, nvfortran and ifx).

>From 7880cf680c0cd654f98df204b57748ecaeee760c Mon Sep 17 00:00:00 2001
From: Jason-Van-Beusekom <jason.van-beusekom at hpe.com>
Date: Wed, 29 Apr 2026 14:45:42 -0500
Subject: [PATCH] [Flang][Fir] Set default alignment of array globals to 64
 bytes This commit implements the proposal from the RFC:
 https://discourse.llvm.org/t/rfc-alignment-of-global-arrays/90397/13

---
 flang/lib/Lower/ConvertVariable.cpp           |  9 +++
 flang/lib/Optimizer/Builder/FIRBuilder.cpp    | 12 +++
 flang/test/Lower/CUDA/cuda-data-attribute.cuf |  6 +-
 flang/test/Lower/CUDA/cuda-program-global.cuf |  2 +-
 .../Lower/HLFIR/tdesc-character-comp-init.f90 |  2 +-
 flang/test/Lower/Intrinsics/ieee_class.f90    |  4 +-
 .../Lower/OpenACC/acc-declare-globals.f90     |  6 +-
 .../OpenACC/acc-declare-use-associated.f90    |  2 +-
 .../target-private-implicit-scalar-map-2.f90  |  4 +-
 flang/test/Lower/OpenMP/cray-pointers01.f90   |  2 +-
 .../test/Lower/OpenMP/declare-target-data.f90 |  4 +-
 .../threadprivate-char-array-chararray.f90    |  4 +-
 .../wsloop-reduction-multiple-clauses.f90     |  2 +-
 flang/test/Lower/array-character.f90          |  2 +-
 flang/test/Lower/array-constructor-1.f90      |  2 +-
 flang/test/Lower/array-constructor-2.f90      |  4 +-
 flang/test/Lower/array.f90                    | 16 ++--
 .../test/Lower/constant-literal-mangling.f90  | 10 +--
 .../test/Lower/constant-logical-transfer.f90  |  2 +-
 flang/test/Lower/convert.f90                  |  2 +-
 .../Lower/default-initialization-globals.f90  | 12 +--
 flang/test/Lower/dense-array-any-rank.f90     |  6 +-
 flang/test/Lower/dense-attributed-array.f90   |  2 +-
 flang/test/Lower/derived-type-descriptor.f90  |  4 +-
 flang/test/Lower/equivalence-1.f90            |  2 +-
 flang/test/Lower/equivalence-static-init.f90  |  4 +-
 flang/test/Lower/global-alignment.f90         | 74 +++++++++++++++++++
 flang/test/Lower/io-derived-type.f90          |  4 +-
 flang/test/Lower/module_definition.f90        |  6 +-
 flang/test/Lower/module_use.f90               |  2 +-
 flang/test/Lower/namelist-common-block.f90    |  2 +-
 m.mod                                         | 16 ++++
 32 files changed, 171 insertions(+), 60 deletions(-)
 create mode 100644 flang/test/Lower/global-alignment.f90
 create mode 100644 m.mod

diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 59abdb92e33ba..65aa8b95549ba 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -223,6 +223,9 @@ static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
   fir::GlobalOp global = builder.createGlobal(
       loc, converter.genType(var), globalName, linkage, mlir::Attribute{},
       isConstant(ultimate), var.isTarget(), dataAttr);
+  // BIND(C) globals follow C ABI alignment; remove default alignment.
+  if (sym.attrs().test(Fortran::semantics::Attr::BIND_C))
+    global.removeAlignmentAttr();
   attachAccDeclareAttribute(builder, global, sym);
   return global;
 }
@@ -566,6 +569,9 @@ fir::GlobalOp Fortran::lower::defineGlobal(
             oeDetails->init().value(), dataAttr);
         if (global) {
           global.setVisibility(mlir::SymbolTable::Visibility::Public);
+          // BIND(C) globals follow C ABI alignment; remove default alignment.
+          if (sym.attrs().test(Fortran::semantics::Attr::BIND_C))
+            global.removeAlignmentAttr();
           return global;
         }
       }
@@ -680,6 +686,9 @@ fir::GlobalOp Fortran::lower::defineGlobal(
   // Set public visibility to prevent global definition to be optimized out
   // even if they have no initializer and are unused in this compilation unit.
   global.setVisibility(mlir::SymbolTable::Visibility::Public);
+  // BIND(C) globals follow C ABI alignment; remove default alignment.
+  if (sym.attrs().test(Fortran::semantics::Attr::BIND_C))
+    global.removeAlignmentAttr();
   return global;
 }
 
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index 6a9c84ffbd909..5e64ce6a767c7 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -463,6 +463,12 @@ fir::GlobalOp fir::FirOpBuilder::createGlobal(
   }
   auto glob = fir::GlobalOp::create(*this, loc, name, isConst, isTarget, type,
                                     value, linkage, attrs);
+  // Set default alignment for array globals.
+  if (mlir::isa<fir::SequenceType>(type)) {
+    unsigned currentAlign = glob.getAlignment().value_or(0);
+    if (currentAlign < 64)
+      glob.setAlignment(64);
+  }
   restoreInsertionPoint(insertPt);
   if (symbolTable)
     symbolTable->insert(glob);
@@ -480,6 +486,12 @@ fir::GlobalOp fir::FirOpBuilder::createGlobal(
   setInsertionPoint(module.getBody(), module.getBody()->end());
   auto glob = fir::GlobalOp::create(*this, loc, name, isConst, isTarget, type,
                                     mlir::Attribute{}, linkage);
+  // Set default alignment for array globals.
+  if (mlir::isa<fir::SequenceType>(type)) {
+    unsigned currentAlign = glob.getAlignment().value_or(0);
+    if (currentAlign < 64)
+      glob.setAlignment(64);
+  }
   auto &region = glob.getRegion();
   region.push_back(new mlir::Block);
   auto &block = glob.getRegion().back();
diff --git a/flang/test/Lower/CUDA/cuda-data-attribute.cuf b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
index 2b06f29af1ef0..a461ec2835996 100644
--- a/flang/test/Lower/CUDA/cuda-data-attribute.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
@@ -117,7 +117,7 @@ end subroutine
 ! CHECK: fir.global @_QMcuda_varEmod_b_ra {data_attr = #cuf.cuda<device>} : f32
 ! CHECK: fir.global @_QMcuda_varEmod_c_rm {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<f32>>
 
-! CHECK: fir.global @_QMcuda_varEmod_d_i_init(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xi32>
-! CHECK: fir.global @_QMcuda_varEmod_d_rinit(dense<[{{.*}}]> : tensor<10xf32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xf32>
+! CHECK: fir.global @_QMcuda_varEmod_d_i_init(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {alignment = 64 : i64, data_attr = #cuf.cuda<device>} : !fir.array<10xi32>
+! CHECK: fir.global @_QMcuda_varEmod_d_rinit(dense<[{{.*}}]> : tensor<10xf32>) {alignment = 64 : i64, data_attr = #cuf.cuda<device>} : !fir.array<10xf32>
 ! CHECK: fir.global @_QMcuda_varEmod_d_rp {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<f32>>
-! CHECK: fir.global @_QMcuda_varEmod_d_t {data_attr = #cuf.cuda<device>} : !fir.array<2x!fir.type<_QMcuda_varTt1{a:i32}>>
+! CHECK: fir.global @_QMcuda_varEmod_d_t {alignment = 64 : i64, data_attr = #cuf.cuda<device>} : !fir.array<2x!fir.type<_QMcuda_varTt1{a:i32}>>
diff --git a/flang/test/Lower/CUDA/cuda-program-global.cuf b/flang/test/Lower/CUDA/cuda-program-global.cuf
index 64141f940a541..cdeb1a1446ecf 100644
--- a/flang/test/Lower/CUDA/cuda-program-global.cuf
+++ b/flang/test/Lower/CUDA/cuda-program-global.cuf
@@ -23,5 +23,5 @@ end
 ! CHECK: cuf.alloc !fir.array<10xi32> {bindc_name = "u", data_attr = #cuf.cuda<unified>, uniq_name = "_QFEu"} -> !fir.ref<!fir.array<10xi32>>
 
 ! CHECK-NOT: fir.global internal @_QFEa {data_attr = #cuf.cuda<device>} : !fir.array<10xi32> {{{$}}
-! CHECK: fir.global internal @_QFEb : !fir.array<10xi32> {{{$}}
+! CHECK: fir.global internal @_QFEb {alignment = 64 : i64} : !fir.array<10xi32> {{{$}}
 ! CHECK-NOT: fir.global internal @_QFEu {data_attr = #cuf.cuda<unified>}
diff --git a/flang/test/Lower/HLFIR/tdesc-character-comp-init.f90 b/flang/test/Lower/HLFIR/tdesc-character-comp-init.f90
index 1ae312e8cc1c4..909523d19f702 100644
--- a/flang/test/Lower/HLFIR/tdesc-character-comp-init.f90
+++ b/flang/test/Lower/HLFIR/tdesc-character-comp-init.f90
@@ -9,5 +9,5 @@ subroutine test()
   end type
   type(t) :: x
 end subroutine
-! CHECK-LABEL: fir.global {{.*}} @_QFtestE.c.t constant
+! CHECK-LABEL: fir.global {{.*}} @_QFtestE.c.t {alignment = 64 : i64} constant
 ! CHECK: fir.address_of(@_QFtestE.di.t.character_comp) : !fir.ref<!fir.char<1,5>>
diff --git a/flang/test/Lower/Intrinsics/ieee_class.f90 b/flang/test/Lower/Intrinsics/ieee_class.f90
index ab177e40e0d0d..1f59abb22122d 100644
--- a/flang/test/Lower/Intrinsics/ieee_class.f90
+++ b/flang/test/Lower/Intrinsics/ieee_class.f90
@@ -127,5 +127,5 @@ program p
   enddo
 end
 
-! CHECK: fir.global linkonce @_FortranAIeeeClassTable(dense<[7, 8, 8, 8, 11, 11, 11, 11, 9, 9, 9, 9, 10, 2, 1, 2, 6, 5, 5, 5, 11, 11, 11, 11, 4, 4, 4, 4, 3, 2, 1, 2]> : tensor<32xi8>) constant : !fir.array<32xi8>
-! CHECK: fir.global linkonce @_FortranAIeeeValueTable_8(dense<[0, 9219994337134247936, 9221120237041090560, -4503599627370496, -4616189618054758400, -9221120237041090560, -9223372036854775808, 0, 2251799813685248, 4607182418800017408, 9218868437227405312, 0]> : tensor<12xi64>) constant : !fir.array<12xi64>
+! CHECK: fir.global linkonce @_FortranAIeeeClassTable(dense<[7, 8, 8, 8, 11, 11, 11, 11, 9, 9, 9, 9, 10, 2, 1, 2, 6, 5, 5, 5, 11, 11, 11, 11, 4, 4, 4, 4, 3, 2, 1, 2]> : tensor<32xi8>) {alignment = 64 : i64} constant : !fir.array<32xi8>
+! CHECK: fir.global linkonce @_FortranAIeeeValueTable_8(dense<[0, 9219994337134247936, 9221120237041090560, -4503599627370496, -4616189618054758400, -9221120237041090560, -9223372036854775808, 0, 2251799813685248, 4607182418800017408, 9218868437227405312, 0]> : tensor<12xi64>) {alignment = 64 : i64} constant : !fir.array<12xi64>
diff --git a/flang/test/Lower/OpenACC/acc-declare-globals.f90 b/flang/test/Lower/OpenACC/acc-declare-globals.f90
index 4556c5f4ddb1c..94d9b00d73467 100644
--- a/flang/test/Lower/OpenACC/acc-declare-globals.f90
+++ b/flang/test/Lower/OpenACC/acc-declare-globals.f90
@@ -42,7 +42,7 @@ module acc_declare_test
  !$acc declare create(data1)
 end module
 
-! CHECK-LABEL: fir.global @_QMacc_declare_testEdata1 {acc.declare = #acc.declare<dataClause = acc_create>} : !fir.array<100000xf32>
+! CHECK-LABEL: fir.global @_QMacc_declare_testEdata1 {acc.declare = #acc.declare<dataClause = acc_create>, alignment = 64 : i64} : !fir.array<100000xf32>
 
 ! CHECK-LABEL: acc.global_ctor @_QMacc_declare_testEdata1_acc_ctor {
 ! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_testEdata1) {acc.declare = #acc.declare<dataClause = acc_create>} : !fir.ref<!fir.array<100000xf32>>
@@ -86,7 +86,7 @@ module acc_declare_device_resident_test
  !$acc declare device_resident(data1)
 end module
 
-! CHECK-LABEL: fir.global @_QMacc_declare_device_resident_testEdata1 {acc.declare = #acc.declare<dataClause =  acc_declare_device_resident>} : !fir.array<5000xi32>
+! CHECK-LABEL: fir.global @_QMacc_declare_device_resident_testEdata1 {acc.declare = #acc.declare<dataClause =  acc_declare_device_resident>, alignment = 64 : i64} : !fir.array<5000xi32>
 
 ! CHECK-LABEL: acc.global_ctor @_QMacc_declare_device_resident_testEdata1_acc_ctor {
 ! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_device_resident_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_declare_device_resident>} : !fir.ref<!fir.array<5000xi32>>
@@ -109,7 +109,7 @@ module acc_declare_device_link_test
  !$acc declare link(data1)
 end module
 
-! CHECK-LABEL: fir.global @_QMacc_declare_device_link_testEdata1 {acc.declare = #acc.declare<dataClause =  acc_declare_link>} : !fir.array<5000xi32> {
+! CHECK-LABEL: fir.global @_QMacc_declare_device_link_testEdata1 {acc.declare = #acc.declare<dataClause =  acc_declare_link>, alignment = 64 : i64} : !fir.array<5000xi32> {
 
 ! CHECK-LABEL: acc.global_ctor @_QMacc_declare_device_link_testEdata1_acc_ctor {
 ! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_device_link_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_declare_link>} : !fir.ref<!fir.array<5000xi32>>
diff --git a/flang/test/Lower/OpenACC/acc-declare-use-associated.f90 b/flang/test/Lower/OpenACC/acc-declare-use-associated.f90
index cd700ae2932b2..4d2275d67efb5 100644
--- a/flang/test/Lower/OpenACC/acc-declare-use-associated.f90
+++ b/flang/test/Lower/OpenACC/acc-declare-use-associated.f90
@@ -25,5 +25,5 @@ subroutine use_mod()
   end do
 end subroutine
 
-! CHECK: fir.global @_QMacc_declare_modEaa {acc.declare = #acc.declare<dataClause = acc_create>} : !fir.array<100xf32>
+! CHECK: fir.global @_QMacc_declare_modEaa {acc.declare = #acc.declare<dataClause = acc_create>, alignment = 64 : i64} : !fir.array<100xf32>
 ! CHECK: fir.global @_QMacc_declare_modEcoef {acc.declare = #acc.declare<dataClause = acc_copyin>} : f32
diff --git a/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90 b/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90
index 676686f6a2def..3f1ed7842f560 100644
--- a/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90
+++ b/flang/test/Lower/OpenMP/DelayedPrivatization/target-private-implicit-scalar-map-2.f90
@@ -14,8 +14,8 @@ module test_data
 end module
 
 ! CHECK-MOD: module {{.*}}
-! CHECK-MOD: fir.global @_QMtest_dataEj : !fir.array<200xi8> {
-! CHECK-MOD: fir.global @_QMtest_dataEi : !fir.array<10x10xf32> {
+! CHECK-MOD: fir.global @_QMtest_dataEj {alignment = 64 : i64} : !fir.array<200xi8> {
+! CHECK-MOD: fir.global @_QMtest_dataEi {alignment = 64 : i64} : !fir.array<10x10xf32> {
 ! CHECK-MOD: fir.global @_QMtest_dataEz : i32 {
 
 !--- imp_scalar_map_target.f90
diff --git a/flang/test/Lower/OpenMP/cray-pointers01.f90 b/flang/test/Lower/OpenMP/cray-pointers01.f90
index 01fa4af3282b1..5f46ae5608c0a 100644
--- a/flang/test/Lower/OpenMP/cray-pointers01.f90
+++ b/flang/test/Lower/OpenMP/cray-pointers01.f90
@@ -56,7 +56,7 @@ program test_cray_pointers_01
     ! CHECK:   omp.terminator
     ! CHECK: }
     ! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEivar : i64
-    ! CHECK-LABEL: fir.global  @_QMtest_host_assoc_cray_pointerEvar : !fir.array<?xf64>
+    ! CHECK-LABEL: fir.global  @_QMtest_host_assoc_cray_pointerEvar {alignment = 64 : i64} : !fir.array<?xf64>
 
 
   !$omp end parallel
diff --git a/flang/test/Lower/OpenMP/declare-target-data.f90 b/flang/test/Lower/OpenMP/declare-target-data.f90
index 474944d7c0bb0..2e3790303984c 100644
--- a/flang/test/Lower/OpenMP/declare-target-data.f90
+++ b/flang/test/Lower/OpenMP/declare-target-data.f90
@@ -8,11 +8,11 @@ module test_0
 INTEGER :: data_int = 10
 !$omp declare target link(data_int)
 
-!CHECK-DAG: fir.global @_QMtest_0Earray_1d({{.*}}) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link), automap = false>} : !fir.array<3xi32>
+!CHECK-DAG: fir.global @_QMtest_0Earray_1d({{.*}}) {alignment = 64 : i64, omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link), automap = false>} : !fir.array<3xi32>
 INTEGER :: array_1d(3) = (/1,2,3/)
 !$omp declare target link(array_1d)
 
-!CHECK-DAG: fir.global @_QMtest_0Earray_2d({{.*}}) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link), automap = false>} : !fir.array<2x2xi32>
+!CHECK-DAG: fir.global @_QMtest_0Earray_2d({{.*}}) {alignment = 64 : i64, omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link), automap = false>} : !fir.array<2x2xi32>
 INTEGER :: array_2d(2,2) = reshape((/1,2,3,4/), (/2,2/))
 !$omp declare target link(array_2d)
 
diff --git a/flang/test/Lower/OpenMP/threadprivate-char-array-chararray.f90 b/flang/test/Lower/OpenMP/threadprivate-char-array-chararray.f90
index 34b21150bb886..4be86bfe7f0a7 100644
--- a/flang/test/Lower/OpenMP/threadprivate-char-array-chararray.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-char-array-chararray.f90
@@ -11,8 +11,8 @@ module test
   !$omp threadprivate(x, y, z)
 
 !CHECK-DAG: fir.global @_QMtestEx : !fir.char<1> {
-!CHECK-DAG: fir.global @_QMtestEy : !fir.array<5xi32> {
-!CHECK-DAG: fir.global @_QMtestEz : !fir.array<5x!fir.char<1,5>> {
+!CHECK-DAG: fir.global @_QMtestEy {alignment = 64 : i64} : !fir.array<5xi32> {
+!CHECK-DAG: fir.global @_QMtestEz {alignment = 64 : i64} : !fir.array<5x!fir.char<1,5>> {
 
 contains
   subroutine sub()
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-multiple-clauses.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-multiple-clauses.f90
index 60a162d8f8002..bd3926647c759 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-multiple-clauses.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-multiple-clauses.f90
@@ -155,7 +155,7 @@ program main
 ! CHECK:             omp.terminator
 ! CHECK:           }
 
-! CHECK-LABEL:   fir.global internal @_QFEarray : !fir.array<3x3xf64> {
+! CHECK-LABEL:   fir.global internal @_QFEarray {alignment = 64 : i64} : !fir.array<3x3xf64> {
 ! CHECK:           %[[VAL_0:.*]] = fir.zero_bits !fir.array<3x3xf64>
 ! CHECK:           fir.has_value %[[VAL_0]] : !fir.array<3x3xf64>
 ! CHECK:         }
diff --git a/flang/test/Lower/array-character.f90 b/flang/test/Lower/array-character.f90
index 85f5af0492c3b..7c4c84a1ba7a1 100644
--- a/flang/test/Lower/array-character.f90
+++ b/flang/test/Lower/array-character.f90
@@ -109,7 +109,7 @@ subroutine charlit
 ! CHECK:           return
 ! CHECK:         }
 
-! CHECK: fir.global internal @_QQro.4x3xc1.0 constant : !fir.array<4x!fir.char<1,3>>
+! CHECK: fir.global internal @_QQro.4x3xc1.0 {alignment = 64 : i64} constant : !fir.array<4x!fir.char<1,3>>
 ! CHECK: AA
 ! CHECK: MM
 ! CHECK: ZZ
diff --git a/flang/test/Lower/array-constructor-1.f90 b/flang/test/Lower/array-constructor-1.f90
index 55e7bb0f0416b..19461006fde19 100644
--- a/flang/test/Lower/array-constructor-1.f90
+++ b/flang/test/Lower/array-constructor-1.f90
@@ -41,6 +41,6 @@ program prog
   call zero
 end
 
-! CHECK: fir.global internal @_QFzeroECa constant : !fir.array<0xcomplex<f32>>
+! CHECK: fir.global internal @_QFzeroECa {alignment = 64 : i64} constant : !fir.array<0xcomplex<f32>>
 ! CHECK:   %0 = fir.undefined !fir.array<0xcomplex<f32>>
 ! CHECK:   fir.has_value %0 : !fir.array<0xcomplex<f32>>
diff --git a/flang/test/Lower/array-constructor-2.f90 b/flang/test/Lower/array-constructor-2.f90
index e08fd111b8649..e4de5312f8f5c 100644
--- a/flang/test/Lower/array-constructor-2.f90
+++ b/flang/test/Lower/array-constructor-2.f90
@@ -153,6 +153,6 @@ subroutine test7(a, n)
   a = (/ (CHAR(i), i=1,n) /)
 end subroutine test7
 
-! CHECK: fir.global internal @_QQro.3xr4.0(dense<[1.000000e+00, 2.000000e+00, 3.000000e+00]> : tensor<3xf32>) constant : !fir.array<3xf32>
+! CHECK: fir.global internal @_QQro.3xr4.0(dense<[1.000000e+00, 2.000000e+00, 3.000000e+00]> : tensor<3xf32>) {alignment = 64 : i64} constant : !fir.array<3xf32>
 
-! CHECK: fir.global internal @_QQro.4xi4.1(dense<[6, 7, 42, 9]> : tensor<4xi32>) constant : !fir.array<4xi32>
+! CHECK: fir.global internal @_QQro.4xi4.1(dense<[6, 7, 42, 9]> : tensor<4xi32>) {alignment = 64 : i64} constant : !fir.array<4xi32>
diff --git a/flang/test/Lower/array.f90 b/flang/test/Lower/array.f90
index f2dfbea9a084f..9a295a381f738 100644
--- a/flang/test/Lower/array.f90
+++ b/flang/test/Lower/array.f90
@@ -151,23 +151,23 @@ end subroutine hugeGlobal
 end
 
 ! c1 data
-! CHECK: fir.global internal @_QFrangeEc1(dense<(0.000000e+00,0.000000e+00)> : tensor<3x2xcomplex<f32>>) : !fir.array<2x3xcomplex<f32>>
+! CHECK: fir.global internal @_QFrangeEc1(dense<(0.000000e+00,0.000000e+00)> : tensor<3x2xcomplex<f32>>) {alignment = 64 : i64} : !fir.array<2x3xcomplex<f32>>
 
 ! a0 array constructor
-! CHECK: fir.global internal @_QQro.10xi4.{{.*}}(dense<[1, 2, 3, 3, 3, 3, 3, 3, 3, 3]> : tensor<10xi32>) constant : !fir.array<10xi32>
+! CHECK: fir.global internal @_QQro.10xi4.{{.*}}(dense<[1, 2, 3, 3, 3, 3, 3, 3, 3, 3]> : tensor<10xi32>) {alignment = 64 : i64} constant : !fir.array<10xi32>
 
 ! a1 array constructor
-! CHECK: fir.global internal @_QQro.2x3xr4.{{.*}}(dense<3.500000e+00> : tensor<3x2xf32>) constant : !fir.array<2x3xf32>
+! CHECK: fir.global internal @_QQro.2x3xr4.{{.*}}(dense<3.500000e+00> : tensor<3x2xf32>) {alignment = 64 : i64} constant : !fir.array<2x3xf32>
 
 ! a2 array constructor
-! CHECK: fir.global internal @_QQro.3x4xi4.{{.*}}(dense<{{\[\[1, 3, 3], \[5, 3, 3], \[3, 3, 9], \[9, 9, 8]]}}> : tensor<4x3xi32>) constant : !fir.array<3x4xi32>
+! CHECK: fir.global internal @_QQro.3x4xi4.{{.*}}(dense<{{\[\[1, 3, 3], \[5, 3, 3], \[3, 3, 9], \[9, 9, 8]]}}> : tensor<4x3xi32>) {alignment = 64 : i64} constant : !fir.array<3x4xi32>
 
 ! a3 array constructor
-! CHECK: fir.global internal @_QQro.2x3x4xi4.{{.*}}(dense<{{\[\[\[1, 1], \[2, 2], \[3, 3]], \[\[4, 4], \[5, 5], \[6, 6]], \[\[7, 7], \[8, 8], \[9, 9]], \[\[10, 10], \[11, 11], \[12, 12]]]}}> : tensor<4x3x2xi32>) constant : !fir.array<2x3x4xi32>
+! CHECK: fir.global internal @_QQro.2x3x4xi4.{{.*}}(dense<{{\[\[\[1, 1], \[2, 2], \[3, 3]], \[\[4, 4], \[5, 5], \[6, 6]], \[\[7, 7], \[8, 8], \[9, 9]], \[\[10, 10], \[11, 11], \[12, 12]]]}}> : tensor<4x3x2xi32>) {alignment = 64 : i64} constant : !fir.array<2x3x4xi32>
 
 ! c0 array constructor
-! CHECK: fir.global internal @_QQro.2x3xz4.{{.*}}(dense<{{\[}}[(1.000000e+00,1.500000e+00), (2.000000e+00,2.500000e+00)], [(3.000000e+00,3.500000e+00), (4.000000e+00,4.500000e+00)], [(5.000000e+00,5.500000e+00), (6.000000e+00,6.500000e+00)]]> : tensor<3x2xcomplex<f32>>) constant : !fir.array<2x3xcomplex<f32>>
+! CHECK: fir.global internal @_QQro.2x3xz4.{{.*}}(dense<{{\[}}[(1.000000e+00,1.500000e+00), (2.000000e+00,2.500000e+00)], [(3.000000e+00,3.500000e+00), (4.000000e+00,4.500000e+00)], [(5.000000e+00,5.500000e+00), (6.000000e+00,6.500000e+00)]]> : tensor<3x2xcomplex<f32>>) {alignment = 64 : i64} constant : !fir.array<2x3xcomplex<f32>>
 
-! CHECK: fir.global internal @_QFrangeglobal{{.*}}(dense<[1, 1, 2, 2, 3, 3]> : tensor<6xi32>) : !fir.array<6xi32>
+! CHECK: fir.global internal @_QFrangeglobal{{.*}}(dense<[1, 1, 2, 2, 3, 3]> : tensor<6xi32>) {alignment = 64 : i64} : !fir.array<6xi32>
 
-! CHECK: fir.global internal @_QQro.500x500xi4.{{.*}}(dense<{{.*}}> : tensor<500x500xi32>) constant : !fir.array<500x500xi32>
+! CHECK: fir.global internal @_QQro.500x500xi4.{{.*}}(dense<{{.*}}> : tensor<500x500xi32>) {alignment = 64 : i64} constant : !fir.array<500x500xi32>
diff --git a/flang/test/Lower/constant-literal-mangling.f90 b/flang/test/Lower/constant-literal-mangling.f90
index 6ef1367369a30..6f72a86a7859a 100644
--- a/flang/test/Lower/constant-literal-mangling.f90
+++ b/flang/test/Lower/constant-literal-mangling.f90
@@ -78,24 +78,24 @@
   print *, [emptyType2()]
 end
 
-! CHECK: fir.global internal @_QQro.1x_QFTsometype.10 constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
+! CHECK: fir.global internal @_QQro.1x_QFTsometype.10 {alignment = 64 : i64} constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
 ! CHECK:   %{{.*}} = arith.constant 11 : i32
 ! CHECK: }
 
-! CHECK: fir.global internal @_QQro.1x_QFTsometype.11 constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
+! CHECK: fir.global internal @_QQro.1x_QFTsometype.11 {alignment = 64 : i64} constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
 ! CHECK:   %{{.*}} = arith.constant 42 : i32
 ! CHECK: }
 
-! CHECK: fir.global internal @_QQro.0x4xc1.null.12 constant : !fir.array<0x!fir.char<1,4>> {
+! CHECK: fir.global internal @_QQro.0x4xc1.null.12 {alignment = 64 : i64} constant : !fir.array<0x!fir.char<1,4>> {
 ! CHECK:   %[[T1:.*]] = fir.undefined !fir.array<0x!fir.char<1,4>>
 ! CHECK:   fir.has_value %[[T1]] : !fir.array<0x!fir.char<1,4>>
 ! CHECK: }
 
-! CHECK: fir.global internal @_QQro.0x2xc1.null.13 constant : !fir.array<0x!fir.char<1,2>> {
+! CHECK: fir.global internal @_QQro.0x2xc1.null.13 {alignment = 64 : i64} constant : !fir.array<0x!fir.char<1,2>> {
 ! CHECK:   %[[T2:.*]] = fir.undefined !fir.array<0x!fir.char<1,2>>
 ! CHECK:   fir.has_value %[[T2]] : !fir.array<0x!fir.char<1,2>>
 ! CHECK: }
 
-! CHECK: fir.global internal @_QQro.1x_QFTothertype.14 constant : !fir.array<1x!fir.type<_QFTothertype{i:i32}>> {
+! CHECK: fir.global internal @_QQro.1x_QFTothertype.14 {alignment = 64 : i64} constant : !fir.array<1x!fir.type<_QFTothertype{i:i32}>> {
 ! CHECK:   %{{.*}} = arith.constant 42 : i32
 ! CHECK: }
diff --git a/flang/test/Lower/constant-logical-transfer.f90 b/flang/test/Lower/constant-logical-transfer.f90
index 9e485bb8026f2..2615f0e79cb28 100644
--- a/flang/test/Lower/constant-logical-transfer.f90
+++ b/flang/test/Lower/constant-logical-transfer.f90
@@ -20,4 +20,4 @@ module constant_logical
 ! CHECK:          %[[BITCAST_1:.*]] = fir.bitcast %[[CONSTANT_1]] : (i64) -> !fir.logical<8>
 ! CHECK:          hlfir.assign %[[BITCAST_1]] to %{{.*}} : !fir.logical<8>, !fir.ref<!fir.logical<8>>
 
-! CHECK:        fir.global @_QMconstant_logicalEvar(dense<[1, 3, 0]> : tensor<3xi32>) : !fir.array<3x!fir.logical<4>>
+! CHECK:        fir.global @_QMconstant_logicalEvar(dense<[1, 3, 0]> : tensor<3xi32>) {alignment = 64 : i64} : !fir.array<3x!fir.logical<4>>
diff --git a/flang/test/Lower/convert.f90 b/flang/test/Lower/convert.f90
index 75d0f844149ce..b9e9f97a20375 100755
--- a/flang/test/Lower/convert.f90
+++ b/flang/test/Lower/convert.f90
@@ -14,7 +14,7 @@ program test
 ! ALL:  %0 = fir.address_of(@_QQEnvironmentDefaults.list) : !fir.ref<tuple<i32, !fir.ref<!fir.array<1xtuple<!fir.ref<i8>, !fir.ref<i8>>>>>>
 ! ALL: fir.call @_FortranAProgramStart(%arg0, %arg1, %arg2, %0)
 
-! ALL: fir.global linkonce @_QQEnvironmentDefaults.items constant : !fir.array<1xtuple<!fir.ref<i8>, !fir.ref<i8>>> {
+! ALL: fir.global linkonce @_QQEnvironmentDefaults.items {alignment = 64 : i64} constant : !fir.array<1xtuple<!fir.ref<i8>, !fir.ref<i8>>> {
 ! ALL: %[[VAL_0:.*]] = fir.undefined !fir.array<1xtuple<!fir.ref<i8>, !fir.ref<i8>>>
 ! ALL: %[[VAL_1:.*]] = fir.address_of(@[[FC_STR:.*]]) : !fir.ref<!fir.char<1,13>>
 ! ALL: %[[VAL_3:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.char<1,13>>) -> !fir.ref<i8>
diff --git a/flang/test/Lower/default-initialization-globals.f90 b/flang/test/Lower/default-initialization-globals.f90
index e9611dab467cb..d799e519eb38b 100644
--- a/flang/test/Lower/default-initialization-globals.f90
+++ b/flang/test/Lower/default-initialization-globals.f90
@@ -72,7 +72,7 @@ module tinit
 
   ! Test array with default init
   type(t0) :: bt0(100)
-! CHECK-LABEL: @_QMtinitEbt0 : !fir.array<100x!fir.type<_QMtinitTt0{k:i32}>> {
+! CHECK-LABEL: @_QMtinitEbt0 {alignment = 64 : i64} : !fir.array<100x!fir.type<_QMtinitTt0{k:i32}>> {
   ! CHECK: %[[VAL_3:.*]] = arith.constant 66 : i32
   ! CHECK: %[[VAL_4:.*]] = fir.undefined !fir.type<_QMtinitTt0{k:i32}>
   ! CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_3]], ["k", !fir.type<_QMtinitTt0{k:i32}>] : (!fir.type<_QMtinitTt0{k:i32}>, i32) -> !fir.type<_QMtinitTt0{k:i32}>
@@ -164,7 +164,7 @@ subroutine eqv()
   type(tseq), save :: somet
   integer :: i(2)
   equivalence (somet, i)
-! CHECK-LABEL: fir.global internal @_QFeqvEi : !fir.array<2xi32> {
+! CHECK-LABEL: fir.global internal @_QFeqvEi {alignment = 64 : i64} : !fir.array<2xi32> {
   ! CHECK-DAG: %[[VAL_50:.*]] = arith.constant 2 : i32
   ! CHECK-DAG: %[[VAL_51:.*]] = arith.constant 3 : i32
   ! CHECK: %[[VAL_52:.*]] = fir.undefined !fir.array<2xi32>
@@ -178,7 +178,7 @@ subroutine eqv_explicit_init()
   type(tseq), save :: somet
   integer :: i(2) = [4, 5]
   equivalence (somet, i)
-! CHECK-LABEL: fir.global internal @_QFeqv_explicit_initEi : !fir.array<2xi32> {
+! CHECK-LABEL: fir.global internal @_QFeqv_explicit_initEi {alignment = 64 : i64} : !fir.array<2xi32> {
   ! CHECK-DAG: %[[VAL_57:.*]] = arith.constant 4 : i32
   ! CHECK-DAG: %[[VAL_58:.*]] = arith.constant 5 : i32
   ! CHECK: %[[VAL_59:.*]] = fir.undefined !fir.array<2xi32>
@@ -191,7 +191,7 @@ subroutine eqv_same_default_init()
   use tinit
   type(tseq), save :: somet1(2), somet2
   equivalence (somet1(1), somet2)
-! CHECK-LABEL: fir.global internal @_QFeqv_same_default_initEsomet1 : !fir.array<2xi64> {
+! CHECK-LABEL: fir.global internal @_QFeqv_same_default_initEsomet1 {alignment = 64 : i64} : !fir.array<2xi64> {
   ! CHECK-LE: %[[VAL_62:.*]] = arith.constant 12884901890 : i64
   ! CHECK-BE: %[[VAL_62:.*]] = arith.constant 8589934595 : i64
   ! CHECK: %[[VAL_63:.*]] = fir.undefined !fir.array<2xi64>
@@ -212,7 +212,7 @@ subroutine eqv_full_overlaps_with_explicit_init()
   equivalence (i, link(1))
   equivalence (somet, link(2))
   equivalence (j, link(3))
-! CHECK-LABEL: fir.global internal @_QFeqv_full_overlaps_with_explicit_initEi : !fir.array<4xi32> {
+! CHECK-LABEL: fir.global internal @_QFeqv_full_overlaps_with_explicit_initEi {alignment = 64 : i64} : !fir.array<4xi32> {
   ! CHECK-DAG: %[[VAL_73:.*]] = arith.constant 5 : i32
   ! CHECK-DAG: %[[VAL_74:.*]] = arith.constant 6 : i32
   ! CHECK-DAG: %[[VAL_75:.*]] = arith.constant 7 : i32
@@ -241,7 +241,7 @@ subroutine eqv_partial_overlaps_with_explicit_init()
   equivalence (i, link(1))
   equivalence (somet, link(2))
   equivalence (j, link(4))
-! CHECK-LABEL: fir.global internal @_QFeqv_partial_overlaps_with_explicit_initEi : !fir.array<4xi32>
+! CHECK-LABEL: fir.global internal @_QFeqv_partial_overlaps_with_explicit_initEi {alignment = 64 : i64} : !fir.array<4xi32>
    ! CHECK-DAG: %[[VAL_82:.*]] = arith.constant 5 : i32
    ! CHECK-DAG: %[[VAL_83:.*]] = arith.constant 6 : i32
    ! CHECK-DAG: %[[VAL_84:.*]] = arith.constant 3 : i32
diff --git a/flang/test/Lower/dense-array-any-rank.f90 b/flang/test/Lower/dense-array-any-rank.f90
index 129adf41de07f..0e11d8e46e516 100644
--- a/flang/test/Lower/dense-array-any-rank.f90
+++ b/flang/test/Lower/dense-array-any-rank.f90
@@ -13,13 +13,13 @@ subroutine test()
 end subroutine
 
 ! a1 array constructor
-! CHECK-FIR: fir.global internal @_QQro.10xi4.{{.*}}(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) constant : !fir.array<10xi32>
+! CHECK-FIR: fir.global internal @_QQro.10xi4.{{.*}}(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {alignment = 64 : i64} constant : !fir.array<10xi32>
 ! CHECK-LLVMIR: @_QQroX10xi4X0 = internal constant [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
 
 ! a2 array constructor
-! CHECK-FIR: fir.global internal @_QQro.3x4xi4.{{.*}}(dense<{{\[\[11, 12, 13], \[21, 22, 23], \[31, 32, 33], \[41, 42, 43]]}}> : tensor<4x3xi32>) constant : !fir.array<3x4xi32>
+! CHECK-FIR: fir.global internal @_QQro.3x4xi4.{{.*}}(dense<{{\[\[11, 12, 13], \[21, 22, 23], \[31, 32, 33], \[41, 42, 43]]}}> : tensor<4x3xi32>) {alignment = 64 : i64} constant : !fir.array<3x4xi32>
 ! CHECK-LLVMIR: @_QQroX3x4xi4X1 = internal constant [4 x [3 x i32]] {{\[\[3 x i32] \[i32 11, i32 12, i32 13], \[3 x i32] \[i32 21, i32 22, i32 23], \[3 x i32] \[i32 31, i32 32, i32 33], \[3 x i32] \[i32 41, i32 42, i32 43]]}}
 
 ! a3 array constructor
-! CHECK-FIR: fir.global internal @_QQro.2x3x4xi4.{{.*}}(dense<{{\[\[\[111, 112], \[121, 122], \[131, 132]], \[\[211, 212], \[221, 222], \[231, 232]], \[\[311, 312], \[321, 322], \[331, 332]], \[\[411, 412], \[421, 422], \[431, 432]]]}}> : tensor<4x3x2xi32>) constant : !fir.array<2x3x4xi32>
+! CHECK-FIR: fir.global internal @_QQro.2x3x4xi4.{{.*}}(dense<{{\[\[\[111, 112], \[121, 122], \[131, 132]], \[\[211, 212], \[221, 222], \[231, 232]], \[\[311, 312], \[321, 322], \[331, 332]], \[\[411, 412], \[421, 422], \[431, 432]]]}}> : tensor<4x3x2xi32>) {alignment = 64 : i64} constant : !fir.array<2x3x4xi32>
 ! CHECK-LLVMIR: @_QQroX2x3x4xi4X2 = internal constant [4 x [3 x [2 x i32]]] {{\[\[3 x \[2 x i32]] \[\[2 x i32] \[i32 111, i32 112], \[2 x i32] \[i32 121, i32 122], \[2 x i32] \[i32 131, i32 132]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 211, i32 212], \[2 x i32] \[i32 221, i32 222], \[2 x i32] \[i32 231, i32 232]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 311, i32 312], \[2 x i32] \[i32 321, i32 322], \[2 x i32] \[i32 331, i32 332]], \[3 x \[2 x i32]] \[\[2 x i32] \[i32 411, i32 412], \[2 x i32] \[i32 421, i32 422], \[2 x i32] \[i32 431, i32 432]]]}}
diff --git a/flang/test/Lower/dense-attributed-array.f90 b/flang/test/Lower/dense-attributed-array.f90
index 2b97436a6cf32..7de146484c11f 100644
--- a/flang/test/Lower/dense-attributed-array.f90
+++ b/flang/test/Lower/dense-attributed-array.f90
@@ -19,5 +19,5 @@ subroutine ss
 !CHECK:  %[[c0:.*]] = arith.constant 53 : i32
 !CHECK:  hlfir.assign %[[c0]] to %[[d0]]#0 : i32, !fir.ref<i32>
 !CHECK:  return
-!CHECK: fir.global @_QMmmECqq(dense<[51, 52, 53]> : tensor<3xi32>) constant : !fir.array<3xi32>
+!CHECK: fir.global @_QMmmECqq(dense<[51, 52, 53]> : tensor<3xi32>) {alignment = 64 : i64} constant : !fir.array<3xi32>
 !CHECK: }
diff --git a/flang/test/Lower/derived-type-descriptor.f90 b/flang/test/Lower/derived-type-descriptor.f90
index 46e4e2b02d51f..76bfea66a3b3a 100644
--- a/flang/test/Lower/derived-type-descriptor.f90
+++ b/flang/test/Lower/derived-type-descriptor.f90
@@ -31,7 +31,7 @@ subroutine foo()
   !CHECK: fir.address_of(@_QFfooE.c.sometype)
 ! CHECK:}
 
-! CHECK-LABEL: fir.global linkonce_odr @_QFfooE.c.sometype constant {{.*}} {
+! CHECK-LABEL: fir.global linkonce_odr @_QFfooE.c.sometype {alignment = 64 : i64} constant {{.*}} {
   ! CHECK: fir.address_of(@_QFfooE.n.num)
   ! CHECK: fir.address_of(@_QFfooE.di.sometype.num) : !fir.ref<i32>
   ! CHECK: fir.address_of(@_QFfooE.n.values)
@@ -50,6 +50,6 @@ subroutine char_comp_init()
 ! CHECK: %[[res:.*]] = fir.string_lit "Empty   "(8) : !fir.char<1,8>
 ! CHECK: fir.has_value %[[res]] : !fir.char<1,8>
 
-! CHECK-LABEL: fir.global linkonce_odr @_QFchar_comp_initE.c.t constant target : {{.*}} {
+! CHECK-LABEL: fir.global linkonce_odr @_QFchar_comp_initE.c.t {alignment = 64 : i64} constant target : {{.*}} {
   ! CHECK: fir.address_of(@_QFchar_comp_initE.di.t.name) : !fir.ref<!fir.char<1,8>>
 ! CHECK: }
diff --git a/flang/test/Lower/equivalence-1.f90 b/flang/test/Lower/equivalence-1.f90
index b27cb55297d7d..5481a87c40ba2 100644
--- a/flang/test/Lower/equivalence-1.f90
+++ b/flang/test/Lower/equivalence-1.f90
@@ -59,7 +59,7 @@ SUBROUTINE s3
 END SUBROUTINE s3
 
 ! test that equivalence in main program containing arrays are placed in global memory.
-! CHECK: fir.global internal @_QFEa : !fir.array<400000000xi8>
+! CHECK: fir.global internal @_QFEa {alignment = 64 : i64} : !fir.array<400000000xi8>
   integer :: a, b(100000000)
   equivalence (a, b)
   b(1) = 42
diff --git a/flang/test/Lower/equivalence-static-init.f90 b/flang/test/Lower/equivalence-static-init.f90
index 1a0f53a4d893d..bc6f882d8a4b4 100644
--- a/flang/test/Lower/equivalence-static-init.f90
+++ b/flang/test/Lower/equivalence-static-init.f90
@@ -7,7 +7,7 @@ module module_without_init
   integer :: i(2)
   equivalence(i(1), x)
 end module
-! CHECK-LABEL: fir.global @_QMmodule_without_initEi : !fir.array<8xi8> {
+! CHECK-LABEL: fir.global @_QMmodule_without_initEi {alignment = 64 : i64} : !fir.array<8xi8> {
   ! CHECK: %0 = fir.zero_bits !fir.array<8xi8>
   ! CHECK: fir.has_value %0 : !fir.array<8xi8>
 ! CHECK: }
@@ -21,7 +21,7 @@ subroutine test_eqv_init
   equivalence (i, link(3))
 end subroutine
 
-! CHECK-LABEL: fir.global internal @_QFtest_eqv_initEi : !fir.array<3xi32> {
+! CHECK-LABEL: fir.global internal @_QFtest_eqv_initEi {alignment = 64 : i64} : !fir.array<3xi32> {
     ! CHECK: %[[VAL_1:.*]] = fir.undefined !fir.array<3xi32>
     ! CHECK: %[[VAL_2:.*]] = fir.insert_value %0, %c7{{.*}}, [0 : index] : (!fir.array<3xi32>, i32) -> !fir.array<3xi32>
     ! CHECK: %[[VAL_3:.*]] = fir.insert_value %1, %c0{{.*}}, [1 : index] : (!fir.array<3xi32>, i32) -> !fir.array<3xi32>
diff --git a/flang/test/Lower/global-alignment.f90 b/flang/test/Lower/global-alignment.f90
new file mode 100644
index 0000000000000..30f4145da3514
--- /dev/null
+++ b/flang/test/Lower/global-alignment.f90
@@ -0,0 +1,74 @@
+! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
+
+module m
+  implicit none
+
+  ! Array Globals that should get alignment 64 by default.
+  integer :: int_array(10)
+  real :: real_array(5, 5)
+  complex :: complex_array(3)
+  logical :: logical_array(4)
+  character(len=10) :: char_array(2)
+
+  integer, target :: target_array(8)
+
+  ! Currently not align 64
+  integer, allocatable :: alloc_array(:)
+
+  ! Non-array and Bind(C) globals should not get alignment 
+  integer :: scalar_var
+
+  integer, bind(c, name="c_int_array") :: bind_c_int_array(10)
+  real, bind(c, name="c_real_array") :: bind_c_real_array(5)
+
+  ! BIND(C) arrays with initializers (exercises tryCreatingDenseGlobal path)
+  integer, bind(c, name="c_init_array") :: bind_c_init_array(5) = [1,2,3,4,5]
+  real, bind(c, name="c_real_init") :: bind_c_real_init(3) = [1.0, 2.0, 3.0]
+
+  integer, bind(c, name="c_scalar") :: bind_c_scalar
+end module
+
+subroutine sub_with_common()
+  implicit none
+  ! Common block (alignment from semantics, not 64)
+  integer :: cb_int(10)
+  real :: cb_real
+  common /myblock/ cb_int, cb_real
+end subroutine
+
+block data
+  implicit none
+  integer :: bd_array(5)
+  common /initblock/ bd_array
+  data bd_array /1, 2, 3, 4, 5/
+end block data
+
+! CHECK: fir.global @initblock_ {alignment = 4 : i64} : tuple<!fir.array<5xi32>>
+! CHECK-NOT: alignment = 64
+! CHECK: fir.global common @myblock_(dense<0> : vector<44xi8>) {alignment = 4 : i64} : !fir.array<44xi8>
+! CHECK-NOT: alignment = 64
+
+! CHECK: fir.global @_QMmEalloc_array : !fir.box<!fir.heap<!fir.array<?xi32>>>
+! CHECK-NOT: alignment
+
+! CHECK: fir.global @c_init_array(dense<[1, 2, 3, 4, 5]> : tensor<5xi32>) : !fir.array<5xi32>
+! CHECK-NOT: alignment
+! CHECK: fir.global common @c_int_array : !fir.array<10xi32>
+! CHECK-NOT: alignment
+! CHECK: fir.global common @c_real_array : !fir.array<5xf32>
+! CHECK-NOT: alignment
+! CHECK: fir.global @c_real_init(dense<[1.000000e+00, 2.000000e+00, 3.000000e+00]> : tensor<3xf32>) : !fir.array<3xf32>
+! CHECK-NOT: alignment
+! CHECK: fir.global common @c_scalar : i32
+! CHECK-NOT: alignment
+
+! CHECK: fir.global @_QMmEchar_array {alignment = 64 : i64} : !fir.array<2x!fir.char<1,10>>
+! CHECK: fir.global @_QMmEcomplex_array {alignment = 64 : i64} : !fir.array<3xcomplex<f32>>
+! CHECK: fir.global @_QMmEint_array {alignment = 64 : i64} : !fir.array<10xi32>
+! CHECK: fir.global @_QMmElogical_array {alignment = 64 : i64} : !fir.array<4x!fir.logical<4>>
+! CHECK: fir.global @_QMmEreal_array {alignment = 64 : i64} : !fir.array<5x5xf32>
+
+! CHECK: fir.global @_QMmEscalar_var : i32
+! CHECK-NOT: alignment
+
+! CHECK: fir.global @_QMmEtarget_array {alignment = 64 : i64} target : !fir.array<8xi32>
diff --git a/flang/test/Lower/io-derived-type.f90 b/flang/test/Lower/io-derived-type.f90
index 7c289ce261678..a3c8eb4b1233d 100644
--- a/flang/test/Lower/io-derived-type.f90
+++ b/flang/test/Lower/io-derived-type.f90
@@ -128,8 +128,8 @@ program p
   print *, y(2:3)
 end
 
-! CHECK: fir.global linkonce @_QQMmFtest1.nonTbpDefinedIoTable.list constant : !fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>
+! CHECK: fir.global linkonce @_QQMmFtest1.nonTbpDefinedIoTable.list {alignment = 64 : i64} constant : !fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>
 ! CHECK: fir.global linkonce @_QQMmFtest1.nonTbpDefinedIoTable constant : tuple<i64, !fir.ref<!fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>>, i1>
 ! CHECK: fir.global linkonce @_QQdefault.nonTbpDefinedIoTable constant : tuple<i64, !fir.ref<!fir.array<0xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>>, i1>
-! CHECK: fir.global linkonce @_QQF.nonTbpDefinedIoTable.list constant : !fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>
+! CHECK: fir.global linkonce @_QQF.nonTbpDefinedIoTable.list {alignment = 64 : i64} constant : !fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>
 ! CHECK: fir.global linkonce @_QQF.nonTbpDefinedIoTable constant : tuple<i64, !fir.ref<!fir.array<1xtuple<!fir.ref<none>, !fir.ref<none>, i32, i8>>>, i1>
diff --git a/flang/test/Lower/module_definition.f90 b/flang/test/Lower/module_definition.f90
index a96bc919c6730..fda9f65a05f85 100644
--- a/flang/test/Lower/module_definition.f90
+++ b/flang/test/Lower/module_definition.f90
@@ -30,7 +30,7 @@ module m1
   integer :: y(100)
 end module
 ! CHECK: fir.global @_QMm1Ex : f32
-! CHECK: fir.global @_QMm1Ey : !fir.array<100xi32>
+! CHECK: fir.global @_QMm1Ey {alignment = 64 : i64} : !fir.array<100xi32>
 
 ! Module modEq1 defines data that is equivalenced and not used in this
 ! file.
@@ -42,8 +42,8 @@ module modEq1
   real :: y2(10)
   equivalence (x1(1), x2(5), x3(10)), (y1, y2(5))
 end module
-! CHECK-LABEL: fir.global @_QMmodeq1Ex1 : !fir.array<76xi8>
-! CHECK-LABEL: fir.global @_QMmodeq1Ey1 : !fir.array<10xi32> {
+! CHECK-LABEL: fir.global @_QMmodeq1Ex1 {alignment = 64 : i64} : !fir.array<76xi8>
+! CHECK-LABEL: fir.global @_QMmodeq1Ey1 {alignment = 64 : i64} : !fir.array<10xi32> {
   ! CHECK: %[[undef:.*]] = fir.undefined !fir.array<10xi32>
   ! CHECK: %[[v1:.*]] = fir.insert_on_range %0, %c0{{.*}} from (0) to (3) : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
   ! CHECK: %[[v2:.*]] = fir.insert_value %1, %c1109917696{{.*}}, [4 : index] : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
diff --git a/flang/test/Lower/module_use.f90 b/flang/test/Lower/module_use.f90
index e7f56f57b2c7e..ab7d7b445407b 100644
--- a/flang/test/Lower/module_use.f90
+++ b/flang/test/Lower/module_use.f90
@@ -41,4 +41,4 @@ real function modCommon1Use()
 
 
 ! CHECK-DAG: fir.global @_QMm1Ex : f32
-! CHECK-DAG: fir.global @_QMm1Ey : !fir.array<100xi32>
+! CHECK-DAG: fir.global @_QMm1Ey {alignment = 64 : i64} : !fir.array<100xi32>
diff --git a/flang/test/Lower/namelist-common-block.f90 b/flang/test/Lower/namelist-common-block.f90
index 200aee609a56a..47916358297d4 100644
--- a/flang/test/Lower/namelist-common-block.f90
+++ b/flang/test/Lower/namelist-common-block.f90
@@ -17,7 +17,7 @@ subroutine print_t()
   end subroutine
 end
 
-! CHECK-LABEL: fir.global linkonce @_QFNt.list constant : !fir.array<2xtuple<!fir.ref<i8>, !fir.ref<!fir.box<none>>>> {
+! CHECK-LABEL: fir.global linkonce @_QFNt.list {alignment = 64 : i64} constant : !fir.array<2xtuple<!fir.ref<i8>, !fir.ref<!fir.box<none>>>> {
 ! CHECK: %[[CB_ADDR:.*]] = fir.address_of(@c_) : !fir.ref<!fir.array<56xi8>>
 ! CHECK: %[[CB_CAST:.*]] = fir.convert %[[CB_ADDR]] : (!fir.ref<!fir.array<56xi8>>) -> !fir.ref<!fir.array<?xi8>>
 ! CHECK: %[[OFFSET:.*]] = arith.constant 8 : index
diff --git a/m.mod b/m.mod
new file mode 100644
index 0000000000000..5bbcf38157941
--- /dev/null
+++ b/m.mod
@@ -0,0 +1,16 @@
+!mod$ v1 sum:444ba0b36254725f
+module m
+integer(4)::int_array(1_8:10_8)
+real(4)::real_array(1_8:5_8,1_8:5_8)
+complex(4)::complex_array(1_8:3_8)
+logical(4)::logical_array(1_8:4_8)
+character(10_4,1)::char_array(1_8:2_8)
+integer(4),target::target_array(1_8:8_8)
+integer(4),allocatable::alloc_array(:)
+integer(4)::scalar_var
+integer(4),bind(c,name="c_int_array")::bind_c_int_array(1_8:10_8)
+real(4),bind(c,name="c_real_array")::bind_c_real_array(1_8:5_8)
+integer(4),bind(c,name="c_init_array")::bind_c_init_array(1_8:5_8)
+real(4),bind(c,name="c_real_init")::bind_c_real_init(1_8:3_8)
+integer(4),bind(c,name="c_scalar")::bind_c_scalar
+end



More information about the flang-commits mailing list