<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/115282>115282</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [GlobalOpt] Reduction of global aggregate with alignment constraint unnecessarily propagates alignment to some elements
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          brunodf-snps
      </td>
    </tr>
</table>

<pre>
    When GlobalOpt performs SRA on a global aggregate with an alignment constraint, it seems to propagate the alignment to _some_ of the elements haphazardly. For example:

```
alignas(32) static int params[8];
```

On a plain 32 bit architecture, the array elements respectively have alignment: 32, 4, 8, 4, 16, 4, 8, 4
GlobalOpt SRA creates individual global variables for the elements with respective alignments: 32, 32, 8, 32, 16, 32, 8, 32

I don't see any benefit to increase the alignments elements 1, 3, 5, 7 from 4 to 32. This is wasteful because the new elements cannot be mapped consecutively in memory anymore.

Godbolt demo: https://godbolt.org/z/WjbPjY9Kh
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0U8FupDgQ_RpzKaUFpmngwCGZqEerPcxqdqXRnkYFLsCRsZHLdLbn61d2ekISzUiosF2q8qv3_JBZT5aoE9WDqB4z3MLsfNf7zTo13rFdOeudunbfZrLw2bgezZc1wEp-dH5h-PvrPTgLCFPKAU6TpwkDwbMOM6AFNHqyC9kAg7McPGobhPwEOgATLQzBwerdiqkqzPSmIjj4zm6h7-DGlCJDMcEw4zrjD_TKXA9wdh7oP1xWQ6K8F_mjyH_GU3770jZ1RhayKaWQLXDAoAfQNsCKHhcW1UMjqkdRPvyy_iV-ifOuBrWFUkKvA6AfZh1oCJunOFuawnu87oA98UpD0BcyV5jx8mZMUd5DxPMJjjE0r6vi9PEw3b_LENkfPGEgBm2Vvmi1ofmpxQW9xt4Qw-j8e_qSODukHQvvYF5isy9f4Lw_fkPLH6CcFbJOugLaK_RkadRJRm0jTv4gMO-IitQwhiqGGkbvFjjG2lIe4J9ZM2iGZ-RA42agpwG3Wz9Lz3ujAa11AXqCBdeVVHp2NGw36rWFhRbnrxHh4jwd3s7w2anemQCKFheZmENYIyVCnoU8Ty_Zg_OTkOcfQp6_PfV_Pf3b_jlnqitVW7aYUVfUZd7WRXlqs7krmmFoalW0BapT3w-FrMo6P441nYq6bapMdzKXx6LI67yV8tgeCEkqKio1yrzHsRHHnBbU5mDMZYl3Z5p5o64oKtnIzGBPhpOBpYxMpKyQMvrZd7Hort8mFsfcaA68twk6mOT81wclqkf4SmobgnY2eu43rv6FpWGzlgZiRq_NdXc0v7dzdPOrVtnmTfeBYh3mrT8MbhHyHJHefnerd080BCHPaT4W8nwj4NLJ_wMAAP__NtmNzw">