From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 971143858417; Mon, 25 Dec 2023 12:35:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 971143858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703507747; bh=j+Zqp17Rn2jTR1aDZI2j7GOiIRhI1mU//xL23yMUFd8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ywpY/Ao8MQ21wCTr4aE+ilEXkQlIx+3fc7aVFPPbjnMb4sh3llFRCWYnrQgHK9E37 xbSgV1PdQ+CagACUJfcPsmfXEfrYvTA7neJyzZr8jVusroyfj3s8PP5boghBNOI+u2 /eXRICWJ2mWX2rAHgH+0llVAs8NNGfQwkFjz/Ak8= From: "tnfchris at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/113134] Middle end early break vectorization: Fail to vectorize a simple early break code Date: Mon, 25 Dec 2023 12:35:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: tnfchris at gcc dot gnu.org 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: cf_reconfirmed_on keywords 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=3D113134 Tamar Christina changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-12-25 Keywords| |missed-optimization --- Comment #1 from Tamar Christina --- Yeah, the patch wasn't intended to handle that case. As the patch says it requires the sizes of the memories being accessed to be constant. i.e. https://compiler-explorer.com/z/87d61h3x5 works and that alr= eady works today. my patch would allow this if we relax vect_analyze_early_break_dependences = to not worry about memory accesses if the condition itself does not access mem= ory. However I don't think this should get to my patch at all. this loop void add(int N, int *__restrict a, int *__restrict b, int *__restrict c) { for (int i =3D 0; i < N; i++) { c[i] =3D a[i] + b[i]; if (i > 1000) { break; } } } is essentially void add2(int N, int *__restrict a, int *__restrict b, int *__restrict c) { for (int i =3D 0; i < 1001; i++) { c[i] =3D a[i] + b[i]; } } and is what clang has rewritten it to. GCC does the same in ivcanon but then doesn't realize the additional exit is unreachable and should be removed. So this case needs to be handled before= it reaches the vectorizer.=