From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id A9DA63857735; Fri, 8 Dec 2023 08:01:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9DA63857735 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702022466; bh=GmnDcdUgwu5LghfJMd+SeIpP3GeLWoS8iW34qir69k4=; h=From:To:Subject:Date:From; b=CvGH+QCkYjtXnIB4bapD8o71nEmrvcEXP6+yQTjh3wUKN3q0rIi6a27e4Ixzuo8i1 YSKDawzMvcdMxPqnQUqP9LtXFVY3yhHr8OVjlb8DRJSUY0idYUkl3gu4uDyCqROco8 5BbShWikw7I1Dury1fTt/io2/bhfGqFwe4fInww4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-6305] haifa-sched: Avoid overflows in extend_h_i_d [PR112411] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: f6cc6eb5b6c7833385f66dbc878e8f6ec1ebdb8f X-Git-Newrev: 8f60f5499e10d19218cada082e0909516ebf0e74 Message-Id: <20231208080106.A9DA63857735@sourceware.org> Date: Fri, 8 Dec 2023 08:01:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8f60f5499e10d19218cada082e0909516ebf0e74 commit r14-6305-g8f60f5499e10d19218cada082e0909516ebf0e74 Author: Jakub Jelinek Date: Fri Dec 8 08:56:33 2023 +0100 haifa-sched: Avoid overflows in extend_h_i_d [PR112411] On Thu, Dec 07, 2023 at 09:36:23AM +0100, Jakub Jelinek wrote: > Without the dg-skip-if I got on 64-bit host with > -O3 --param min-nondebug-insn-uid=0x40000000: > cc1: out of memory allocating 571230784744 bytes after a total of 2772992 bytes I've looked at this and the problem is in haifa-sched.cc: 9047 h_i_d.safe_grow_cleared (3 * get_max_uid () / 2, true); get_max_uid () is 0x4000024d with the --param min-nondebug-insn-uid=0x40000000 and so 3 * get_max_uid () / 2 actually overflows to -536870028 but as vec.h then treats the value as unsigned, it attempts to allocate 0xe0000374U * 152UL bytes, i.e. those 532GB. If the above is fixed to do 3U * get_max_uid () / 2 instead, it will get slightly better and will only need 0x60000373U * 152UL bytes, i.e. 228GB. Perhaps more could be helped by making the vector indirect (contain pointers to haifa_insn_data_def rather than the structures themselves) and pool allocate those, but the more important question is how sparse are uids in normal compilations without those large --param min-nondebug-insn-uid= parameters. Because if they aren't enough, such a change would increase compile time memory just to help the unusual case. 2023-12-08 Jakub Jelinek PR middle-end/112411 * haifa-sched.cc (extend_h_i_d): Use 3U instead of 3 in 3 * get_max_uid () / 2 calculation. Diff: --- gcc/haifa-sched.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc index 8e8add709b3..35c2c9f2bdc 100644 --- a/gcc/haifa-sched.cc +++ b/gcc/haifa-sched.cc @@ -9044,7 +9044,7 @@ extend_h_i_d (void) if (reserve > 0 && ! h_i_d.space (reserve)) { - h_i_d.safe_grow_cleared (3 * get_max_uid () / 2, true); + h_i_d.safe_grow_cleared (3U * get_max_uid () / 2, true); sched_extend_target (); } }