From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3CCB53858C2D; Tue, 27 Sep 2022 11:25:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CCB53858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664277934; bh=tfMBK30Xs69D6gDAxR8RGlVzaPssDQcQ0szf0II2AHU=; h=From:To:Subject:Date:From; b=nmspRoIfaHKixVPkOCdOE4CeVHLJ5pSrM5MwtQTvkvJfvR6h8sX8L1fRf/XWbNTet k48msqAmdwy8hB+07RH06llRu9Ng69pEGG1RT5SRcuD1rmaio+6JIrWLKoYPMVupJG UKoTPsulo7P92yoP0iQM8A3TbaV6JOiF/VPmAq+E= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/107051] New: redundant loads when copying a union Date: Tue, 27 Sep 2022 11:25:33 +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: 12.1.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=3D107051 Bug ID: 107051 Summary: redundant loads when copying a union Product: gcc Version: 12.1.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: --- for this code: union U2 { unsigned f0; char * f1; }; union U2 g_284[2] =3D {{0UL},{0xC2488F72L}}; int e; void func_1() { union U2 c =3D {7}; int32_t *d[2]; for (; e;) *d[1] =3D 0; g_284[0] =3D c =3D g_284[1]; } compile it with gcc-12.1.0 -O1, and generate: 0000000000401186 : 401186: 83 3d fb 8c 00 00 00 cmpl $0x0,0x8cfb(%rip) # 409e88 40118d: 74 02 je 401191 40118f: eb fe jmp 40118f 401191: 8b 15 d1 2e 00 00 mov 0x2ed1(%rip),%edx # 404068 401197: 48 b8 00 00 00 00 ff movabs $0xffffffff00000000,%rax 40119e: ff ff ff=20 4011a1: 48 23 05 c0 2e 00 00 and 0x2ec0(%rip),%rax # 404068 4011a8: 48 09 d0 or %rdx,%rax 4011ab: 48 89 05 ae 2e 00 00 mov %rax,0x2eae(%rip) # 404060 4011b2: c3 retq=20 I don't understand why clearing the low 4 bytes of g_284[1].f1 and then or = it with g_284[1].f0, because it should be equal? and for the next example, we can see the both fields of g_303 have been loa= ded and written to g: union U0 { short f0; int f3; }; union U0 g_303 =3D {0x9B86L}; union U0 g; int a,b; void func_1() { union U0 d[1] =3D {1}; for (; a;) for (; b;) ; g =3D d[0] =3D g_303; } under gcc-12.1.0 -O1: 0000000000401186 : 401186: 83 3d ff 8c 00 00 00 cmpl $0x0,0x8cff(%rip) # 409e8c 40118d: 74 02 je 401191 40118f: eb fe jmp 40118f 401191: 8b 05 c9 2e 00 00 mov 0x2ec9(%rip),%eax # 404060 401197: 66 8b 05 c2 2e 00 00 mov 0x2ec2(%rip),%ax # 40= 4060 40119e: 89 05 ec 8c 00 00 mov %eax,0x8cec(%rip) # 409e90 4011a4: c3 retq=