From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BA0DB3853566; Fri, 12 May 2023 06:25:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA0DB3853566 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683872746; bh=QC4T6iueQRz3kjXAa14VS1r8YytXqUPZvbbWU0Jk9ms=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JgvNrnRRnX7xd7o7n0KqokPEj0kuQ1GYFRSfNRyL2HGSpXmYsrqAk+l+01eeeFbmT Z9Psyw/7Raic9yQJtOVkmQEs7IUrRBBYWdy7VAkYLp5Bpkd31zMFcWcyBgjCBxTvSm 5nNuDfESvWxDJe1TA8X7c3lAVhTT0JzWnfYBnpAU= From: "guojiufu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108757] We do not simplify (a - (N*M)) / N + M -> a / N Date: Fri, 12 May 2023 06:25:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: guojiufu 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: 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=3D108757 --- Comment #23 from Jiu Fu Guo --- /* Simplify ((t + -N*M) / N + M) -> t / N: (t + -C) >> N + (C>>N) =3D=3D> t= >> N */ (for div (trunc_div exact_div) (simplify (plus (rshift (plus @0 INTEGER_CST@1) INTEGER_CST@2) INTEGER_CST@3) (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) && (wi::to_wide (@3) << wi::to_wide (@2)) =3D=3D -wi::to_wide (@1)) (if (TYPE_OVERFLOW_UNDEFINED (type)) (div @0 @2) #if GIMPLE (with { bool overflowed =3D true; value_range vr0; if (get_range_query (cfun)->range_of_expr (vr0, @0) && !vr0.varying_p () && !vr0.undefined_p ()) { wide_int wmin0 =3D vr0.lower_bound (); wide_int wmax0 =3D vr0.upper_bound (); wide_int w1 =3D -wi::to_wide (@1); wi::overflow_type min_ovf, max_ovf; wi::sub (wmin0, w1, TYPE_SIGN (type), &min_ovf); wi::sub (wmax0, w1, TYPE_SIGN (type), &max_ovf); if (min_ovf =3D=3D wi::OVF_NONE && max_ovf =3D=3D wi::OVF_NONE) overflowed =3D false; } } (if (!overflowed) (rshift @0 @2))) #endif )))) Got one match for the case. Checking if it is safe(condition) or how to support other forms: signed type, negative N, non-power2 N, negative M ...=