From patchwork Wed Nov 23 08:59:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 24802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2672746wrr; Wed, 23 Nov 2022 01:00:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6V7XHYPJLj+ke201UN4LZVKZ46zs4D0pX6fzJHXxIEHFFEvGWBD9EDA6cNMwRf6fJm7Nfx X-Received: by 2002:a17:906:1e83:b0:78d:addf:67c3 with SMTP id e3-20020a1709061e8300b0078daddf67c3mr14317262ejj.253.1669194040841; Wed, 23 Nov 2022 01:00:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669194040; cv=none; d=google.com; s=arc-20160816; b=f6156rKYFxT3Mbn7g9uJABCbheKI30w1sKpmn6JWrrTemI+PFfCkO/F74SIt00Od1D w0fSVr5XqrMarf+Oe2um2kdu+JGjzjF+TnYwU0QhSh65giJq9gRm02jpN9snbtRZBaxn VCj3mWnqodUcd1dtWYlSXUZiUXoOQm8G48XEaSrtYhR/GVE71Z/qhnrLln7Ew8CDQw2z U16PF5Aj02JuPsCg5BO9AUwS5WTddXpr356HYNLzqBa1piY9BQH8C6zhf1KxXknbF1Np VWTr+LURm9A//5um3HsFAhk8nsOPJjm56U3GPydHPjnsYlbIFYv59HzDxOJ2AfP9NCYN ONHA== 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-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Ws7uvixvcngDMm9tdax682ITRhBBSCwUtY//P/GMzfE=; b=R9Y7zvSxwjQyEDpbZod31yhFAah4y3FS9Ka74ufWj1YEvTr41qoZu23uaB44Tu3irw QniJHi/jMGTU6HM8Hd6zKClWT9gRdjgEqmkOG82975iC8J/SWkpMvHxGNT37gAT0sUU8 zz4XhRF+dNAKjbZD/YO5LICagx6mZAlRgBqoKlG2BeSlzECw2NHTXvZKTPrEj9rgldCA 9QmRlNl7qWYjZUVWRFgvHYkkzm1frC1ZNL8RhZTyMRGx165wfmejbdkCty7SEDR0rV7N T+00sJk3+guRid/mi2E/OpMTbOqb5tVRBBlNRgH2evAVlTay/6BU+/vo2glNHEMLMlDS WMVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="CIy/zeUW"; 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 q24-20020aa7d458000000b00461d97e5287si11918247edr.344.2022.11.23.01.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 01:00:40 -0800 (PST) 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="CIy/zeUW"; 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 D557A3854562 for ; Wed, 23 Nov 2022 09:00:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D557A3854562 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669194039; bh=Ws7uvixvcngDMm9tdax682ITRhBBSCwUtY//P/GMzfE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CIy/zeUWtqmONYRxqrj6x2vKtTTVb3WjL8YvSOxowz/y7duudjjVau/5qz1R6h3ao 8yzR3m6kw1vxbxwaY47K7NLSpNAlfpzCutEt8pfvxaEcgfz718Ekmm9BqHtSppbTRq WWaOABR98vGjJLdYB9eydY4Qsk04Uodd6hoDkClw= 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 204613853D60 for ; Wed, 23 Nov 2022 08:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 204613853D60 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-478-QgHT7wfuPzuczzNKbOnZEw-1; Wed, 23 Nov 2022 03:59:55 -0500 X-MC-Unique: QgHT7wfuPzuczzNKbOnZEw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50CCD185A794; Wed, 23 Nov 2022 08:59:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B735492B07; Wed, 23 Nov 2022 08:59:54 +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 2AN8xo0h2527573 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 23 Nov 2022 09:59:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AN8xnNu2527572; Wed, 23 Nov 2022 09:59:49 +0100 Date: Wed, 23 Nov 2022 09:59:49 +0100 To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Fix compile time hog in c_genericize [PR107127] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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_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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1750276810720312688?= X-GMAIL-MSGID: =?utf-8?q?1750276810720312688?= Hi! The complex multiplications result in deeply nested set of many SAVE_EXPRs, which takes even on fast machines over 5 minutes to walk. This patch fixes that by using walk_tree_without_duplicates where it is instant. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-11-23 Andrew Pinski Jakub Jelinek PR c/107127 * c-gimplify.cc (c_genericize): Use walk_tree_without_duplicates instead of walk_tree for c_genericize_control_r. * gcc.dg/pr107127.c: New test. +} Jakub --- gcc/c-family/c-gimplify.cc.jj 2022-08-12 13:39:59.229218070 +0200 +++ gcc/c-family/c-gimplify.cc 2022-11-22 11:48:39.977263700 +0100 @@ -572,8 +572,8 @@ c_genericize (tree fndecl) bc_state_t save_state; push_cfun (DECL_STRUCT_FUNCTION (fndecl)); save_bc_state (&save_state); - walk_tree (&DECL_SAVED_TREE (fndecl), c_genericize_control_r, - NULL, NULL); + walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl), + c_genericize_control_r, NULL); restore_bc_state (&save_state); pop_cfun (); } --- gcc/testsuite/gcc.dg/pr107127.c.jj 2022-11-22 11:56:20.798454526 +0100 +++ gcc/testsuite/gcc.dg/pr107127.c 2022-11-22 11:56:06.224669767 +0100 @@ -0,0 +1,12 @@ +/* PR c/107127 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int *v; + +_Complex double +foo (_Complex double a, double b, double c) +{ + return v[0] / ((((c * (0 - 0 / a + 699.0 + 7.05 - 286.0 - +-4.65 + 1.57 + 0) * 0.1 - 3.28 + 4.22 + 0.1)) * b + 5.06) + * 1.23 * 8.0 * 12.0 * 16.0 * 2.0 * 2.0 * 0.25 * 0.125 * 18.2 * -15.25 * 0.0001 + * 42.0 * 0.012 - 8.45 + 0 + 88.0 + 6.96 + 867.0 + 9.10 - 7.04 * -1.0);