public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]rs6000: Update rtx_cost for constant building
@ 2022-03-25  2:05 Jiufu Guo
  0 siblings, 0 replies; only message in thread
From: Jiufu Guo @ 2022-03-25  2:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: segher, dje.gcc, guojiufu

When building a const to a reg, it may need a few instructions.
This patch updates rs6000_rtx_costs to make it more accurate for
constant building.

With this patch, cse.cc could get accurate cost for complex
constant and then read the constant from a pool.
As discussed in the mail list, this patch is updating rtx_cost hook
which may be preferred for this issue.

Bootstrap and regtest pass on ppc64 and ppc64le.
Is this ok for trunk or more suitable for stage1?


BR,
Jiufu

	PR target/63281

gcc/ChangeLog:

	* config/rs6000/rs6000.cc (rs6000_rtx_costs): Update for
	const int.

gcc/testsuite/ChangeLog:

	* gcc.target/powerpc/pr63281.c: New test.

---
 gcc/config/rs6000/rs6000.cc                |  8 ++++++++
 gcc/testsuite/gcc.target/powerpc/pr63281.c | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr63281.c

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 283e8306ff7..62fcd345af2 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -21838,6 +21838,14 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
 
     case CONST_DOUBLE:
     case CONST_WIDE_INT:
+      /* Set a const to reg, it may needs a few insns.  */
+      if (outer_code == SET)
+	{
+	  *total = COSTS_N_INSNS (num_insns_constant (x, mode));
+	  return true;
+	}
+      /* FALLTHRU */
+
     case CONST:
     case HIGH:
     case SYMBOL_REF:
diff --git a/gcc/testsuite/gcc.target/powerpc/pr63281.c b/gcc/testsuite/gcc.target/powerpc/pr63281.c
new file mode 100644
index 00000000000..469a8f64400
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr63281.c
@@ -0,0 +1,11 @@
+/* PR target/63281 */
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O2 -std=c99" } */
+
+void
+foo (unsigned long long *a)
+{
+  *a = 0x020805006106003;
+}
+
+/* { dg-final { scan-assembler-times {\mp?ld\M} 1 } } */
-- 
2.25.1


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

only message in thread, other threads:[~2022-03-25  2:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25  2:05 [PATCH]rs6000: Update rtx_cost for constant building Jiufu Guo

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).