From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3398A3858C2F; Tue, 12 Dec 2023 10:24:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3398A3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702376675; bh=i7eo92S3GdPfjSNOrJedmQbXO2QStSWu600K4kkJKsw=; h=From:To:Subject:Date:From; b=Hx8Mn6tyQjiAXRFrjXUEfxPj4vaY+VHuc58+eaxRLQSfcjYjkhv6GAHYL3SElAl71 ApJ55bIQDZ91SLeAfKEMF1/+0ZpkvK32VOG6BENdn+xjIA8X/C6u8Q0jmRpnQtaaz+ yuCtmDAc37I8N/a1NAlFyvShzAWC5H9Go3bMii8Y= From: "xxs_chy at outlook dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112982] New: Missing optimization: fold max(b, a + 1) to b when a < b Date: Tue, 12 Dec 2023 10:24:34 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xxs_chy at outlook 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=3D112982 Bug ID: 112982 Summary: Missing optimization: fold max(b, a + 1) to b when a < b Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- Godbolt example: https://godbolt.org/z/nn8hT16Ka long src(long a, long b) { if(a < b){ return max(b, a + 1); }else{ return 0; } } can be folded to: long tgt(long a, long b) { if(a < b){ return b; }else{ return 0; } } Similarly, such pattern can be generalized to `a > b`, `min(b, a + 1)`. Both GCC and LLVM missed such optimization opportunity.=