From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 28ABF3858C36; Thu, 29 Feb 2024 15:35:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28ABF3858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709220948; bh=nulQBnTmNR23fwAA5gUgS5xozsIeYtd6BWEVyKzUJfU=; h=From:To:Subject:Date:From; b=MiYllVYGJw6jgDCI7xE1MZ5nnCtA32soSqbrvL9rs3oXe/elLbWjJcAXY8ETSSqcr nDHUCgZZjckYW/oJ7LHVwINokHAA1sY9wEz88AS3onjwpieHE7mo3+goYxMHmU6hZW ppnfKTEf4GY9byjatoxRKDUlYR2jGFkEHh8kQq1w= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/114169] New: miss optimization of repeat load&store in place Date: Thu, 29 Feb 2024 15:35:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114169 Bug ID: 114169 Summary: miss optimization of repeat load&store in place Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- Hi, here's the code: ``` typedef signed char int8_t; typedef unsigned char uint8_t; typedef signed short int int16_t; typedef unsigned short int uint16_t; typedef signed int int32_t; typedef unsigned int uint32_t; typedef signed long int int64_t; typedef unsigned long int uint64_t; #include #include #include #include /* --- Struct/Union Declarations --- */ struct S0 { int32_t f0; uint16_t f1; int32_t f2; int32_t f3; uint16_t f4; uint16_t f5; int32_t f6; int16_t f7; }; /* --- GLOBAL VARIABLES --- */ struct S0 g_2 =3D {1L,0xF8C7L,0x5C6EFF3DL,0x0369BD69L,65535UL,0x0CA9L,-9L,0x9C92L}; struct S0 g_4 =3D {-1L,0UL,0x314A5EA9L,0x4A90C6D2L,0xCD43L,65528UL,0x2E40C18AL,0x9C27L}; int16_t g_17 =3D 0xF85AL; uint16_t g_18 =3D 0xA88AL; const uint64_t g_19 =3D 0UL; /* --- FORWARD DECLARATIONS --- */ struct S0 func_1(void); void func_10(struct S0 p_13); struct S0 func_1() { int32_t a; g_4 =3D g_2; func_10(g_4); } void func_10(struct S0 b) { int32_t c =3D 0; int32_t *d =3D &g_4.f0; struct S0 *e =3D &g_2; *d =3D c; *e =3D b; } ``` compiled with gcc-13.2.0 -O3, it generates: https://godbolt.org/z/4d9roGWTz ``` 0000000000401630 : func_1(): /root/loadtest3/test/output2.c:49 401630: movdqa 0x2a58(%rip),%xmm0 # 404090 401638: mov 0x2a52(%rip),%eax # 404090 # load 40163e: movdqu 0x2a56(%rip),%xmm1 # 40409c 401646: movaps %xmm0,0x2a23(%rip) # 404070 func_10(): /root/loadtest3/test/output2.c:57 40164d: mov %eax,0x2a3d(%rip) # 404090 # store 401653: movzwl 0x2a1a(%rip),%eax # 404074 func_1(): /root/loadtest3/test/output2.c:49 40165a: movups %xmm1,0x2a1b(%rip) # 40407c func_10(): /root/loadtest3/test/output2.c:57 401661: mov %ax,0x2a2c(%rip) # 404094 401668: mov 0x2a09(%rip),%rax # 404078 /root/loadtest3/test/output2.c:56 40166f: movl $0x0,0x29f7(%rip) # 404070 /root/loadtest3/test/output2.c:57 401679: mov %rax,0x2a18(%rip) # 404098 401680: mov 0x29f9(%rip),%rax # 404080 401687: mov %rax,0x2a12(%rip) # 4040a0 40168e: movzwl 0x29f3(%rip),%eax # 404088 401695: mov %ax,0x2a0c(%rip) # 4040a8 func_1(): /root/loadtest3/test/output2.c:51 40169c: mov %rdi,%rax 40169f: retq=20=20=20 ``` we can see the pair of load&store at address 0x401638 and 0x40164d is unnecessary=