From patchwork Fri Sep 2 12:32:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp708841wro; Fri, 2 Sep 2022 05:33:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7NeaFDhE4YneyBU1QZUJKVxg3Q9J4z4lu09DTGJE6Odqc3NXvhnx+EFmqrx6SAbr4L7jd1 X-Received: by 2002:a05:6402:882:b0:447:e6b9:89db with SMTP id e2-20020a056402088200b00447e6b989dbmr28946495edy.346.1662122024120; Fri, 02 Sep 2022 05:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662122024; cv=none; d=google.com; s=arc-20160816; b=GcwL1dAFQpPQoIxdiZI9MV4XzPHSmZXzzz0SLNGz5EPs/0cQLH4kKJbgp4mDwp/evI DDRPot+XfHzpgjlEy6YB8TF+x8c9ejy8l7h3svTwf+3r+hHWXx/vvDer3Rp33xehpRjM swe7YttoFoJj2zy+b+/46St2vCMXUtP5mh9US8zuAlcjUNPXMt3DsNb6OSa2fq6Ug3Zr YTsz56o/CviNI9sIU32+S3yEP/yes/6UrvReTpHdsNwjs+5XcMJqHq/uIhBkUzICZjCY +mbPnvPjB/YYwT1y3egfSFn7EOyTc39jInGIq8hhQtVtPskXnDkOyPh88plau1MD3Xfw VLhg== 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:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=uEqe73EbFZI3rtmRH+CDQJIE+fwemnZat6LUUEIKUks=; b=l2yXfjB/axq719ZqH2oh6bVX4CLhR8NcfiYZ65UPeDxAkwVgPSLzFm+pP09pnOp8Ya rGMInuULLVrxhhSZXSx2/vih1OpWsG9JPutnbTXrwe+cfLX7ydW0O2d0Xh6cVhclqKLQ mjD8fXGBnJqcYP45B5Cxq9Q4zW7hwpWu4tGSZI9mAG+SptZ/A90/DB/eLONxCQ3wj3t3 REu3udr037kAB4hkIDeEJUG5SFC65W0YrQUkyxdEVk6qnA8CFy4ndm4+2+uD7YS8ZUb1 FQXVvdYQSAnwTY+UPSk7z3LvO4yYo0oEOtWp20hjmtmh4iCJNIMMngYzo5ds9ZEgVUGE fl2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PN2Lpa8Y; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fs37-20020a170907602500b007330c59455fsi1457172ejc.938.2022.09.02.05.33.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 05:33:44 -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=PN2Lpa8Y; 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 AFFC83858285 for ; Fri, 2 Sep 2022 12:33:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFFC83858285 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662122020; bh=uEqe73EbFZI3rtmRH+CDQJIE+fwemnZat6LUUEIKUks=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PN2Lpa8Y/Ii88E6Vl2dw6MdhItllqDf7gI22Ds5amK887WN5WdTT7mnCvflIUsaau l9WA3dtNlkvxcIbo97+TU5KyS+eOObEwe0/vZre1O+NrktnbIE18rUFgdzM/mp0F2L 3iEHw0/Wn566BY9P4hFYY1Su0QeGK84IGt66J3/U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id B53CE3858C74 for ; Fri, 2 Sep 2022 12:32:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B53CE3858C74 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7837C20A4C for ; Fri, 2 Sep 2022 12:32:56 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 63A7B13328 for ; Fri, 2 Sep 2022 12:32:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4JL0Fvj3EWNwaAAAMHmgww (envelope-from ) for ; Fri, 02 Sep 2022 12:32:56 +0000 Date: Fri, 2 Sep 2022 14:32:55 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106809 - compile time hog in VN MIME-Version: 1.0 Message-Id: <20220902123256.63A7B13328@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener 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?1742861263382564752?= X-GMAIL-MSGID: =?utf-8?q?1742861263382564752?= The dominated_by_p_w_unex function is prone to high compile time. With GCC 12 we introduced a VN run for uninit diagnostics which now runs into a degenerate case with bison generated code. Fortunately this case is easy to fix with a simple extra check - a more general fix needs more work. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106809 * tree-ssa-sccvn.cc (dominaged_by_p_w_unex): Check we have more than one successor before doing extra work. * gcc.dg/torture/pr106809.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr106809.c | 28 ++++++++++++ gcc/tree-ssa-sccvn.cc | 57 +++++++++++++------------ 2 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106809.c diff --git a/gcc/testsuite/gcc.dg/torture/pr106809.c b/gcc/testsuite/gcc.dg/torture/pr106809.c new file mode 100644 index 00000000000..11e158185cf --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106809.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wuninitialized" } */ + +int foo (int x, int *val) +{ + switch (x) + { +#define C(n) \ + case n + 0: return *val; \ + case n + 1: return *val; \ + case n + 2: return *val; \ + case n + 3: return *val; \ + case n + 4: return *val; \ + case n + 5: return *val; \ + case n + 6: return *val; \ + case n + 7: return *val; \ + case n + 8: return *val; \ + case n + 9: return *val; +#define C1(n) \ + C(n+00) C(n+10) C(n+20) C(n+30) C(n+40) \ + C(n+50) C(n+60) C(n+70) C(n+80) C(n+90) +#define C10(n) \ + C1(n+000) C1(n+100) C1(n+200) C1(n+300) C1(n+400) \ + C1(n+500) C1(n+600) C1(n+700) C1(n+800) C1(n+900) + C10(1000) + } + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index a1f6f309609..5abc8667ce6 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -4877,41 +4877,44 @@ dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool allow_back) } /* Iterate to the single executable bb2 successor. */ - edge succe = NULL; - FOR_EACH_EDGE (e, ei, bb2->succs) - if ((e->flags & EDGE_EXECUTABLE) - || (!allow_back && (e->flags & EDGE_DFS_BACK))) - { - if (succe) - { - succe = NULL; - break; - } - succe = e; - } - if (succe) + if (EDGE_COUNT (bb2->succs) > 1) { - /* Verify the reached block is only reached through succe. - If there is only one edge we can spare us the dominator - check and iterate directly. */ - if (EDGE_COUNT (succe->dest->preds) > 1) - { - FOR_EACH_EDGE (e, ei, succe->dest->preds) - if (e != succe - && ((e->flags & EDGE_EXECUTABLE) - || (!allow_back && (e->flags & EDGE_DFS_BACK)))) + edge succe = NULL; + FOR_EACH_EDGE (e, ei, bb2->succs) + if ((e->flags & EDGE_EXECUTABLE) + || (!allow_back && (e->flags & EDGE_DFS_BACK))) + { + if (succe) { succe = NULL; break; } - } + succe = e; + } if (succe) { - bb2 = succe->dest; + /* Verify the reached block is only reached through succe. + If there is only one edge we can spare us the dominator + check and iterate directly. */ + if (EDGE_COUNT (succe->dest->preds) > 1) + { + FOR_EACH_EDGE (e, ei, succe->dest->preds) + if (e != succe + && ((e->flags & EDGE_EXECUTABLE) + || (!allow_back && (e->flags & EDGE_DFS_BACK)))) + { + succe = NULL; + break; + } + } + if (succe) + { + bb2 = succe->dest; - /* Re-do the dominance check with changed bb2. */ - if (dominated_by_p (CDI_DOMINATORS, bb1, bb2)) - return true; + /* Re-do the dominance check with changed bb2. */ + if (dominated_by_p (CDI_DOMINATORS, bb1, bb2)) + return true; + } } }