From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 497783858C62; Mon, 28 Nov 2022 20:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 497783858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669666186; bh=+kQBnLudYT7YzE9OyuEUlKDJ1lzCdm72b8y5w4JqTU0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YolxOX7O9PYYvgUcAwq7uvi3bTMz21oeTQLHDaPabCdcAKb+KElnhB3QVgwoDt4id prddAgDzR36e6q0PkBeDz0WCCuw2tYOoyrQC6G9V9FwIU1Y0lzQb81SJnH8RzL5gz4 BwRvzWPCvCnHEeqNfN/64m1IOfQTilnw05r20b3E= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/105119] the division in x / (1 << y) is optimized away when x has unsigned type, but not when it's signed Date: Mon, 28 Nov 2022 20:09:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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_status cf_reconfirmed_on everconfirmed 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=3D105119 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2022-11-28 Ever confirmed|0 |1 --- Comment #2 from Andrew Pinski --- The unsigned case is handled with r8-1550-g71f82be94fad15 . The comment in match.pd is now: /* (A / (1 << B)) -> (A >> B). Only for unsigned A. For signed A, this would not preserve rounding toward zero. For example: (-1 / ( 1 << B)) !=3D -1 >> B. Also also [handle] widening conversions, like: (A / (unsigned long long) (1U << B)) -> (A >> B) or (A / (unsigned long long) (1 << B)) -> (A >> B). If the left shift is signed, it can be done only if the upper bits of A starting from shift's type sign bit are zero, as (unsigned long long) (1 << 31) is -2147483648ULL, not 2147483648ULL, so it is valid only if A >> 31 is zero. */ Confirmed.=