public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3
@ 2020-07-02 13:22 xiezhiheng
  2020-07-02 14:45 ` Richard Biener
  0 siblings, 1 reply; 44+ messages in thread
From: xiezhiheng @ 2020-07-02 13:22 UTC (permalink / raw)
  To: gcc-patches

Hi,

This is a fix for pr94442.
I modify get_inner_reference to handle the case for MEM[ptr, off].
I extract the "off" and add it to the recorded offset, then I build a
MEM[ptr, 0] and return it later.

diff --git a/gcc/expr.c b/gcc/expr.c
index 3c68b0d754c..8cc18449a0c 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -7362,7 +7362,8 @@ tree
 get_inner_reference (tree exp, poly_int64_pod *pbitsize,
 		     poly_int64_pod *pbitpos, tree *poffset,
 		     machine_mode *pmode, int *punsignedp,
-		     int *preversep, int *pvolatilep)
+		     int *preversep, int *pvolatilep,
+		     bool include_memref_p)
 {
   tree size_tree = 0;
   machine_mode mode = VOIDmode;
@@ -7509,6 +7510,21 @@ get_inner_reference (tree exp, poly_int64_pod *pbitsize,
 		}
 	      exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
 	    }
+	  else if (include_memref_p
+		   && TREE_CODE (TREE_OPERAND (exp, 0)) == SSA_NAME)
+	    {
+	      tree off = TREE_OPERAND (exp, 1);
+	      if (!integer_zerop (off))
+		{
+		  poly_offset_int boff = mem_ref_offset (exp);
+		  boff <<= LOG2_BITS_PER_UNIT;
+		  bit_offset += boff;
+
+		  exp = build2 (MEM_REF, TREE_TYPE (exp),
+				TREE_OPERAND (exp, 0),
+				build_int_cst (TREE_TYPE (off), 0));
+		}
+	    }
 	  goto done;
 
 	default:
@@ -10786,7 +10802,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
 	int reversep, volatilep = 0, must_force_mem;
 	tree tem
 	  = get_inner_reference (exp, &bitsize, &bitpos, &offset, &mode1,
-				 &unsignedp, &reversep, &volatilep);
+				 &unsignedp, &reversep, &volatilep, true);
 	rtx orig_op0, memloc;
 	bool clear_mem_expr = false;
 
diff --git a/gcc/tree.h b/gcc/tree.h
index a74872f5f3e..7df0d15f7f9 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -6139,7 +6139,8 @@ extern bool complete_ctor_at_level_p (const_tree, HOST_WIDE_INT, const_tree);
    look for the ultimate containing object, which is returned and specify
    the access position and size.  */
 extern tree get_inner_reference (tree, poly_int64_pod *, poly_int64_pod *,
-				 tree *, machine_mode *, int *, int *, int *);
+				 tree *, machine_mode *, int *, int *, int *,
+				 bool = false);
 
 extern tree build_personality_function (const char *);


I add an argument "include_memref_p" to control whether to go into MEM_REF,
because without it will cause the test case "Warray-bounds-46.c" to fail in regression.

It because function set_base_and_offset in gimple-ssa-warn-restrict.c
  base = get_inner_reference (expr, &bitsize, &bitpos, &var_off,
                              &mode, &sign, &reverse, &vol);
  ...
  ...
  if (TREE_CODE (base) == MEM_REF)
    {
      tree memrefoff = fold_convert (ptrdiff_type_node, TREE_OPERAND (base, 1));
      extend_offset_range (memrefoff);
      base = TREE_OPERAND (base, 0);

      if (refoff != HOST_WIDE_INT_MIN
          && TREE_CODE (expr) == COMPONENT_REF)
        {
          /* Bump up the offset of the referenced subobject to reflect
             the offset to the enclosing object.  For example, so that
             in
               struct S { char a, b[3]; } s[2];
               strcpy (s[1].b, "1234");
             REFOFF is set to s[1].b - (char*)s.  */
          offset_int off = tree_to_shwi (memrefoff);
          refoff += off;
        }

      if (!integer_zerop (memrefoff))       <=================
        /* A non-zero offset into an array of struct with flexible array
           members implies that the array is empty because there is no
           way to initialize such a member when it belongs to an array.
           This must be some sort of a bug.  */
        refsize = 0;
    }

needs MEM_REF offset to judge whether refsize should be set to zero.
But I fold the offset into bitpos and the offset will always be zero.

Suggestion?

^ permalink raw reply	[flat|nested] 44+ messages in thread
* [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3
@ 2020-04-02  6:35 xiezhiheng
  2020-06-09 20:40 ` Jeff Law
  0 siblings, 1 reply; 44+ messages in thread
From: xiezhiheng @ 2020-04-02  6:35 UTC (permalink / raw)
  To: gcc-patches

Hi,
  I've created a bug for this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94442

  And I'm going to solve this problem by propagating def's insn to its use
  when they are at the same loop in fwprop pass.
  I mean something like:
diff --git a/gcc/fwprop.c b/gcc/fwprop.c
index 705d2885aae..0edbbc65047 100644
--- a/gcc/fwprop.c
+++ b/gcc/fwprop.c
@@ -416,7 +416,7 @@ should_replace_address (rtx old_rtx, rtx new_rtx, machine_mode mode,
     gain = (set_src_cost (new_rtx, VOIDmode, speed)
            - set_src_cost (old_rtx, VOIDmode, speed));

-  return (gain > 0);
+  return (gain >= 0);
 }


@@ -1573,10 +1573,14 @@ fwprop (bool fwprop_addr_p)
       df_ref use = DF_USES_GET (i);
       if (use)
        {
+         df_ref def = get_def_for_use (use);
          if (DF_REF_TYPE (use) == DF_REF_REG_USE
              || DF_REF_BB (use)->loop_father == NULL
              /* The outer most loop is not really a loop.  */
-             || loop_outer (DF_REF_BB (use)->loop_father) == NULL)
+             || loop_outer (DF_REF_BB (use)->loop_father) == NULL
+             || (def && (DF_REF_BB (def)->loop_father == DF_REF_BB (use)->loop_father
+                         || flow_loop_nested_p (DF_REF_BB(use)->loop_father,
+                                                DF_REF_BB(def)->loop_father))))
            forward_propagate_into (use, fwprop_addr_p);

          else if (fwprop_addr_p)

Any suggestions?

Best regards
Xie Zhiheng

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

end of thread, other threads:[~2020-11-11 10:59 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 13:22 [PATCH PR94442] [AArch64] Redundant ldp/stp instructions emitted at -O3 xiezhiheng
2020-07-02 14:45 ` Richard Biener
2020-07-06  9:10   ` xiezhiheng
2020-07-06  9:31     ` Richard Sandiford
2020-07-07 12:49       ` xiezhiheng
2020-07-07 14:07         ` Richard Sandiford
2020-07-15  8:49           ` xiezhiheng
2020-07-16 12:41             ` Richard Sandiford
2020-07-16 14:05               ` xiezhiheng
2020-07-17  9:03                 ` Richard Sandiford
2020-07-30  2:43                   ` xiezhiheng
2020-07-31  9:02                     ` Richard Sandiford
2020-08-03  2:21                       ` xiezhiheng
2020-08-03 13:55                         ` Richard Sandiford
2020-08-04  8:01                           ` xiezhiheng
2020-08-04 16:25                             ` Richard Sandiford
2020-08-17  8:05                               ` xiezhiheng
2020-08-19 10:06                                 ` Richard Sandiford
2020-08-20  8:24                                   ` xiezhiheng
2020-08-20  8:55                                     ` Richard Sandiford
2020-08-20 12:16                                       ` xiezhiheng
2020-08-21  9:02                                         ` Richard Sandiford
2020-08-25  3:14                                           ` xiezhiheng
2020-08-25 11:07                                             ` Richard Sandiford
2020-08-26  1:39                                               ` xiezhiheng
2020-08-26 10:14                                                 ` Richard Sandiford
2020-08-27  2:50                                                   ` xiezhiheng
2020-08-27  8:08                                                     ` Richard Sandiford
2020-10-09  9:32                                                       ` xiezhiheng
2020-10-13  8:07                                                         ` Richard Sandiford
2020-10-19  9:21                                                           ` xiezhiheng
2020-10-20 16:53                                                             ` Richard Sandiford
2020-10-22  9:16                                                               ` xiezhiheng
2020-10-26 13:03                                                                 ` Richard Sandiford
2020-10-30  6:41                                                                   ` xiezhiheng
2020-10-30 10:23                                                                     ` Richard Sandiford
2020-11-03 11:59                                                                       ` xiezhiheng
2020-11-03 13:57                                                                         ` Richard Sandiford
2020-11-09  3:27                                                                           ` xiezhiheng
2020-11-10 11:53                                                                             ` Richard Sandiford
2020-11-11  7:59                                                                               ` xiezhiheng
2020-11-11 10:59                                                                                 ` Richard Sandiford
  -- strict thread matches above, loose matches on Subject: below --
2020-04-02  6:35 xiezhiheng
2020-06-09 20:40 ` 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).