From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 77BE8385840D; Wed, 22 Nov 2023 10:46:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77BE8385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700649965; bh=Uj2AX81ek/ldlmU4p9LS6gzMbcrYADkTrnBFZfac4xY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kattYkGhEjX3A8/cuNBWpGl3fOEl0YdVj/liPDpRtISVqcINNkK47iMJwuXvg3xKl y5na1CDMxGGjfRBvlrq5DGn+6dX5MJy21h7mwE4woRuiLJ3rjPy/rlf55T/l4tZh2g 69thPw0cPci9oWfyVPbw3y8MdyfKJdW2CtNU2wAg= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112653] We should optimize memmove to memcpy using alias oracle Date: Wed, 22 Nov 2023 10:46:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: unknown X-Bugzilla-Keywords: alias, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org 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=3D112653 --- Comment #4 from Richard Biener --- We do use the alias oracle in folding memmove: /* If the destination and source do not alias optimize into memcpy as well. */ if ((is_gimple_min_invariant (dest) || TREE_CODE (dest) =3D=3D SSA_NAME) && (is_gimple_min_invariant (src) || TREE_CODE (src) =3D=3D SSA_NAME)) { ao_ref destr, srcr; ao_ref_init_from_ptr_and_size (&destr, dest, len); ao_ref_init_from_ptr_and_size (&srcr, src, len); if (!refs_may_alias_p_1 (&destr, &srcr, false)) { tree fn; fn =3D builtin_decl_implicit (BUILT_IN_MEMCPY); if (!fn) return false; but the issue is that test2 escapes which makes this conflict: # PT =3D null { D.2775 } (escaped, escaped heap) # ALIGN =3D 8, MISALIGN =3D 0 # USE =3D nonlocal escaped # CLB =3D nonlocal escaped test2_4 =3D __builtin_malloc (1000); # PT =3D nonlocal escaped null test.0_1 =3D test; __builtin_memmove (test2_4, test.0_1, 1000); it works for char *test, *test3; void copy_test () { char *test2 =3D __builtin_malloc (1000); __builtin_memmove (test2, test, 1000); __builtin_memmove (test3, test2, 1000); __builtin_free (test2); } where both memmove calls become memcpy. So this isn't asking for better folding but for better pointer analysis I guess.=