From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9351C3858012; Thu, 29 Oct 2020 02:02:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9351C3858012 From: "wsnyder at wsnyder dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97623] New: Extremely slow O2 compile (>>O(n^2)) Date: Thu, 29 Oct 2020 02:02:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wsnyder at wsnyder dot org X-Bugzilla-Status: UNCONFIRMED 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_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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: Thu, 29 Oct 2020 02:02:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97623 Bug ID: 97623 Summary: Extremely slow O2 compile (>>O(n^2)) Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wsnyder at wsnyder dot org Target Milestone: --- Created attachment 49461 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49461&action=3Dedit slow.cpp The attached program compiles very slowly with -O2. It is fast with clang (FWIW). This is an shortened version of a routine taking > 10 minutes. $ gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 time g++ -O2 -c slow.cpp 6.457 (average) time g++ -Os -c slow.cpp 0.236 (average) time g++ -O2 -DNO_BOTTOM -c slow.cpp 0.560 (average) time g++ -O2 -DNO_TOP -c slow.cpp 0.702 (average) time g++ -O2 -DNO_FINAL -c slow.cpp 6.271 (average) time clang++ -O2 -c slow.cpp 0.210 (average) Note Os is much faster. The defines remove the top half of the function, or bottom half, note the time is crazy faster, one would expect the whole prog= ram to be only slightly slower than the sum of these. Removing a single statem= ent from the bottom (-DNO_FINAL) also makes an enormous 0.21 second difference,= so some algorithm is not scaling correctly. Would greatly appreciate some indication of 1. a compiler flag to bypass the bad optimization if possible, and 2. a hint as to what operator or how to a= void this as this is generated code so there's some flexibility for a workaround. Thanks.=