From patchwork Tue Sep 28 09:12:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 45494 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 DFF353858433 for ; Tue, 28 Sep 2021 09:13:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFF353858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632820394; bh=vcujaLgxRBMCF4+SBMip7a8s01HsJ6NsMqXlse3/W2A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YnCPRZqYv8KaF3sZ/XLyDN8W74ckpVqYKFxouDDCwSNSaZMTrX9jbPXLGjiLRuUpg 0cES61vnOkj2QLj77lmPpPdBPx/7bKtb0WJuFfyoBjdiyOflI1tKhxojfwU3+jTpiP qMwriSbbdhM1gv0rVqHqWl2f/JX/728/Iubdn5P8= 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 ESMTP id 73D7A385840B for ; Tue, 28 Sep 2021 09:12:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73D7A385840B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-346-g91kHCJ8OZ2z8q7TgWYD3A-1; Tue, 28 Sep 2021 05:12:17 -0400 X-MC-Unique: g91kHCJ8OZ2z8q7TgWYD3A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 785D8835DEE for ; Tue, 28 Sep 2021 09:12:16 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57ACD19D9D; Tue, 28 Sep 2021 09:12:13 +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 18S9CA3J867945 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Sep 2021 11:12:10 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 18S9C9KH867944; Tue, 28 Sep 2021 11:12:09 +0200 To: GCC patches Subject: [COMMITTED] Return VARYING in range_on_path_entry if nothing found. Date: Tue, 28 Sep 2021 11:12:01 +0200 Message-Id: <20210928091200.867893-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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 Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The problem here is that the solver's code solving unknown SSAs on entry to a path was returning UNDEFINED if there were no incoming edges to the start of the path that were not the function entry block. This caused a cascade of pain down stream. Tested on x86-64 Linux. PR tree-optimization/102511 gcc/ChangeLog: * gimple-range-path.cc (path_range_query::range_on_path_entry): Return VARYING when nothing found. gcc/testsuite/ChangeLog: * gcc.dg/pr102511.c: New test. * gcc.dg/tree-ssa/ssa-dom-thread-14.c: Adjust. --- gcc/gimple-range-path.cc | 11 +++++++++- gcc/testsuite/gcc.dg/pr102511.c | 21 +++++++++++++++++++ .../gcc.dg/tree-ssa/ssa-dom-thread-14.c | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr102511.c diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 71e04e4deba..9da67d2a35b 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -136,14 +136,23 @@ path_range_query::range_on_path_entry (irange &r, tree name) { int_range_max tmp; basic_block entry = entry_bb (); + bool changed = false; + r.set_undefined (); for (unsigned i = 0; i < EDGE_COUNT (entry->preds); ++i) { edge e = EDGE_PRED (entry, i); if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun) && m_ranger.range_on_edge (tmp, e, name)) - r.union_ (tmp); + { + r.union_ (tmp); + changed = true; + } } + + // Make sure we don't return UNDEFINED by mistake. + if (!changed) + r.set_varying (TREE_TYPE (name)); } // Return the range of NAME at the end of the path being analyzed. diff --git a/gcc/testsuite/gcc.dg/pr102511.c b/gcc/testsuite/gcc.dg/pr102511.c new file mode 100644 index 00000000000..8a9af347305 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102511.c @@ -0,0 +1,21 @@ +// { dg-do run } +// { dg-options "-O3" } + +char arr_15 [8]; +__attribute__((noipa)) +void test(signed char a, unsigned short b, unsigned long long c, + unsigned short f) { + for (int d = b - 8; d < b; d += 2) + for (short e = 0; e < (unsigned short)((f ? 122 : 0) ^ (a ? c : 0)) - 64055; + e += 3) + arr_15[d] = 42; +} +int main() { + test(37, 8, 12325048486467861044ULL, 45936); + for (int i = 0; i < 8; ++i) + { + if (arr_15[i] != ((i&1) ? 0 : 42)) + __builtin_abort(); + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c index 3bc4b3795cb..a25fe8bd89e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-14.c @@ -37,5 +37,5 @@ expand_shift_1 (int code, int unsignedp, int rotate, we will enter the TRUE arm of the conditional and we can thread the test to compute the first first argument of the expand_binop call if we look backwards through the boolean logicals. */ -/* { dg-final { scan-tree-dump-times "Threaded" 1 "dom2"} } */ +/* { dg-final { scan-tree-dump-times "Threaded" 2 "dom2"} } */