From patchwork Sun Dec 5 21:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 48519 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 CECCE3858405 for ; Sun, 5 Dec 2021 22:00:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CECCE3858405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638741628; bh=eKUXnmUs95neR4toH2X4lCHDpGGqKTTdw0IBXz6AtHo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OZDC1KzKougjQNkPdEiOwtiIpPyNHaZCFlkvPCfAWcDXIr4EpmGpxBPoUXBneZRxP fFHBN1ZJKUFHmxbDY5Isyrngcd+f7RREQVdvaYQbetfKHp98EJn5EOdE/SBZ5+OXPX SvVIxEFRnGo+auq1bdJsnzp6PV/GkusUw8GpsTOg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 4E3B13858D28 for ; Sun, 5 Dec 2021 21:59:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4E3B13858D28 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 05FC6113E for ; Sun, 5 Dec 2021 13:59:59 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A12A43F5A1 for ; Sun, 5 Dec 2021 13:59:58 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] fold: Optimise fold_view_convert_expr Date: Sun, 05 Dec 2021 21:59:57 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When compiling an optabs.ii at -O2 with a release-checking build, there were 210,172 calls to fold_view_convert_expr. 99.8% of them were conversions of an INTEGER_CST to an ENUMERAL_TYPE, so this patch adds a fast(er) path for that case. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * fold-const.c (fold_view_convert_expr): Add a fast path for conversions of INTEGER_CSTs to other integral types. --- gcc/fold-const.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0b9a42f764a..19613015ddb 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9128,6 +9128,13 @@ fold_view_convert_vector_encoding (tree type, tree expr) static tree fold_view_convert_expr (tree type, tree expr) { + /* Conversions of INTEGER_CSTs to ENUMERAL_TYPEs are very common, + so handle them directly. */ + if (INTEGRAL_TYPE_P (type) + && TREE_CODE (expr) == INTEGER_CST + && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))) + return wide_int_to_tree (type, wi::to_wide (expr)); + /* We support up to 512-bit values (for V8DFmode). */ unsigned char buffer[64]; int len;