From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7D0963858C54; Wed, 26 Apr 2023 21:00:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D0963858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682542831; bh=kDtw+N7Mb+wW94JdkJA3j6bbqwtoyMTWjzaE+FgLul4=; h=From:To:Subject:Date:From; b=yUQl4ij+l+1LJY2TGYAsCctjADJ1ZDBh03aPFzaHkBkG89fzmTt1Z7eX+DrGfe2wi wFcgbPzx2mQY6okENp2Eu2Q+TTJYdDReXFhTKp5WToGAN3P1BBVmrjLvWLlFz8StX+ VyLCNJMj2BHsys3fXR0KHmB/kcfx2gxK7K1bXj+Q= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109638] New: unsigned > 1 ? 0 : n is not optimized to n == 1 Date: Wed, 26 Apr 2023 21:00: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: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement 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=3D109638 Bug ID: 109638 Summary: unsigned > 1 ? 0 : n is not optimized to n =3D=3D 1 Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` unsigned test_cst (unsigned n) { if (n > 1) n =3D 0; return n; } unsigned test_cst1 (unsigned n) { return (n =3D=3D 1); } ``` For gimple at least the second one is smaller. I suspect for x86 the second version is also faster because it uses sete rather than cmov. But these 2 functions should produce the same code. I found this on accident while looking at gcc.dg/tree-ssa/builtin-snprintf-= 2.c=20 testcase. This can only be done for 1 too.=