From patchwork Tue Nov 30 15:47:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 48300 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71BB23857835 for ; Tue, 30 Nov 2021 15:48:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71BB23857835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638287300; bh=W3IQ9RgZgbb8k6Ng/+INfKg3lPOemJcCZTYuROsiD+s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WD3gF/YAafBFqZu5ns4fKuTAiyCzBJoLSq8Yxn60n1Od//Fm93RsmbA4j/0LQs08C U+L38EiN8TXmGcZ26m5fPJU/7Ack1HBv962DWVP4Pe3MzrpKveznzNGxtju9zNR40c k/ARKCKPGTNTDgVtvukfvNLnLC7q6ZcRRImyJdko= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 2CB193858D28 for ; Tue, 30 Nov 2021 15:47:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CB193858D28 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-bHlYHI_FNNm_p3PI_g0d8g-1; Tue, 30 Nov 2021 10:47:50 -0500 X-MC-Unique: bHlYHI_FNNm_p3PI_g0d8g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74135100CCC3; Tue, 30 Nov 2021 15:47:49 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4847860C13; Tue, 30 Nov 2021 15:47:42 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 1AUFldYQ231841 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Nov 2021 16:47:40 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1AUFldU4231840; Tue, 30 Nov 2021 16:47:39 +0100 To: Jeff Law Subject: [PATCH] Allow loop crossing paths in back threader copier. Date: Tue, 30 Nov 2021 16:47:32 +0100 Message-Id: <20211130154731.231707-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: Martin Sebor , GCC patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" We are currently restricting loop crossing paths in the generic copier used by the back threader, but we should be able to handle them after loop_done has completed. This fixes the PR at -O2, though the problem remains at -O1 because we have no threaders smart enough to elide the undefined read. DOM3 could be a candidate when it is converted to either a hybrid threader or replaced with the backward threader (when ranger can handle floats). Tested on x86-64 Linux. OK for trunk? PR tree-optimization/80548 gcc/ChangeLog: * attribs.c (sorted_attr_string): Add assert for -Wstringop-overread. * tree-ssa-threadupdate.c (back_jt_path_registry::duplicate_thread_path): Allow paths that cross loops after loop_done. (back_jt_path_registry::update_cfg): Diagnose dropped threads after duplicate_thread_path. gcc/testsuite/ChangeLog: * gcc.dg/pr80548.c: New test. --- gcc/attribs.c | 1 + gcc/testsuite/gcc.dg/pr80548.c | 23 +++++++++++++++++++++++ gcc/tree-ssa-threadupdate.c | 19 +++++++++++-------- 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr80548.c diff --git a/gcc/attribs.c b/gcc/attribs.c index c252f5af07b..9a079b8405a 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -1035,6 +1035,7 @@ sorted_attr_string (tree arglist) attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0'; str_len_sum += len + 1; } + gcc_assert (arglist); /* Replace "=,-" with "_". */ for (i = 0; i < strlen (attr_str); i++) diff --git a/gcc/testsuite/gcc.dg/pr80548.c b/gcc/testsuite/gcc.dg/pr80548.c new file mode 100644 index 00000000000..2327111143e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80548.c @@ -0,0 +1,23 @@ +// { dg-do compile } +// { dg-options "-O2 -Wuninitialized" } + +int g (void); +void h (int, int); + +void f (int b) +{ + int x, y; + + if (b) + { + x = g (); + y = g (); + } + + while (g ()) + if (b) + { + h (x, y); // { dg-bogus "uninit" } + y = g (); + } +} diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 8aac733ac25..b194c11e23d 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -2410,13 +2410,14 @@ back_jt_path_registry::duplicate_thread_path (edge entry, missuses of the functions. I.e. if you ask to copy something weird, it will work, but the state of structures probably will not be correct. */ - for (i = 0; i < n_region; i++) - { - /* We do not handle subloops, i.e. all the blocks must belong to the - same loop. */ - if (region[i]->loop_father != loop) - return false; - } + if (!(cfun->curr_properties & PROP_loop_opts_done)) + for (i = 0; i < n_region; i++) + { + /* We do not handle subloops, i.e. all the blocks must belong to the + same loop. */ + if (region[i]->loop_father != loop) + return false; + } initialize_original_copy_tables (); @@ -2651,9 +2652,11 @@ back_jt_path_registry::update_cfg (bool /*peel_loop_headers*/) visited_starting_edges.add (entry); retval = true; m_num_threaded_edges++; + path->release (); } + else + cancel_thread (path, "Failure in duplicate_thread_path"); - path->release (); m_paths.unordered_remove (0); free (region); }