From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9696B3858439; Wed, 27 Mar 2024 00:21:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9696B3858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711498899; bh=hGM9DSPaTbH4LfMIMPOxQnQyi6+tvMaFPts0L/xaGBM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DhQEaUWJkKtwOWniL7raSTEwWG9PjxWiUpOCimT37dP+dIlzNZKQkPXAeuA8A1sCH VGWzKLzJlEWcEz+S1RVzo22eXUSxkk3rGjwn9Emlt4nq7E5VOqLvNgwO3pU2drJ/D4 Rd3W30y35TjA5y6lIERaoDNecPOBu1dlR5UEHWPA= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/107051] redundant loads when copying a union Date: Wed, 27 Mar 2024 00:21:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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 --- Comment #2 from absoler at smail dot nju.edu.cn --- (In reply to Richard Biener from comment #1) > With -O2 I see >=20 > func_1: > .LFB0: > .cfi_startproc > movl e(%rip), %eax > testl %eax, %eax > je .L2 > .L3: > jmp .L3 > .p2align 4,,10 > .p2align 3 > .L2: > movq g_284+8(%rip), %rax > movq %rax, g_284(%rip) > ret >=20 > note that with -O1 we retain >=20 > c =3D g_284[1]; > c$f0_3 =3D g_284[1].f0; > c.f0 =3D c$f0_3; > g_284[0] =3D c; >=20 > after GIMPLE optimization which possibly explains this compared to >=20 > c =3D g_284[1]; > g_284[0] =3D c; >=20 > with -O2. for gcc-13.2.0 -O2, it seems still forget to remove the load for this reduc= ed case: ``` union U0 { short f1; int f2; }; union U0 g1, g2; volatile int flag; void func_1() { union U0 d[1] =3D {{.f1 =3D 1}}; for (; flag;) ; d[0] =3D g2; g1 =3D d[0]; } ``` ``` func_1: .LFB0: .cfi_startproc .p2align 4,,10 .p2align 3 .L2: movl flag(%rip), %eax testl %eax, %eax jne .L2 movl g2(%rip), %eax movw g2(%rip), %ax movl %eax, g1(%rip) ret .cfi_endproc ```=