https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105448
Bug ID: 105448 Summary: load introduced when passing a struct as argument Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- Created attachment 52915 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52915&action=edit C source file where a struct field has been loaded repeatedly Hi, I find in this code: (the full file has been uploaded) ... struct S0 { const uint64_t f0; int32_t f1; int64_t f2; int32_t f3; int64_t f4; const int32_t f5; }; struct S0 g_19 = {0xF4275799D45EB447LL,0xD326D35DL,1L,1L,9L,0L}; ... const int16_t func_2(uint32_t p_3, const struct S1 p_4) { if (func_7(g_19, 0, g_20)) { return 0; } return g_6.f1; } int32_t func_7(struct S0 p_10, uint32_t p_11, int32_t p_12) { func_21(0, g_26, p_10); return p_10.f1; } int32_t func_21(int32_t p_22, int64_t p_23, struct S0 p_24) { if ((g_5[0] - (g_5[1] != p_23)) ) { g_19.f3 = p_24.f4; } return g_5[4]; } int main(){ ... func_2(0, g_6); ... } when compiled on gcc-11.3.0 with O1 option, func_2 will be compiled as: ... 0x000000000040118a <+5>: movdqa 0x2ece(%rip),%xmm0 # 0x404060 <g_19> 0x0000000000401192 <+13>: movaps %xmm0,(%rsp) 0x0000000000401196 <+17>: mov 0x2ecc(%rip),%ebx # 0x404068 <g_19+8> 0x000000000040119c <+23>: mov %ebx,0x8(%rsp) 0x00000000004011a0 <+27>: pushq 0x2ee2(%rip) # 0x404088 <g_19+40> 0x00000000004011a6 <+33>: pushq 0x2ed4(%rip) # 0x404080 <g_19+32> 0x00000000004011ac <+39>: pushq 0x2ec6(%rip) # 0x404078 <g_19+24> 0x00000000004011b2 <+45>: pushq 0x2eb8(%rip) # 0x404070 <g_19+16> ... it's obvious that g_19.f1 has been loaded twice in the first and third instruction abnormally.