From patchwork Tue Oct 6 01:15:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1377180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C4zzX46nqz9ryj for ; Tue, 6 Oct 2020 12:15:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82F78385782E; Tue, 6 Oct 2020 01:15:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id D57283857C50 for ; Tue, 6 Oct 2020 01:15:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D57283857C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oliva@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F2BF3117756; Mon, 5 Oct 2020 21:15:09 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AKoKON5FYEsj; Mon, 5 Oct 2020 21:15:09 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id BC64611773C; Mon, 5 Oct 2020 21:15:09 -0400 (EDT) Received: from livre.home (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 0961F2Ts121534 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 5 Oct 2020 22:15:03 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: make sincos take type from intrinsic formal, not from result assignment Organization: Free thinker, does not speak for AdaCore Date: Mon, 05 Oct 2020 22:15:02 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-10.2 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This is a first step towards enabling the sincos optimization in Ada. The issue this patch solves is that sincos takes the type to be looked up with mathfn_built_in from variables or temporaries in which results of sin and cos are stored. In Ada, sin and cos are declared in an internal aux package, with uses thereof in a standard generic package, which ensures that the types are not what mathfn_built_in expects. Taking the type from the intrinsic's formal parameter, as in the patch, ensures we get the type associated with the intrinsics, regardless of the types used to declare and import them, so the lookup of the CEXPI intrinsic for the same type finds it. for gcc/ChangeLog * tree-ssa-math-opts.c (execute_cse_sincos_1): Take the type for the cexpi/sincos intrinsic interface from formals of other intrinsics. --- gcc/tree-ssa-math-opts.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 8423caa..31fd241 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1139,7 +1139,7 @@ execute_cse_sincos_1 (tree name) { gimple_stmt_iterator gsi; imm_use_iterator use_iter; - tree fndecl, res, type; + tree fndecl = NULL_TREE, res, type = NULL_TREE; gimple *def_stmt, *use_stmt, *stmt; int seen_cos = 0, seen_sin = 0, seen_cexpi = 0; auto_vec stmts; @@ -1147,7 +1147,6 @@ execute_cse_sincos_1 (tree name) int i; bool cfg_changed = false; - type = TREE_TYPE (name); FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, name) { if (gimple_code (use_stmt) != GIMPLE_CALL @@ -1169,15 +1168,34 @@ execute_cse_sincos_1 (tree name) break; default:; + continue; } - } + tree t = TREE_VALUE (TYPE_ARG_TYPES (gimple_call_fntype (use_stmt))); + if (!type) + type = t; + else if (t != type) + { + if (!tree_nop_conversion_p (type, t)) + return false; + /* If there is more than one type to choose from, prefer one + that has a CEXPI builtin. */ + else if (!fndecl + && (fndecl = mathfn_built_in (t, BUILT_IN_CEXPI))) + type = t; + } + } if (seen_cos + seen_sin + seen_cexpi <= 1) return false; + if (type != TREE_TYPE (name) + && !tree_nop_conversion_p (type, TREE_TYPE (name))) + return false; + /* Simply insert cexpi at the beginning of top_bb but not earlier than the name def statement. */ - fndecl = mathfn_built_in (type, BUILT_IN_CEXPI); + if (!fndecl) + fndecl = mathfn_built_in (type, BUILT_IN_CEXPI); if (!fndecl) return false; stmt = gimple_build_call (fndecl, 1, name);