public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] internal-fn: Support undefined rtx for uninitialized SSA_NAME[PR110751]
@ 2023-09-26 15:10 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-09-26 15:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7d66f9075bb12945f149669e1e37c4441aded3f2

commit 7d66f9075bb12945f149669e1e37c4441aded3f2
Author: Juzhe-Zhong <juzhe.zhong@rivai.ai>
Date:   Wed Sep 20 22:58:49 2023 +0800

    internal-fn: Support undefined rtx for uninitialized SSA_NAME[PR110751]
    
    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:
            PR target/110751
    
            * 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.
    
    (cherry picked from commit 27282dc0931484c31fa391772499d878afcc746a)

Diff:
---
 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 7a23640ec07..c23ee3407f9 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -193,6 +193,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 8978cac5ace..e93970e2e78 100644
--- a/gcc/optabs.cc
+++ b/gcc/optabs.cc
@@ -8019,6 +8019,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);
 }
@@ -8057,7 +8067,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 f14d012d92f..c244ea421d9 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.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-26 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 15:10 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] internal-fn: Support undefined rtx for uninitialized SSA_NAME[PR110751] Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).