public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] treat argp-based mem as frame related in dse
@ 2023-12-06  9:27 Jiufu Guo
  2023-12-07 21:57 ` Jeff Law
  2023-12-22  2:17 ` Hans-Peter Nilsson
  0 siblings, 2 replies; 9+ messages in thread
From: Jiufu Guo @ 2023-12-06  9:27 UTC (permalink / raw)
  To: gcc-patches
  Cc: rguenther, jeffreyalaw, richard.sandiford, zadeck, pinskia,
	segher, dje.gcc, linkw, bergner, guojiufu

Hi,

The issue mentioned in PR112525 would be able to be handled by                             
updating dse.cc to treat arg_pointer_rtx similarly with frame_pointer_rtx.                             
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30271#c10 also mentioned                              
this idea.                                                           
                                                                
One thing, arpg area may be used to pass argument to callee. So, it would                            
be needed to check if call insns are using that mem.

Bootstrap &regtest pass on ppc64{,le} and x86_64.
Is this ok for trunk?

BR,
Jeff (Jiufu Guo)


	PR rtl-optimization/112525

gcc/ChangeLog:

	* dse.cc (get_group_info): Add arg_pointer_rtx as frame_related.
	(check_mem_read_rtx): Add parameter to indicate if it is checking mem
	for call insn.
	(scan_insn): Add mem checking on call usage.

gcc/testsuite/ChangeLog:

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

---
 gcc/dse.cc                                  | 17 +++++++++++++----
 gcc/testsuite/gcc.target/powerpc/pr112525.c | 15 +++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr112525.c

diff --git a/gcc/dse.cc b/gcc/dse.cc
index 1a85dae1f8c..f43b7bf8ba6 100644
--- a/gcc/dse.cc
+++ b/gcc/dse.cc
@@ -682,7 +682,8 @@ get_group_info (rtx base)
       gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
       gi->process_globally = false;
       gi->frame_related =
-	(base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx);
+	(base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx)
+	|| (base == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]);
       gi->offset_map_size_n = 0;
       gi->offset_map_size_p = 0;
       gi->offset_map_n = NULL;
@@ -2157,7 +2158,7 @@ replace_read (store_info *store_info, insn_info_t store_insn,
    be active.  */
 
 static void
-check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
+check_mem_read_rtx (rtx *loc, bb_info_t bb_info, bool used_in_call = false)
 {
   rtx mem = *loc, mem_addr;
   insn_info_t insn_info;
@@ -2302,7 +2303,8 @@ check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
 		 stored, rewrite the read.  */
 	      else
 		{
-		  if (store_info->rhs
+		  if (!used_in_call
+		      && store_info->rhs
 		      && known_subrange_p (offset, width, store_info->offset,
 					   store_info->width)
 		      && all_positions_needed_p (store_info,
@@ -2368,7 +2370,8 @@ check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
 
 	  /* If this read is just reading back something that we just
 	     stored, rewrite the read.  */
-	  if (store_info->rhs
+	  if (!used_in_call
+	      && store_info->rhs
 	      && store_info->group_id == -1
 	      && store_info->cse_base == base
 	      && known_subrange_p (offset, width, store_info->offset,
@@ -2650,6 +2653,12 @@ scan_insn (bb_info_t bb_info, rtx_insn *insn, int max_active_local_stores)
            that is not relative to the frame.  */
         add_non_frame_wild_read (bb_info);
 
+      for (rtx link = CALL_INSN_FUNCTION_USAGE (insn);
+	   link != NULL_RTX;
+	   link = XEXP (link, 1))
+	if (GET_CODE (XEXP (link, 0)) == USE && MEM_P (XEXP (XEXP (link, 0),0)))
+	  check_mem_read_rtx (&XEXP (XEXP (link, 0),0), bb_info, true);
+
       return;
     }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr112525.c b/gcc/testsuite/gcc.target/powerpc/pr112525.c
new file mode 100644
index 00000000000..428598188e7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr112525.c
@@ -0,0 +1,15 @@
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O2" } */
+
+typedef struct teststruct
+{
+  double d;
+  int arr[15]; 
+} teststruct;
+
+void
+foo (teststruct p)
+{
+}
+
+/* { dg-final { scan-assembler-not {\mstd\M} } } */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-22  2:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06  9:27 [PATCH] treat argp-based mem as frame related in dse Jiufu Guo
2023-12-07 21:57 ` Jeff Law
2023-12-08  7:18   ` Jiufu Guo
2023-12-10 18:19     ` Jeff Law
2023-12-11  3:07       ` Jiufu Guo
2023-12-11  6:28         ` Jeff Law
2023-12-11  9:26           ` Jiufu Guo
2023-12-11 15:53             ` Jeff Law
2023-12-22  2:17 ` Hans-Peter Nilsson

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