From patchwork Wed Sep 20 14:58:49 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: 142476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4201612vqi; Wed, 20 Sep 2023 07:59:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBtklEfCoP8jmILc9IdCFpLLqZYXmBLUhVzUeEb+iXeWH30R6i0eIRVHquAr03ecRLr+6o X-Received: by 2002:a17:907:2ced:b0:9a5:7887:ef09 with SMTP id hz13-20020a1709072ced00b009a57887ef09mr2310306ejc.32.1695221991714; Wed, 20 Sep 2023 07:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695221991; cv=none; d=google.com; s=arc-20160816; b=Vg2hdIwFVYnIC1PrKwaU8wUOTU52h0esFdEHorYnuthEIV0xSKv7MfDgjY4afJB3jj fM1pAzpYZYvZB9PQcWfBuomJ9rKp8WtS8m0lPbgU6LozPOUn1Hno1PwMb+D6jsxQR/Bn C9RJc6Lkfj9MXTSfrtVnkYGpcKVWKsCXjL5T6yiDON/jyGFEcqrcgcq4whp+H2ZDLOBe sKxPEDDbxB9hKtGyYFN59NLMUYrpvCfT+124EiDS2DrnnS9U5/R1hVemwLHfxwhr16uq o1yXXtzU2N3uCfK8Chum98QfLodQ/IGx7jnddvGTXGCDJn8juHUiz4Kim4QpvgkU7YlD GBSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=rQPxiwq8d4tQZcrsaOckA9DTDGEesSqjoQ2FZPVnfzY=; fh=XOn9s5dq2NONAouyNARm1/dbaUTu13fDQSseNxDiA58=; b=K4UKHTStcD33pjM/jitYcmeM0rpUY6ysTLypYMNLiOymV8qXxFBDbcbONqMapEAHnX IHbPMOwXtUST7nMM0Z0Q9H7BNI63+A89N4A9SLANavLX/VBEs3IJ0mHPOPT3IJPuyMOK V9TpWcNlL4TriPtLV8i2B7MuNxFRV84jsizhH4MWBaD4GyYX2B8naoi4TVyIsk5uZBls HLTNUFqHAAiCkIH3RRPizOJGC3/g9il5zToHcO3AeJaF6uEAkmWFCbYimylb1Z6nGNm0 fcDr/pjUHed1Jc3v0Z0n3Eiv2M6nCWnEGEieDNKYeZAEoIK0iCBRFUYo5QO0trXOeMxE XKVg== 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 l24-20020a170906231800b0099381745ba0si12259334eja.156.2023.09.20.07.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 07:59:51 -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 17105385828D for ; Wed, 20 Sep 2023 14:59:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by sourceware.org (Postfix) with ESMTPS id E6A6F3858D39 for ; Wed, 20 Sep 2023 14:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6A6F3858D39 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: bizesmtp87t1695221932t58c08zm Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 20 Sep 2023 22:58:51 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: aBJFcW+uBGZpoiDoHltwNkCtbaeJX9DUrQxuul0ACns1yB/zH/iuxLyJF7Bon 3M+64dbAwhV+CQ+7hop5A1VDD/FYeK+4j3FcqZTT7iVFQPvAAMk7sxgbzwRTEF/T7u+ON6K qI2NoSkKJ6UhCtv43Fa5meYwmdZKpSaFOg3eUyeXabTrgkXbE5Zz7/HNYyCr4OZ8rXLZByZ 1eUORe3e9B0kQAqwg8bTtpYCLwC0DuTQu49wScL/lG3OUEw4197QGLE0BtIT2LFhb1kuJta JGToODy0O02ftIIGzgfl9Hm7uj4B1X54htAYMcUQ/Sw3+0rfslkho0Qe1xav5V0C4Wdhafk ivR+bXG5IP6L5+Gt7ost1RSHyYuyT3kaCSfl9tUG3UOw+U7GN8WeAU+SA/u+tqZbLWpQ+8f E6JycgaqRTBMJFFATr4e6w== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 1275808695233463458 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: rdapp.gcc@gmail.com, Juzhe-Zhong Subject: [Committed V4] internal-fn: Support undefined rtx for uninitialized SSA_NAME[PR110751] Date: Wed, 20 Sep 2023 22:58:49 +0800 Message-Id: <20230920145849.1118927-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=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777569095216389023 X-GMAIL-MSGID: 1777569095216389023 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 | 13 ++++++++++++- gcc/optabs.h | 13 ++++++++++++- 3 files changed, 28 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..8b96f23aec0 100644 --- a/gcc/optabs.cc +++ b/gcc/optabs.cc @@ -8102,6 +8102,16 @@ maybe_legitimize_operand (enum insn_code icode, unsigned int opno, goto input; } break; + + case EXPAND_UNDEFINED_INPUT: + /* See if the predicate accepts a SCRATCH rtx, which in this context + indicates an undefined value. Use an uninitialized register if not. */ + 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 +8150,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..9b78d40a46c 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,16 @@ 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 of mode MODE. MODE cannot + be null. */ + +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. */