From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669193996; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Ws7uvixvcngDMm9tdax682ITRhBBSCwUtY//P/GMzfE=; b=Q+qlr6h5iHiROxMKSXTeX7OL2BBDavasAb0lFRqh+h4rUxoayx4b/ETF3vVwkuMJJGVtHl FvgKJSgIfV7FPWqZFFzWCUSZpS2GQatSuTam2Lgyfaj6VmZYWUlTtLy2HdyW6h8di3Iybj J+VmtWYsRDMYKDPbLIXsSGfzr/hxawk= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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); +} Jakub