From patchwork Mon Sep 18 01:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 141227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2383153vqi; Sun, 17 Sep 2023 18:45:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGf0BuyKlSpoN7sJDHga2V1MRxPwDerhGkMbH6vj9OTfa+7T6hXnaWlHZzuvLjY3OgqLF+f X-Received: by 2002:a19:3841:0:b0:4f8:5d0f:c779 with SMTP id d1-20020a193841000000b004f85d0fc779mr5328516lfj.40.1695001514433; Sun, 17 Sep 2023 18:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695001514; cv=none; d=google.com; s=arc-20160816; b=uu+y0jKFAFzWOTfSrpojezCcEvJ6LO16//ynRACTRWnNyrHaOVmjXhB8m3sq4Epc8l w9JyAJArAGzCvLGdsuuKkQbu71Lf+mqryu4Xwz6mTmHq7CNmS6tasKlXq7FpUgbQpZEA b0kZMcTaZfal6dDSOsgif+XCQjNPmr/VESxSk5HXKflsyoS9mxuhatwjFLNQx5/nVF6w T8LV/9wWUyYgIn95RI+ThF/xoX0s2lfXrwIomfEwVCBoj1Lact1Uue60aPfnV6Mbm+dN +ZioE2vTR/g5aBYBRMYz/FLQS5JKkufv3eLyHph9SnlLw/1tmxwlU+eHP1tnvA4/WLvV ni4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=HbPQx2T40sekXgAlZEaPx1Ywv0FJQ5Gqt5M8VfN4CpU=; fh=Hxj0cw/2jAkyitv6gv3v4BQlApRvZwleU4172JThTNQ=; b=KnXa8lIWKYJA4HQEUP3OSe5VByOSVquGRd6hNviUdF8C94ULubCfGnRbTaZL+zpaT4 0VqaUerAF7PMqaJF54G090/o1VWdaTwfxX5g8h9RczX5WOi1r9YvEqfeqYzX/W39u6Hy rVQ4NVxsyINL1LL27r4NyvCkxTZ8R1vnVbcZfM4L/deVYgrZN3Fi9cMKS04xstZ/kOa6 8P4w1WM3QM9NsdYdgohMgkJ/q4Icqt5nU3/iVcHQYRwjuusr9Xru5KDkbSWjg3mIDggx sFr9YZJ0+M3RRxWbepENyRFPC4CKVyH8EpB/25cmgCzG/FMAIEx+yipKx8lRGtfJGC4V 9hnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m15-20020aa7c2cf000000b0053115a037adsi927817edp.386.2023.09.17.18.45.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 18:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 515D53857B93 for ; Mon, 18 Sep 2023 01:45:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by sourceware.org (Postfix) with ESMTPS id 67A6C3858D32 for ; Mon, 18 Sep 2023 01:44:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67A6C3858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp80t1695001476to27gmfh Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 18 Sep 2023 09:44:35 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: JdnlBSJ0/wY0wgn6drhnXS50uqbt9kV6Z7/EOmIFbrejRnRfLUCumnT2o+sYk zJtI6rW5TiA+kd1uWVRofL3oK6nt0UcK/OqkZ+6y/h35bPwgZODRII+FulL80ogQictiUnY keSg0ybxzS8fxOOi0oQF7hIrJPRSL07DCd5Upe0LF2mxWxCV24uUr6cki8JaVX8bgbmp9Af MXemdcv+TTX87xX257lfuwf/+Q0By6iga4XjY1fJgVVLN4U5/vxSSAJZiozao04MO0jEkNo wABgLWSCW16EDKGgNuemjRu3BsP0dVHXl2sZKibkhyr76kA2KLk5tqpYSpoSnvRQqQygyH9 qbnTsPxc8m4IEpMn9WGPnEUss9xkmdvdrxyLrVgHNJ34DnrDB7AGH5GIrX/fg== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 1132293106127324574 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Juzhe-Zhong Subject: [PATCH V3] internal-fn: Support undefined rtx for uninitialized SSA_NAME Date: Mon, 18 Sep 2023 09:44:34 +0800 Message-Id: <20230918014434.2566268-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777337907706358120 X-GMAIL-MSGID: 1777337907706358120 According to PR: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110751 As Richard and Richi suggested, we recognize uninitialized SSA_NAME and convert it into SCRATCH rtx if the target predicate allows SCRATCH. It can help to reduce redundant data move instructions of targets like RISC-V. Bootstrap and Regression on x86 passed. gcc/ChangeLog: * internal-fn.cc (expand_fn_using_insn): Support undefined rtx value. * optabs.cc (maybe_legitimize_operand): Ditto. (can_reuse_operands_p): Ditto. * optabs.h (enum expand_operand_type): Ditto. (create_undefined_input_operand): Ditto. --- gcc/internal-fn.cc | 4 ++++ gcc/optabs.cc | 14 +++++++++++++- gcc/optabs.h | 14 +++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index 0fd34359247..61d5a9e4772 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -247,6 +247,10 @@ expand_fn_using_insn (gcall *stmt, insn_code icode, unsigned int noutputs, create_convert_operand_from (&ops[opno], rhs_rtx, TYPE_MODE (rhs_type), TYPE_UNSIGNED (rhs_type)); + else if (TREE_CODE (rhs) == SSA_NAME + && SSA_NAME_IS_DEFAULT_DEF (rhs) + && VAR_P (SSA_NAME_VAR (rhs))) + create_undefined_input_operand (&ops[opno], TYPE_MODE (rhs_type)); else create_input_operand (&ops[opno], rhs_rtx, TYPE_MODE (rhs_type)); opno += 1; diff --git a/gcc/optabs.cc b/gcc/optabs.cc index 32ff379ffc3..75b1d54ad7c 100644 --- a/gcc/optabs.cc +++ b/gcc/optabs.cc @@ -8102,6 +8102,17 @@ maybe_legitimize_operand (enum insn_code icode, unsigned int opno, goto input; } break; + + case EXPAND_UNDEFINED_INPUT: + /* For SCRATCH rtx which is converted from uninitialized + SSA, we convert it as fresh pseudo when target doesn't + allow scratch rtx in predicate. Otherwise, return true. */ + if (!insn_operand_matches (icode, opno, op->value)) + { + op->value = gen_reg_rtx (op->mode); + goto input; + } + return true; } return insn_operand_matches (icode, opno, op->value); } @@ -8140,7 +8151,8 @@ can_reuse_operands_p (enum insn_code icode, switch (op1->type) { case EXPAND_OUTPUT: - /* Outputs must remain distinct. */ + case EXPAND_UNDEFINED_INPUT: + /* Outputs and undefined intputs must remain distinct. */ return false; case EXPAND_FIXED: diff --git a/gcc/optabs.h b/gcc/optabs.h index c80b7f4dc1b..6faebf7cb63 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -37,7 +37,8 @@ enum expand_operand_type { EXPAND_CONVERT_TO, EXPAND_CONVERT_FROM, EXPAND_ADDRESS, - EXPAND_INTEGER + EXPAND_INTEGER, + EXPAND_UNDEFINED_INPUT }; /* Information about an operand for instruction expansion. */ @@ -117,6 +118,17 @@ create_input_operand (class expand_operand *op, rtx value, create_expand_operand (op, EXPAND_INPUT, value, mode, false); } +/* Make OP describe an undefined input operand for uninitialized + SSA. It's the scratch operand with mode MODE; MODE cannot be + VOIDmode. */ + +inline void +create_undefined_input_operand (class expand_operand *op, machine_mode mode) +{ + create_expand_operand (op, EXPAND_UNDEFINED_INPUT, gen_rtx_SCRATCH (mode), + mode, false); +} + /* Like create_input_operand, except that VALUE must first be converted to mode MODE. UNSIGNED_P says whether VALUE is unsigned. */