From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 83A983858D39 for ; Wed, 20 Sep 2023 15:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83A983858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dabbelt.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dabbelt.com Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c4194f7635so7442095ad.0 for ; Wed, 20 Sep 2023 08:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20230601.gappssmtp.com; s=20230601; t=1695222688; x=1695827488; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=+u/jCRN6QbTKioZZwzYBUqJad5hhvYkJ4kLHS+oWLf4=; b=o5kB1FqDJKkSJ+m7jiWw10EdGM4wh5Pl+4ViG4der3mUHURAyZKmlleTnIWhRjH3GJ 925idPIxI/0NqwTEMKnWtHC/Sq6dx4ZLoYhGnbNkO8aIlV9JWF5RA80/bJUS+n5MG3iq 1WPOGCKo/YDDRkFcV9/oOaOFzryQG087YZ3if6sB7RNyZZNYcDnindVWLXhikh/0mU5W QJOgToYag6b1vOJDEZxDegsiU+Bg5wj3TqEuSTfSIJZlLuZrZOb49c5No1bpuktu1EHr LSbokIDzNjpUvOzUIGJtT6HdJkE7tNDTNUson1J/MJFtPfltdu76czPkx2vKYlj5ZaWT Cd4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695222688; x=1695827488; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+u/jCRN6QbTKioZZwzYBUqJad5hhvYkJ4kLHS+oWLf4=; b=DewLqLSkQNndi9fHz7falH7wINnDBYHcUoylmTPgdIG44L4YJtS4xFwqfqeR8UYk/d CfMKzyusgJW31jEpXXS4UEs4ThAxexpFHbbe6oO8z0HQ1YtDs17u+fE2LzULYG5zz14j 4u/M9o+luccai6bl3OWmpHsPKcsdx/fNTHoxvtEBHlf1A0kagUjQcXckfHBGD/0JhW93 tOOMOvaWNU1DYYkCQqyLlJXsK14t4JMzzZgcLiECO/qfBUQ79y7OvuZSYHO8vsInOwMY vMKuFEXKBc22S71DmmGZ8m9/rJi3najWQbpyK/nlSFCWK/jbN/btGRt6GjpMbPM+aGwG zviw== X-Gm-Message-State: AOJu0YwtSKEp/L/sxNsWXSa6MUzw1hIijD92dPg7sXubfQbn7cbSVi0C kF3pDqqPTgHUMHYOs+o2SC0MtzrhVZtuQle6IM9kOw== X-Google-Smtp-Source: AGHT+IG0wGJkBzYQL6oiF7FLCzFDjqSolP2tb8mTEGp1yj/p9hhxBbFBAOaPZeoKNwxjSs7enrzfhg== X-Received: by 2002:a17:902:d2cd:b0:1c5:6f43:9502 with SMTP id n13-20020a170902d2cd00b001c56f439502mr4345430plc.14.1695222688175; Wed, 20 Sep 2023 08:11:28 -0700 (PDT) Received: from localhost ([51.52.155.79]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c21500b001b9d335223csm2585490pll.26.2023.09.20.08.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:11:27 -0700 (PDT) Date: Wed, 20 Sep 2023 08:11:27 -0700 (PDT) X-Google-Original-Date: Wed, 20 Sep 2023 08:11:14 PDT (-0700) Subject: Re: [Committed V4] internal-fn: Support undefined rtx for uninitialized SSA_NAME[PR110751] In-Reply-To: <20230920145849.1118927-1-juzhe.zhong@rivai.ai> CC: gcc-patches@gcc.gnu.org, rdapp.gcc@gmail.com, juzhe.zhong@rivai.ai From: Palmer Dabbelt To: juzhe.zhong@rivai.ai Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: On Wed, 20 Sep 2023 07:58:49 PDT (-0700), juzhe.zhong@rivai.ai wrote: > 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. It's somewhat common to put the PR at the top of the ChangeLog (though I pretty frequently forget as well). > > --- > 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. */