From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 782533861823; Fri, 15 Dec 2023 10:20:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 782533861823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702635604; bh=q355lQo4ike6I80NywxwFPOqYExAm6kb0Mw7LhnV9Vs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nnMZlo4gzhYsqba69dYPg7DnuVRKM2MuXUeAVZk6eFHhynbbAkfadceLdTg8HwDnW JIdfP0sAQyFgOs6Bolwj5L7Eh4FS6HAqqQShcb7QGrHey+IdssoMuRagRWXr+0tpCv VFFmH8P8wcqsTgFn5hNb6xQOIofIQICfPmzhzYro= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113026] Bogus -Wstringop-overflow warning on simple memcpy type loop Date: Fri, 15 Dec 2023 10:20:03 +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: 14.0 X-Bugzilla-Keywords: diagnostic, missed-optimization 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: 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=3D113026 --- Comment #3 from Richard Biener --- I do have a patch to avoid the epilog, but that doesn't help when adjusting= the testcase to char dst[17]; void foo (char *src, long n) { for (long i =3D 0; i < n; i++) dst[i] =3D src[i]; } because then we still fail to constrain the epilog number of iterations (the different cases of flow are now quite complicated, the pending early exit vectorization patches will complicate it more). I'll see what to do _after_ that work got in. The following helps the dst[16] case, ideally we'd refactor that a bit according to the comment. diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 7a3db5f098b..a4dd2caa400 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -1260,7 +1260,11 @@ vect_need_peeling_or_partial_vectors_p (loop_vec_info loop_vinfo) the epilogue is unnecessary. */ && (!LOOP_REQUIRES_VERSIONING (loop_vinfo) || ((unsigned HOST_WIDE_INT) max_niter - > (th / const_vf) * const_vf)))) + /* We'd like to use LOOP_VINFO_VERSIONING_THRESHOLD + but that's only computed later based on our result. + The following is the most conservative approximation. = */ + > (std::max ((unsigned HOST_WIDE_INT) th, + const_vf) / const_vf) * const_vf)))) return true; return false; it's interesting that we don't seem to adjust the upper bound of the niters for the epilog at all. The following cures that as well: diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index bcd90a331f5..07a30b7ee98 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -3193,6 +3193,19 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree nite= rs, tree nitersm1, bb_before_epilog->count =3D single_pred_edge (bb_before_epilog)->count (); bb_before_epilog =3D loop_preheader_edge (epilog)->src; } + else + { + /* When we do not have a loop-around edge to the epilog we know + the vector loop covered at least VF scalar iterations. Update + any known upper bound with this knowledge. */ + if (loop->any_upper_bound) + epilog->nb_iterations_upper_bound -=3D constant_lower_bound (vf= ); + if (loop->any_likely_upper_bound) + epilog->nb_iterations_likely_upper_bound -=3D constant_lower_bo= und (vf); + if (loop->any_estimate) + epilog->nb_iterations_estimate -=3D constant_lower_bound (vf); + } + /* If loop is peeled for non-zero constant times, now niters refers = to orig_niters - prolog_peeling, it won't overflow even the orig_nite= rs overflows. */=