From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1389F389851F; Thu, 30 Apr 2020 17:25:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1389F389851F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588267504; bh=nCZkNXJPBPbKqSPrc72bkVmugUyEy7DBtxRC3OMSdLU=; h=From:To:Subject:Date:From; b=aJtUyjs5O82GHQ+/0NfUIX9NBO/AH1Y8j51Z2w7983i/qW1Rv1nOfiy3io1iP3DDe JIYARyHJXv3Pdg7lT3PfShWYnO9o2nb2xAIrSpIbbo13Cz2hqKt6NdNwhRyD+5OVey FWHIiHi2PVrCgKRz8xAd1VMnaJWXcA6XMgZMOrpc= From: "gabravier at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94892] New: (x >> 31) + 1 not getting narrowed to compare Date: Thu, 30 Apr 2020 17:25:03 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gabravier 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 17:25:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94892 Bug ID: 94892 Summary: (x >> 31) + 1 not getting narrowed to compare Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- inline int sign(int x) { return (x >> 31) | ((unsigned)-x >> 31); } bool f(int x) { return sign(x) > -1; } With -O3, LLVM produces this : f(int): test edi, edi setns al ret GCC produces this : f(int): sar edi, 31 lea eax, [rdi+1] ret Changing `f` to `(x >> 31) + 1` results in it being optimized optimally=