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

    <tr>
        <th>Summary</th>
        <td>
            The Union type affects the elimination of redundant memory access.
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          vfdff
      </td>
    </tr>
</table>

<pre>
    * test: https://gcc.godbolt.org/z/7ebq45TMx

* when we defined the type __m256 with a union type
```
typedef union {
     fvec32 vect_f32;
} __m256, __m256d;

FORCE_INLINE __m256 _mm256_loadu_ps(float const * mem_addr)
{
    __m256 res;
    res.vect_f32 = svld1_f32(svptrue_b32(), mem_addr);
    return res;
}

FORCE_INLINE __m256 _mm256_mul_ps(__m256 a, __m256 b)
{
    __m256 res;
    res.vect_f32 = svmul_f32_z(svptrue_b32(), a.vect_f32, b.vect_f32);
    return res;
}

__m256 calculate(__m256 a, __m256 b) {
    return _mm256_mul_ps(a, b);
}
```
 we'll get it assemble with 2 memory load **ld1w**
```
calculate(__m256, __m256):                  // @calculate(__m256, __m256)
        ptrue   p0.s
        ld1w    { z0.s }, p0/z, [x0]
        ld1w    { z1.s }, p0/z, [x1]
        fmul    z0.s, z1.s, z0.s
        st1w    { z0.s }, p0, [x8]
        ret
```

*  then, if we defined it typedef svfloat32_t __m256; (**change the #if 1 to #if 0 in line 21**)
```
FORCE_INLINE __m256 _mm256_loadu_ps(float const * mem_addr)
{
     __m256 res;
     res = svld1_f32(svptrue_b32(), mem_addr);
     return res;
}

FORCE_INLINE __m256 _mm256_mul_ps(__m256 a, __m256 b)
{
     __m256 res;
     res = svmul_f32_z(svptrue_b32(), a, b);
     return res;
}

__m256 calculate(__m256 a, __m256 b) {
    return _mm256_mul_ps(a, b);
}
```
we can have efficient assemble 
```
calculate(__SVFloat32_t, __SVFloat32_t): // @calculate(__SVFloat32_t, __SVFloat32_t)
        fmul    z0.s, z0.s, z1.s
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVt-PozYQ_mucl9FFMA4hPPCQH4d0UnuV2mtfkYFxcGUgxSa53b--siGb5LK53erUNlph7GFmvs-e-dbCGLVviVIWbVi0m4nB1l2fHmUl5azoqqeU4RosGcv4GmprD4bxNcOMYbYvy_m-q4pO23nX7xlmzwyzmIq_FtGXn7-yYMeC9fTENZxqauFEUJFULVVgawL7dCDI8wajJZyUrUHA0Kqu9YbJdRlMf37qDBXJ6TMWb8ZlcD95pJIjHKm0ueTI-GRk8W5KwnA7vVUXq39mv_y6_Zh_-vzTp88fz4jyxg257kQ15AfDcCV1JyyUXWssOE4NNbmoqp5hck51BWgK05N5SeaWezLzM0ZgfAfmqKvQI8aVOR5sP1Be-JmLi9ubNLeR7NC3NwlYvHsnrWbQI6lpWVw2B4ofJeSCS4758yNK4sXDzYqr2T-lOIEqhS4HLSw9ZnRbLlPkb3fDOxXXMC75bksRTsQw1hr2ZEFZEMZQU2gaKxndqXX9E7jyccXCcK2r8DS-vRrwnsKFgAc0lvnNb2xFYIvgLe9LnwCAPxE3BnNza3EYfeB4A8_B3ICjj1s4BGODb4FFm68Bi3bf8Qsf-YV3frIZtBtdLveV8_XjHTJjHyMbo6_uovdkX93qiyw5HWpdACWv1UlZOEuNOfq255jb83byDbCPGdts2Wo1HmhZi3ZPXtQYciUhBNtNrwGoFrRqCTCcjn9yTl4F929o0aPedQs_JkL_uQq9g8rb8nPX5e-k8r-pzYmgFC3U4khAUqpSUXulOe8QlN_-yM51PEK9WfDy8khN3nL9fkdfd_Yb3TmrUl4lPBEzSsNlsoiXPFzgrE5jTHggoijhFEYRSlktCpSyFEG1XAaCz1SKAfIgCaMg5og4T3gkkjBJQh6QEFiwRUCNUHqu9bFxF5aZMmagdLlcLOOZFgVp469BiC2dwBsZorsV9anz-VAMe8MWgVbGmksUq6ym9EtN8PvL1QWElFRa4_WAtGpUK6wzdhJ6qoa2Eq09_4MQZUnGzGdDr9NvbljK1kMxL7uGYeYSTsOHQ9_9SaVlmHmYhmHmafwdAAD__6SOs_U">