From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CA0F33858D34; Wed, 6 Mar 2024 17:50:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA0F33858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709747417; bh=2gOibO5bhvuJZFOmObyIFs0o+6B5bZAuA3jSzgilJ4A=; h=From:To:Subject:Date:From; b=UjJLPDJYibQeECFJN9+RF+EvVQ4nTLKDT62EwoUerOSSnR/QS481aqLRnFNw0ef9L M0DMAg1XnACbp9hqIcYxfABdAiwWzh0Xjc8kLhoVtuI/4Vx+Qq95foRjSuECDRFfXe W7ylIwsNTP7FKl+f5rm4FwGuKKvMxEr39CjLPGo0= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/114258] New: repeat store operation when copying a union Date: Wed, 06 Mar 2024 17:50:17 +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=3D114258 Bug ID: 114258 Summary: repeat store operation when copying a union 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 and generated binary compiled with gcc-13.2.0 -O2: ``` // https://godbolt.org/z/jsMhcbKnh union U6 { int f0; long long f1; int f2; }; union U8 { int f0; const long long f1; const long long f2; }; union U6 g_13 =3D {.f0 =3D 0xE13F5E3DL}; union U8 g_189 =3D {.f0 =3D 0x959411BBL}; int d =3D 0; int a; void func_1() { const union U6 b[] =3D {{.f0 =3D 2}, {.f0 =3D 2}}; for (; d;) a =3D 0; g_189.f0 &=3D (g_13 =3D b[1], 5); } ``` ``` func_1: mov 0x2f02(%rip),%eax # 404028 test %eax,%eax je 401130 jmp 40112a nopl 0x0(%rax) movq $0x0,0x2edd(%rip) # 404018 andl $0x5,0x2ece(%rip) # 404010 movl $0x2,0x2ecc(%rip) # 404018 ret ``` we can see that the first write to `g_13` could be removed to improve performance.=