From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 29336385780D; Wed, 24 Mar 2021 23:36:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29336385780D From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99755] New: failure to fold a conditional that's a subset of another expression Date: Wed, 24 Mar 2021 23:36:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Wed, 24 Mar 2021 23:36:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99755 Bug ID: 99755 Summary: failure to fold a conditional that's a subset of another expression Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC successfully folds to false the second conditional expression in f1() b= ut it fails to do the same in f2() and f3(). In addition (and likely as a result), it triggers a bogus -Wmaybe-uninitialized in both functions.=20 Clang and ICC fold all three expressions to false and emit optimal code for= all three functions. Initializing the local variable to any value lets GCC fold the conditional = and avoid the warning. But then, replacing the test for x !=3D i + 1 in f3() = with x !=3D 3 as shown at below the first test case, the conditional is again not = folded (making the same change in f2() allows the folding to take place). The bogus -Wmaybe-uninitialized first appeared in 4.9. As far as I can tell none of the failures to fold is a regression. $ cat t.c && gcc -O2 -S -Wall t.c void f1 (int i) {=20 int x; if (i > 1) x =3D i + 1; if (i =3D=3D 2 && x !=3D i + 1) // folded to false __builtin_abort (); } void f2 (int i, int j) {=20 int x; if (i > 1 && j > 2) x =3D i + 1; if (i =3D=3D 2 && j =3D=3D 3 && x !=3D i + 1) // not folded __builtin_abort (); } void f3 (int i, int j, int k) { int x; if (i > 1 && j > 2 && k > 3) x =3D i + 1; if (i =3D=3D 2 && j =3D=3D 3 && k =3D=3D 4 && x !=3D i + 1) // not fold= ed __builtin_abort (); } ;; Function f1 (f1, funcdef_no=3D0, decl_uid=3D1943, cgraph_uid=3D1, symbol= _order=3D0) void f1 (int i) { [local count: 1073741824]: return; } t.c: In function =E2=80=98f2=E2=80=99: t.c:17:24: warning: =E2=80=98x=E2=80=99 may be used uninitialized in this f= unction [-Wmaybe-uninitialized] 17 | if (i =3D=3D 2 && j =3D=3D 3 && x !=3D i + 1) | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ t.c: In function =E2=80=98f3=E2=80=99: t.c:28:34: warning: =E2=80=98x=E2=80=99 may be used uninitialized in this f= unction [-Wmaybe-uninitialized] 28 | if (i =3D=3D 2 && j =3D=3D 3 && k =3D=3D 4 && x !=3D i + 1) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ The following is also not folded: void f3 (int i, int j, int k) {=20 int x =3D 0; if (i > 1 && j > 2 && k > 3) x =3D i + 1; if (i =3D=3D 2 && j =3D=3D 3 && k =3D=3D 4 && x !=3D 3) // not folded __builtin_abort (); }=