From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8D6623858D3C; Sun, 27 Nov 2022 19:28:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D6623858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669577334; bh=/6lGaAEpD9FeZ3eyMiCbcJAU/4wI/myZLucHKWyMyVk=; h=From:To:Subject:Date:From; b=wr6RjcX6vl5nTNDVwQq2aBHHp/R9c/bw/WHH2frozMbWB161JiwwjRLkLN0fhL+qF W7AGf3i/wvonU4d0FqFeCBvUqVAfQtagJqKVzeb/Ii4p+UU/x6wwevTsl521lECzF3 R3mXDfW3IdiNFU/BRBmHzeb/e83HBprTdZmUMX0E= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107888] New: [12/13 Regression] Missed min/max transformation in phiopt due to VRP Date: Sun, 27 Nov 2022 19:28:54 +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: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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 keywords 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107888 Bug ID: 107888 Summary: [12/13 Regression] Missed min/max transformation in phiopt due to VRP Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` #define bool _Bool int maxbool(bool ab, bool bb) { int a =3D ab; int b =3D bb; int c; if (a > b) c =3D a; else c =3D b; return c; } ``` We miss that c is max of a and b because VRP decides to change the phi. We get out of VRP: ``` if (a_3 > b_5) goto ; [INV] else goto ; [INV] : : # c_1 =3D PHI <1(2), b_5(3)> ``` What VRP is doing is correct just is harder to optimize to a max (and then = a | ). In the above case we could optimize `bool0 ? 1 : bool1` to `bool0 | bool1` = But then we end up with PR 107887 too. You can also end up with the above issue where you know the only overlap between the two arguments is [5,6] : ``` int max(int ab, int bb) { if (ab < 5) __builtin_trap(); if (bb > 6) __builtin_trap(); int a =3D ab; int b =3D bb; int c; if (a >=3D b) c =3D a; else c =3D b; return c; } ``` Which we cannot optimize based on zero/one any more. (note this version of = max has been an issue since at least GCC 4.1, I suspect since VRP was added).=