From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 16BDF3882AE3; Wed, 10 Jan 2024 22:12:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16BDF3882AE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704924727; bh=hmvO4/vW0PD5Z14N//2y8swlwG4z6vgzlr5ZD0ekkkU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hdS6he0lLHQ2j31n3A0i1CLbC0hsEzDqTVgoHY07+8knpnJIcSl813uSGryN+FFRx rM73v/2bwk+zDheRwJl2y/SoH+G2U0DcZ0CkV8oVDHQVmVyYj5tk472/elQC21g6+r Rd/ZLI31UpwVA2uspH3qBfxV0Wrq8LP8fskCR5cs= From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113301] [12/13/14 Regression] Missed optimization: (1/(x+1))/2 => 0 since gcc-12 Date: Wed, 10 Jan 2024 22:12:06 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.4 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=3D113301 --- Comment #6 from Andrew Macleod --- (In reply to Andrew Macleod from comment #5) > (In reply to Jakub Jelinek from comment #4) > > Even then, I wonder why ranger doesn't figure this out. > > (x+1u) <=3D 2 ? x : 0 > > must have a range [-1, 1] and [-1, 1] / [2, 2] range should be [0, 0], = no? >=20 > its because there is no branch which is what drives ranger. At this point, > we aren't quite smart enough to completely evaluate the 2 operands of a > conditional as if they were actual branches. > ie > _1 =3D x_4(D) + 1; > _10 =3D (unsigned int) x_4(D); > _6 =3D _10 + 2; > _7 =3D _6 <=3D 2; > _2 =3D _7 ? _1 : 0; >=20 > if that were: > if (_6 <=3D 2) > _2 =3D _1 > we'd recalculate _1 with the condition being (_6 <=3D 2) and we come upwi= th > [-1, 1] for _1 instead of varying. >=20 > I'll have to look at whats involved in enhancing the fold code to invoke > GORI to reevaluate _1 if _7 is [1,1]. in theory is not too difficult...= :-) ah, its more complicated than that. we normally do this evaluation, but the cond_expr is using _1.. if you trace back from _6 in the condition, _1 is n= ot in the dependency chain anywhere, so GORi cannot compute anything for it. = it can compute that x_4 is [-2, 0] but it doesnt see any connection between _= 6 in the condition and _1. the remaining question is whether this can be cheaply identified as a recomputation.. in which case we could recompute _1 usin the [-2, 0] for x_4 and come up with [-1, 1]=20 I'll have a look if we can easily invoke hte recompuation code the edges evaluations use or nor=