From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3625 invoked by alias); 12 Mar 2015 15:09:30 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 3530 invoked by uid 48); 12 Mar 2015 15:09:24 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/44563] GCC uses a lot of RAM when compiling a large numbers of functions Date: Thu, 12 Mar 2015 15:09:00 -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: 4.3.4 X-Bugzilla-Keywords: compile-time-hog, memory-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg01323.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44563 --- Comment #29 from Richard Biener --- Sth like @@ -672,8 +650,18 @@ cleanup_tree_cfg_bb (basic_block bb) if (single_succ_p (bb) && can_merge_blocks_p (bb, single_succ (bb))) { - merge_blocks (bb, single_succ (bb)); - return true; + /* If there is a merge opportunity with the predecessor + do nothing now but wait until we process the predecessor. + This happens when we visit BBs in a non-optimal order and + avoids quadratic behavior with adjusting stmts BB pointer. */ + if (single_pred_p (bb) + && can_merge_blocks_p (single_pred (bb), bb)) + ; + else + { + merge_blocks (bb, single_succ (bb)); + return true; + } } return retval; in addition should do the job. Iteration on the predecessor should cover both merges (so we don't actually need to revisit this block itself).