From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 80765385840E; Mon, 10 Jan 2022 21:12:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80765385840E From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103821] [12 Regression] huge compile time (jump threading) at -O3 for simple code since r12-4790-g4b3a325f07acebf47e82de227ce1d5ba62f5bcae Date: Mon, 10 Jan 2022 21:12:39 +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: 12.0 X-Bugzilla-Keywords: compile-time-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2022 21:12:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103821 --- Comment #3 from Andrew Macleod --- Interesting. This isn't caused by jump threading, just exposed by it. We end up unrolling this loop, and the pattern of code creates a set of cascading multiplies for which we can precisely evaluate them with subrange= s. For instance, we calculate: _38 =3D int [8192, 8192][24576, 24576][40960, 40960][57344, 57344] so _38 has 4 subranges, and then we calculate: _39 =3D _38 * _38; we do 16 multiplications and end up with: int [67108864, 67108864][2013265= 92, 201326592][335544320, 335544320][469762048, 469762048][603979776, 603979776][1006632960, 1006632960][1409286144, 1409286144][1677721600, 1677721600][+INF, +INF] This feeds other multiplies and progresses rapidly to blow up the number of subranges, which are then propagated via PHIs and other operations. Folding of subranges is an O(n*m) process. We perform the operation on each pair of subranges and union them. Values like _38 * _38 that continue fee= ding each other quickly become exponential. Then combining that with union (an inherently linear operation over the num= ber of subranges) at each step of the way adds an additional quadratic operatio= n on top of the exponential factor.=20 I will adjust the wi_fold routine to recognize when the calculation is movi= ng in an exponential direction, simply produce a summary a result instead of a precise one. Longer term, we could consider merging some of the subranges = to prevent the exponential growth, but still retain some precision.=