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

    <tr>
        <th>Summary</th>
        <td>
            Mismatched padding between `byval` and globals
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:codegen,
            miscompilation
      </td>
    </tr>

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

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

<pre>
    Reproducer: https://godbolt.org/z/PexPvPjf6
```
#include <stdint.h>
#include <stdio.h>
int8_t safe_mul_func_int8_t_s_s(int8_t si1, int8_t si2) {

 return (((si1 > 0) && (si2 > 0) && (si1 > (INT8_MAX / si2))) ||
 ((si1 > 0) && (si2 <= 0) && (si2 < (INT8_MIN / si1))) ||
          ((si1 <= 0) && (si2 > 0) && (si1 < (INT8_MIN / si2))) ||
          ((si1 <= 0) && (si2 <= 0) && (si1 != 0) && (si2 < (INT8_MAX / si1))))
             ? 0
 : si1 * si2;
}
uint64_t safe_div_func_uint64_t_u_u(uint64_t ui1, uint64_t ui2) {
  return (ui2 == 0) ? 0 : (ui1 / ui2);
}
struct a {
 uint32_t b;
  uint64_t c;
  int32_t d;
  int32_t z;
} e = {5, 0, 1, 90986701};
int32_t *f;
int32_t h, r, p, q, s, m;
uint8_t g[3][3][4];
uint32_t o;
int64_t l;
struct a aa[1];
uint32_t n[1][1];
const int32_t *ab(int32_t *, struct a);
uint8_t ad(struct a);
int32_t *ac(int32_t *, struct a, uint32_t *, uint32_t *, int16_t);
int32_t *t(int16_t);
int64_t af(int16_t, struct a, uint16_t, int8_t);
int32_t u() {
  struct a ag;
  ab(f, ag);
  return 0;
}
const int32_t *ab(int32_t *, struct a) {
  ad(e);
  return &r;
}
uint8_t ad(struct a ah) {
  int8_t ae[3];
  int i, j, k;
  for (i = 0; i < 3; i++)
    ae[i] = 1;
  for (;;) {
    uint32_t *v = &p;
    if (ah.z) {
 uint32_t *aj[2][4][4];
      for (i = j = k = 0; k < 4; k++)
 aj[i][j][k] = 0;
      for (ah.b = 0;;) {
        int32_t ak;
        if (ae[ah.d]) {
          ac(t(af(0, ah, ah.b, e.z)), ah, aj[0][0][0], v, ah.c);
          return s;
        }
      }
    }
  }
}
int32_t *ac(int32_t *al, struct a y, uint32_t *, uint32_t *, int16_t ai) {
  if (1 >= (aa[0] = y, ai))
    return al;
}
int32_t *t(int16_t) { return &q; }
int64_t af(int16_t, struct a am, uint16_t, int8_t) {
  int32_t w = 7;
 am = e;
  for (h = 0; h <= 2; h++)
    for (o = 0; o <= 2; o++) {
 int32_t *an = &w;
      int64_t *ao = &l;
      uint8_t *x = &g[1][2][3];
 w ^= g[2][1][3];
      if (safe_mul_func_int8_t_s_s(
 am.c, m == (*x ^= 1 <= safe_mul_func_int8_t_s_s(
 safe_div_func_uint64_t_u_u(*ao, am.z),
 *an))))
        ++n[2][0];
    }
  return am.z;
}
int main() {
  int i;
  u();
  i = 0;
  printf("%d\n", aa[i].b);
}
```
```
> clang -O0 test.c && ./a.out
0
> clang -O3 test.c && ./a.out
5
```
```
%struct.a = type { i32, i64, i32, i32 }
@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8
define dso_local zeroext i8 @ad(ptr noundef byval(%struct.a) align 8 %ah)
%call = call zeroext i8 @ad(ptr noundef byval(%struct.a) align 8 @e)
```
We should also emit the padding for `%struct.a`.
llvm version: d21fc58aeeaa7f0369a24dbe70a0360e0edbf76f
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykWEuPo7oS_jXOpjSRsQMhiyxIeiLNYuaOrq50zy4yYIK7CWTApB-__shlDA6d7jOj00J-Vn31cFXZadF16lRLuSXhjoQPC9Hrsmm3uc5e3l6fF2mTv27_Ky9tk_eZbAlPoNT60hGeEHYg7HBq8rSp9LJpT4Qd3gg7_JQvP68_H4uI0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