From patchwork Tue Oct 1 08:18:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1991350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OlqAeo5N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHrS64NQQz1xtg for ; Tue, 1 Oct 2024 18:18:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58C9D3845BC1 for ; Tue, 1 Oct 2024 08:18:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 0024338650D5 for ; Tue, 1 Oct 2024 08:18:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0024338650D5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0024338650D5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727770694; cv=none; b=XOwyAEMW+0dXIpWTg8h1jFGbsxREve3vK87LXGDU9azFelR62FJ6pnur8Z5P0mlTU5a/6SjQJpVWpQNaK0uKeXJyfppy1iUY4RGl3oqPFnO4w70jPkYzhVaxO658D86ot68OKTFSC+Xfl3egM/pqGwtF8Nk6WnGgCf+qgS4SfTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727770694; c=relaxed/simple; bh=pyTzBTtOrxRLSWgeXfk74bNAc865HgeAM3AdvNZlUQ8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=DYAAaK987coBDVfBAaq6lbpaVv8IOO7+TMvkubis4TtNq9EUh/1XMF9jkDxe+mveh+EdtutEyFNUqX9gsTXNnrZ8rSmq16iyY63s2lh6joor7g8apUb5c/8du0CsUlO/D2af3GNlcDRG7Qy2U5L5HOHv3BnfOaOnTe7LbTkn5A4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727770691; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=zT+7l0KlleL6jpHo/ZmxozvOxm8n1gcWCHKQzLR3b4g=; b=OlqAeo5NywHEJ6088WNRMWFgKsNyPlSC8i0kUVOWbVit709JQCj6B5A5ZCeQs5KP8atasm ZY5yU15NX1smkKFwsCsc8Zj9/zHeEughUPJN1fyIbVQz1XmEZjaBjeXeG38qcZEHvHp7LA Z0jmRncgT49eUgYOcZtFxKV302ZzOvg= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-o0jU5x07PDqe-6UFNza0DQ-1; Tue, 01 Oct 2024 04:18:10 -0400 X-MC-Unique: o0jU5x07PDqe-6UFNza0DQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52B671955E75 for ; Tue, 1 Oct 2024 08:18:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.61]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8B9B195421D; Tue, 1 Oct 2024 08:18:08 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 4918I5WY3495544 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 1 Oct 2024 10:18:06 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4918I5hw3495543; Tue, 1 Oct 2024 10:18:05 +0200 Date: Tue, 1 Oct 2024 10:18:05 +0200 From: Jakub Jelinek To: Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [committed] range-cache: Fix ranger ICE if number of bbs increases [PR116899] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! Ranger cache during initialization reserves number of basic block slots in the m_workback vector (in an inefficient way by doing create (0) and safe_grow_cleared (n) and truncate (0) rather than say create (n) or reserve (n) after create). The problem is that some passes split bbs and/or create new basic blocks and so when one is unlucky, the quick_push into that vector can ICE. The following patch replaces those 4 quick_push calls with safe_push. I've also gathered some statistics from compiling 63 gcc sources (picked those that dependent on gimple-range-cache.h just because I had to rebuild them once for the instrumentation), and that showed that in 81% of cases nothing has been pushed into the vector at all (and note, not everything was small, there were even cases with 10000+ basic blocks), another 18.5% of cases had just 1-4 elements in the vector at most, 0.08% had 5-8 and 19 out of 305386 cases had at most 9-11 elements, nothing more. So, IMHO reserving number of basic block in the vector is a waste of compile time memory and with the safe_push calls, the patch just initializes the vector to vNULL. Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved in the PR by Andrew, committed to trunk. 2024-10-01 Jakub Jelinek PR middle-end/116899 * gimple-range-cache.cc (ranger_cache::ranger_cache): Set m_workback to vNULL instead of creating it, growing and then truncating. (ranger_cache::fill_block_cache): Use safe_push rather than quick_push on m_workback. (ranger_cache::range_from_dom): Likewise. * gcc.dg/bitint-111.c: New test. Jakub --- gcc/gimple-range-cache.cc.jj 2024-09-30 18:50:52.314056272 +0200 +++ gcc/gimple-range-cache.cc 2024-09-30 19:33:22.160685645 +0200 @@ -997,9 +997,7 @@ update_list::pop () ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) { - m_workback.create (0); - m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun)); - m_workback.truncate (0); + m_workback = vNULL; m_temporal = new temporal_cache; // If DOM info is available, spawn an oracle as well. @@ -1560,7 +1558,7 @@ ranger_cache::fill_block_cache (tree nam // Visit each block back to the DEF. Initialize each one to UNDEFINED. // m_visited at the end will contain all the blocks that we needed to set // the range_on_entry cache for. - m_workback.quick_push (bb); + m_workback.safe_push (bb); undefined.set_undefined (); m_on_entry.set_bb_range (name, bb, undefined); gcc_checking_assert (m_update->empty_p ()); @@ -1634,7 +1632,7 @@ ranger_cache::fill_block_cache (tree nam // the list. gcc_checking_assert (!m_on_entry.bb_range_p (name, pred)); m_on_entry.set_bb_range (name, pred, undefined); - m_workback.quick_push (pred); + m_workback.safe_push (pred); } } @@ -1729,7 +1727,7 @@ ranger_cache::range_from_dom (vrange &r, // This block has an outgoing range. if (gori ().has_edge_range_p (name, bb)) - m_workback.quick_push (prev_bb); + m_workback.safe_push (prev_bb); else { // Normally join blocks don't carry any new range information on @@ -1753,7 +1751,7 @@ ranger_cache::range_from_dom (vrange &r, break; } if (all_dom) - m_workback.quick_push (prev_bb); + m_workback.safe_push (prev_bb); } } --- gcc/testsuite/gcc.dg/bitint-111.c.jj 2024-09-30 19:36:11.997330014 +0200 +++ gcc/testsuite/gcc.dg/bitint-111.c 2024-09-30 19:37:02.085635292 +0200 @@ -0,0 +1,16 @@ +/* PR middle-end/116899 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-O2" } */ + +float f; +_BitInt(255) b; + +void +foo (signed char c) +{ + for (;;) + { + c %= (unsigned _BitInt(512)) 0; /* { dg-warning "division by zero" } */ + f /= b >= c; + } +}