From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D2FAE3858D28; Fri, 22 Mar 2024 05:44:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2FAE3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711086270; bh=g3B7ZQOOljI5sMLiYtzNd3tj25VaiyCeNdITYD5wlX8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EpDCsjurmXBS2i3prIOCzpYu658le/a3lKhYFDysVTAEkzfVhRPhOGjA5xrMhmLPx N1l+YmeyVM3+XQ8v0KBPQfz89u77O+kk1wK+0FMuHHaU4io4NFUvxFdJiD4J4x5PCh 7EWK3HURjkwBxdS1n9TWtfSzf+YSUVCYrk9MrcLQ= From: "liuhongt at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/114429] [x86] (neg a) ashifrt>> 31 can be optimized to a > 0. Date: Fri, 22 Mar 2024 05:44:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: liuhongt 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: cf_gcctarget Message-ID: In-Reply-To: References: 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=3D114429 Hongtao Liu changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |x86_64-*-* i?86-*-* --- Comment #1 from Hongtao Liu --- when x is INT_MIN, I assume -x is UD, so compiler can do anything. otherwise, (-x) >> 31 is just x > 0. >From rtl view. neg of INT_MIN is assumed to 0 after it's truncated. (neg:m x) (ss_neg:m x) (us_neg:m x) These two expressions represent the negation (subtraction from zero) of the value represented by x, carried out in mode m. They differ in the behavior = on overflow of integer modes. In the case of neg, the negation of the operand = may be a number not representable in mode m, in which case it is truncated to m. ss_neg and us_neg ensure that an out-of-bounds result saturates to the maxi= mum or minimum signed or unsigned value. so we can optimize (neg a)>>31 to a>0.=