From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F34213857831; Tue, 5 Jan 2021 09:21:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F34213857831 From: "marxin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98513] [10/11 Regression] Wrong code with -O3 since r10-2804-gbf05a3bbb58b3558 Date: Tue, 05 Jan 2021 09:21:21 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: marxin at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: marxin at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.3 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 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: Tue, 05 Jan 2021 09:21:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98513 --- Comment #4 from Martin Li=C5=A1ka --- One last version: $ cat combined.cc unsigned var; unsigned array[2]; int zero =3D 0, minus_2 =3D -2; const int &max(const int &a, const int &b) { return a > b ? a : b; } void test(int minus_1) { for (unsigned i_0 =3D 0; i_0 < 2; i_0++) { for (int i_1 =3D 0; i_1 < zero; i_1++) for (int i_2 =3D 0; i_2 < 2; i_2++) var =3D max(minus_1, 0); for (int i_3 =3D minus_2 + 2; i_3 < minus_1 + 3; i_3++) array[i_3] =3D zero; } } int main() { test(-1); } Apparently, the unswitching is not responsible for the problem, it triggers= one more loop invariant motion and end with: 175.lim4: [local count: 29489562]: _26 =3D (unsigned int) pretmp_1; array[_8] =3D _26; if (_3 >=3D i_3_14) goto ; [66.67%] else goto ; [33.33%] [local count: 19660691]: array[i_3_14] =3D _26; i_3_21 =3D i_3_14 + 1; goto ; [100.00%] while without the option we have: [local count: 29489562]: _26 =3D (unsigned int) pretmp_1; array[_8] =3D _26; i_3_11 =3D _8 + 1; if (_3 >=3D i_3_11) goto ; [66.67%] else goto ; [33.33%] [local count: 19660691]: array[i_3_11] =3D _26; i_3_21 =3D i_3_11 + 1; Anyway I think the problem happens in 189.dom3 where we replace: Optimizing statement array[i_3_14] =3D _26; Replaced 'i_3_14' with constant '-2147483648' which is bogus (the replace is about the second iteration of the loop i_3). Can please somebody familiar with VRP explain the transformation: Visiting controlling predicate if (_3 >=3D i_3_14) Adding assert for _3 from _3 >=3D i_3_14 Adding assert for i_3_14 from i_3_14 <=3D _3 Intersecting int [i_3_14, +INF] EQUIVALENCES: { _3 } (1 elements) and int [minus_1_29(D) + 2, minus_1_29(D) + 2] to int [i_3_14, +INF] EQUIVALENCES: { _3 } (1 elements) Intersecting int [-INF, minus_1_29(D) + 2] EQUIVALENCES: { i_3_14 } (1 elements) and int ~[-2147483647, -2147483646] to int [-INF, -INF] EQUIVALENCES: { i_3_14 } (1 elements) Intersecting int [minus_1_29(D) + 2, minus_1_29(D) + 2] and int [i_3_14, +INF] to int [minus_1_29(D) + 2, minus_1_29(D) + 2] Intersecting int ~[-2147483647, -2147483646] and int [-INF, -INF] to int [-INF, -INF] pushing new range for i_3_14: int [-INF, -INF] EQUIVALENCES: { i_3_14 } (1 elements) 1>>> STMT 1 =3D _3 ge_expr i_3_14 1>>> STMT 0 =3D _3 lt_expr i_3_14 Optimizing statement array[i_3_14] =3D _26; Replaced 'i_3_14' with constant '-2147483648'=