From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1DD0B387085F; Mon, 27 Apr 2020 12:48:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DD0B387085F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587991713; bh=eSZKRlNx296I1KphG9X1Ul17aXu8gIbIluy0/9jNjZg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jOOr4awI9/V6gPCyLDTNfwvniyDwPLhwWCV4Hb/kdavHJfuJuZW0Ok6WGsozVaRrZ DA/enj4WcNu44FOoIamTgRt9uEmJcbzD2WSmG8/7d2rZ1RzGpj8PDEyFHG2zhd2+cx aWQ/4ZSBYvrfE2SGt51UNVTrWQy+/I9+5DnrAqdA= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/57359] store motion causes wrong code for union access at -O3 Date: Mon, 27 Apr 2020 12:48:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: alias, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2020 12:48:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D57359 --- Comment #30 from Richard Biener --- Created attachment 48381 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48381&action=3Dedit more complex approach, POC Another testcase, this time for store ordering (IIRC we may have a duplicate for this). We currently use a fixed order of *p and *r for _both_ exits which is of course wrong. POC patch fixing all issues attached, it needs to be enhanced to not give up when not all stores we want to move are stored in the exit block. Also some memory leaks need fixing and we need to avoid doing redundant work when enhancing the scheme and eventually enhance it to prune SMs we cannot perfo= rm. extern void abort(); typedef int A; typedef float B; void __attribute__((noinline,noclone)) foo(A * p, B *r, long unk, long oh) { for (long i =3D 0; i < unk; ++i) { *p =3D 1; *r =3D 2; if (oh & i) break; *r =3D 3; *p =3D 4; } } int main(void) { union { A x; B f; } u; foo(&u.x, &u.f, 1, 1); if (u.x !=3D 4) abort(); foo(&u.x, &u.f, 2, 1); if (u.f !=3D 2) abort (); return 0; }=