From patchwork Mon Oct 17 18:56:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 3656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1596355wrs; Mon, 17 Oct 2022 11:58:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Fql5w7PjE9mECbBnzZsqqsNlGvFsuBMICZqpOxpjUCPOIsprgzhUmd8fgc983F7hwBP9F X-Received: by 2002:a17:907:2723:b0:78e:214b:e3c7 with SMTP id d3-20020a170907272300b0078e214be3c7mr9979918ejl.186.1666033102509; Mon, 17 Oct 2022 11:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666033102; cv=none; d=google.com; s=arc-20160816; b=fLpaRm46rgekxDlU+Xu+qb79LNCsIz4QkFzgiR3QgiN9AdcQTYuD0WSJ196cwGaL1u t9LnBQZpmSByQY4oPNYvvAT7vcWYrZ7ecogyehbwohehSs+fT2ckdq+oFv6j5ctnvftK xO5NqTo0oO6D9NbHolPzmmWn+pBayANovcCQR25Wn9KJjHzY9c6RKFeRSZWHSoTEmCrr ZZgylXrTirqXBpxnOA/I9UYsKF65u43nYMRASvKc/vKai+I3LHthysZLIutsAmXagbFq /8GJ2IwfAN1tjoxojSn+9PSm4qJlyHufGqhmdCW2tc7z3AuX6cxctorXOyX924VyTDnC ykGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=TC+O8ImE+FVnqBQbSTAxruTDxmiQHPlUE7rCT4YSufU=; b=h2joyQcA6VYTEdWOSjplqUt2IQL0IojF3JOJyaGWQj3ObY66tE+gBjesSnAtb7ABkk 9OqIyOvUREqilHhLgN3ThroSHgC+sWapVImGtPnKaYfv2DMlFH22AhobRNjyeo2wlic9 QmySJCAjTxFtZ4QaN55CDdGyoE+Zdx8rJ0kjT/WpIBsmpPiMZK5q/puepiShqFEypIEd 2A9+Gs2ZWYEMdQ6RfdRO8EmXYaSlOaIRyOukPiHpirbkKNzCSE3XRFbmPFQNE9cmYL9w 9U3iIkErKLhbr2Yz8QPK3pEQpYX0lrSiGFLryrw3Sp2b56RAGm52jvrfdiEJrNTDw5U9 fPuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eWWlkJCZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f10-20020a50d54a000000b0045c3f6adb7csi9294678edj.215.2022.10.17.11.58.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 11:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eWWlkJCZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8FFF03858293 for ; Mon, 17 Oct 2022 18:58:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FFF03858293 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666033101; bh=TC+O8ImE+FVnqBQbSTAxruTDxmiQHPlUE7rCT4YSufU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eWWlkJCZHW6qgSa/bacCmacrrs+2pfHuGKOrm/NeGq93ie6iR1wsimBIuPv+laFT6 Z04E9PzthPi3GqdwJkBD7JFPdD5U3QIGKhU9QkTRc2msaNt4CiBqjjaTf/RsjRnDDx +qjsVfuiF+fSYxWnSGl+KtJieCC/7vtLdcY6zO/M= 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 1BC523858403 for ; Mon, 17 Oct 2022 18:56:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BC523858403 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-65Dzk_dwMuepMOIB4Hx9ag-1; Mon, 17 Oct 2022 14:56:29 -0400 X-MC-Unique: 65Dzk_dwMuepMOIB4Hx9ag-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D61C8823F65 for ; Mon, 17 Oct 2022 18:56:28 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.141]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 763EBF1033; Mon, 17 Oct 2022 18:56:26 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 29HIuMtQ078522 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 17 Oct 2022 20:56:22 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29HIuMeC078521; Mon, 17 Oct 2022 20:56:22 +0200 To: GCC patches Subject: [COMMITTED] Make sure exported range for SSA post-dominates the DEF in set_global_ranges_from_unreachable_edges. Date: Mon, 17 Oct 2022 20:56:18 +0200 Message-Id: <20221017185618.78502-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_NONE, RCVD_IN_MSPIKE_H2, 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.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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746962326315549768?= X-GMAIL-MSGID: =?utf-8?q?1746962326315549768?= The problem here is that we're exporting a range for an SSA range that happens on the other side of a __builtin_unreachable, but the SSA does not post-dominate the definition point. This is causing ivcanon to unroll things incorrectly. This was a snafu when converting the code from evrp. PR tree-optimization/107293 gcc/ChangeLog: * tree-ssa-dom.cc (dom_opt_dom_walker::set_global_ranges_from_unreachable_edges): Check that condition post-dominates the definition point. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107293.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr107293.c | 32 ++++++++++++++++++++++++ gcc/tree-ssa-dom.cc | 6 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107293.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c new file mode 100644 index 00000000000..724c31a11e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107293.c @@ -0,0 +1,32 @@ +// { dg-do run } +// { dg-options "-w -Os" } + +short a; +int b[1]; + +int c(int p) { + return (p < 0) ? 0 : 10 + ((p / 100 - 16) / 4); +} + +void f(int n) { + while (1) { + int m = n; + while ((m ) ) + m /= 2; + break; + } +} + +void g() { + int h = a = 0; + for (; h + a <= 0; a++) { + if (b[c(a - 6)]) + break; + f(a); + } +} +int main() { + g(); + if (a != 1) + __builtin_abort (); +} diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index e6b8dace5e9..c7f095d79fc 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1367,7 +1367,11 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb) tree name; gori_compute &gori = m_ranger->gori (); FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name) - if (all_uses_feed_or_dominated_by_stmt (name, stmt)) + if (all_uses_feed_or_dominated_by_stmt (name, stmt) + // The condition must post-dominate the definition point. + && (SSA_NAME_IS_DEFAULT_DEF (name) + || (gimple_bb (SSA_NAME_DEF_STMT (name)) + == pred_e->src))) { Value_Range r (TREE_TYPE (name));