From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F7173875DC4; Thu, 27 Jun 2024 04:58:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F7173875DC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1719464329; bh=LRTcTPcnWD2z9R0a1Kx5F/4J791EAYtKUpKHqxoLjM0=; h=From:To:Subject:Date:From; b=ej/qZwi84zMUj5b0uyl2rQfO8z9xQIb+A7cgygfFMSbPbZI4QdnWD6d40P1JxjCzI u6vgHhx0P32C56fYvjk6snAQ4ww/d+IH/uMkcMK/N0mcyzS/zrOzF9B0gwsGl7/cfG kEB7C76+pFotdWrSkw0Nm2lbAYWZSI/lEKAvwdFA= From: "Explorer09 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/115674] New: "Checking if number is within interval" missed optimization when number is from a smaller int type Date: Thu, 27 Jun 2024 04:58:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 14.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Explorer09 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=3D115674 Bug ID: 115674 Summary: "Checking if number is within interval" missed optimization when number is from a smaller int type Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: Explorer09 at gmail dot com Target Milestone: --- ```c #include #include bool func1(uint8_t x) { uint32_t value; value =3D x; if (value < 0xC2 || value > 0xF4) { return false; } return true; } bool func2(uint8_t x) { uint32_t value; value =3D x; if ((uint8_t)value < 0xC2 || (uint8_t)value > 0xF4) { return false; } return true; } ``` x86_64 gcc with -Os option produces: ```x86asm func1: movzx edi, dil sub edi, 194 cmp edi, 50 setbe al ret func2: add edi, 62 cmp dil, 50 setbe al ret ``` For x86-64, the expected result is func1 transformed to func2. For ARM and RISC-V targets, I expect the other way around, that is, transfo= rm func2 to func1, so that it saves a "bitwise AND 0xFF" operation.=