From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 48D973882052; Thu, 13 Jun 2024 10:47:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48D973882052 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718275652; bh=xFgMf1DiLOt34s/Q1PvGxk3o4xEcV/h3EKOpKdjukXk=; h=From:To:Subject:Date:From; b=Cepxm67naDmzjI3yrdWVVaSgvREZZBLR7H5rxNRorUjmnzTut0bVCsG3q+80a7t4J LTDUEZSFQpCNq7Uhw5hH1j2gpfMnMskS7k4ZOVhZE3ZwGSuRO27QmcQSXKagoRytdK PWLZQzpEWOAvDw7UUZ6qskH24sCT7/uA/FAXGRp8= From: "zhiwuyazhe154 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115474] New: Missed optimization: fold `std::max(a > b, a)` to `a` (bool a, bool b) Date: Thu, 13 Jun 2024 10:47:31 +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: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zhiwuyazhe154 at gmail dot com 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115474 Bug ID: 115474 Summary: Missed optimization: fold `std::max(a > b, a)` to `a` (bool a, bool b) Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zhiwuyazhe154 at gmail dot com Target Milestone: --- godbolt example: https://godbolt.org/z/KG1fhaPvM Code Example: ``` int func(bool a, bool b) { return std::max(a > b, a); // equals to a } ``` In this case, when a =3D=3D 0, a > b =3D=3D 0(a); when a =3D=3D 1, a > b <= =3D 1(a). So it can be folded to a. GCC -O3: func(bool, bool): cmp sil, dil setb dl cmp dl, dil setb al or eax, edx movzx eax, al ret Expected code(CLANG -O3): func(bool, bool):=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20 mov eax, edi ret=