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: 61019 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 3483D3852C59 for ; Wed, 23 Nov 2022 09:00:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3483D3852C59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669194025; 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=LdgK8SK9TxeoAezIbUgngri9JmLo0n96rzwDvBsP4T9UrsZjzu/HBOjBk+lK66G83 ebHpsc736ypjW6bHG7CEkhHmIYTx/A4Tes90N6BLpL9QFWTSPMwqinsGpf7OQwPuZ5 Z6JC7CHv6sScGjdu9YjsyfKqXNu96N1UtO3Z8bxc= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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);