From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 352F83858426; Fri, 12 May 2023 01:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 352F83858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683856353; bh=G0lsrqD5K2bM/+M2d0EVfkM9rt2I830Qb2EVDCGYmTo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C1MJxV6Ckxcy4Iup1IpM227GO9XVj40jtddO/7imWMiSiVTif4eDzJIhxnVCluomI B4Nbqsm4eDDm/cJOaChP905jTdpcD9qTZ0EHS+6fBi+OyW6s51zPdXuxqE8OllnLnz C7c1Dwr59rEEOX/1r72TGz7QY+lgljMZR+JuMlPg= 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 01:52:32 +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 #22 from Jiu Fu Guo --- (In reply to Andrew Pinski from comment #21) > (In reply to Jiu Fu Guo from comment #20) > > Interesting thing: > > the VR is always VR_VARYING, even for the below simple case: > >=20 > > typedef unsigned long INT; > > INT __attribute__ ((noinline)) foo (INT x) > > { > > if (x < 4) > > return 0; > > INT a =3D x + 18446744073709551612ULL; > > INT b =3D a >> 2; > > return b + 1; > > } >=20 > Yes that is because x does not have a "global" range. I also tried "get_range_query (cfun)->range_of_expr (vr0, @0)",=20 >=20 > You could try the following testcase: > ``` > typedef unsigned long INT; > INT __attribute__ ((noinline)) foo (INT x) > { > if (x < 4) > __builtin_unreachable(); > INT a =3D x + 18446744073709551612ULL; > INT b =3D a >> 2; > return b + 1; > } > ``` >=20 > Which gets a (global) range for x_1(D) during forwprop3: > # RANGE [irange] INT [4, +INF] > INTD.2750 x_1(D) =3D xD.2751; (In reply to Andrew Pinski from comment #21) > (In reply to Jiu Fu Guo from comment #20) > > Interesting thing: > > the VR is always VR_VARYING, even for the below simple case: > >=20 > > typedef unsigned long INT; > > INT __attribute__ ((noinline)) foo (INT x) > > { > > if (x < 4) > > return 0; > > INT a =3D x + 18446744073709551612ULL; > > INT b =3D a >> 2; > > return b + 1; > > } >=20 > Yes that is because x does not have a "global" range. >=20 > You could try the following testcase: > ``` > typedef unsigned long INT; > INT __attribute__ ((noinline)) foo (INT x) > { > if (x < 4) > __builtin_unreachable(); > INT a =3D x + 18446744073709551612ULL; > INT b =3D a >> 2; > return b + 1; > } > ``` >=20 > Which gets a (global) range for x_1(D) during forwprop3: > # RANGE [irange] INT [4, +INF] > INTD.2750 x_1(D) =3D xD.2751; Thanks so much! "get_range_query (cfun)->range_of_expr (vr0, @0)" works for both the case!=