public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC, Patch]: Optimized changes in the register used inside loop for LICM and IVOPTS.
@ 2015-10-08  4:32 Ajit Kumar Agarwal
  2015-10-08  4:59 ` Bin.Cheng
  2015-11-13  6:13 ` Jeff Law
  0 siblings, 2 replies; 14+ messages in thread
From: Ajit Kumar Agarwal @ 2015-10-08  4:32 UTC (permalink / raw)
  To: GCC Patches
  Cc: Vinod Kathail, Shail Aditya Gupta, Vidhumouli Hunsigida, Nagaraju Mekala

[-- Attachment #1: Type: text/plain, Size: 3159 bytes --]

Following Proposed:

Changes are done in the Loop Invariant(LICM) at RTL level and also the Induction variable optimization based on SSA representation. 
The current logic used in LICM for register used inside the loops is changed. The Live Out of the loop latch node and the Live in of the 
destination of the exit nodes is used to set the Loops Liveness at the exit of the Loop. The register used is the number of live variables 
at the exit of the Loop calculated above.

For Induction variable optimization on tree SSA representation, the register used logic is based on the number of phi nodes at the loop 
header to represent the liveness at the loop. Current Logic used only the number of phi nodes at the loop header. I have made changes
 to represent the phi operands also live at the loop. Thus number of phi operands also gets incremented in the number of registers used.

Performance runs:

Bootstrapping with i386 goes through fine. The spec cpu 2000 benchmarks is run and following performance runs and the code size for
 i386 target seen.

Ratio with the above optimization changes vs ratio without above optimizations for INT benchmarks (3785.261 vs 3783.064).
Ratio with the above optimization changes vs ratio without above optimization for FP benchmarks ( 4676.763189 vs 4676.072428 ).

Code size reduction for INT benchmarks : 2324 instructions.
Code size reduction for FP benchmarks : 1283 instructions.

For Microblaze target the Mibench and EEMBC benchmarks is run and the following improvements is seen.

(qos_lite(5.3%), consumer_jpeg_c(1.34%), security_rijndael_d(1.8%), security_rijndael_e(1.4%))

Code Size reduction for Mibench  = 16164 instructions.
Code Size reduction for EEMBC = 98 instructions.

Patch ChangeLog:

PATCH] [RFC, Patch]: Optimized changes in the register used inside  loop for LICM and IVOPTS.

Changes are done in the Loop Invariant(LICM) at RTL level and also the Induction variable optimization 
based on SSA representation. The current logic used in LICM for register used inside the loops is changed. 
The Live Out of the loop latch node and the Live in of the destination of the exit nodes is used to set the
 Loops Liveness at the exit of the Loop. The register used is the number of live variables at the exit of the
 Loop calculated above.

For Induction variable optimization on tree SSA representation, the register used logic is based on the
 number of phi nodes at the loop header to represent the liveness at the loop.  Current Logic used only
 the number of phi nodes at the loop header.  Changes are made to represent the phi operands also live
 at the loop. Thus number of phi operands also gets incremented in the number of registers used.

ChangeLog:
2015-10-09  Ajit Agarwal  <ajitkum@xilinx.com>

        * loop-invariant.c (compute_loop_liveness): New.
        (determine_regs_used): New.
        (find_invariants_to_move): Use of determine_regs_used.
        * tree-ssa-loop-ivopts.c (determine_set_costs): Consider the phi
        arguments for register used.

Signed-off-by:Ajit Agarwal ajitkum@xilinx.com

Thanks & Regards
Ajit

[-- Attachment #2: 0001-RFC-Patch-Optimized-changes-in-the-register-used-ins.patch --]
[-- Type: application/octet-stream, Size: 4674 bytes --]

From f164fd80953f3cffd96a492c8424c83290cd43cc Mon Sep 17 00:00:00 2001
From: Ajit Kumar Agarwal <ajitkum@xilix.com>
Date: Wed, 7 Oct 2015 20:50:40 +0200
Subject: [PATCH] [RFC, Patch]: Optimized changes in the register used inside
 loop for LICM and IVOPTS.

Changes are done in the Loop Invariant(LICM) at RTL level and also the
Induction variable optimization based on SSA representation. The current
logic used in LICM for register used inside the loops is changed. The
Live Out of the loop latch node and the Live in of the destination of
the exit nodes is used to set the Loops Liveness at the exit of the Loop.
The register used is the number of live variables at the exit of the
Loop calculated above.

For Induction variable optimization on tree SSA representation, the register
used logic is based on the number of phi nodes at the loop header to represent
the liveness at the loop.  Current Logic used only the number of phi nodes at
the loop header.  Changes are made to represent the phi operands also live at
the loop. Thus number of phi operands also gets incremented in the number of
registers used.

ChangeLog:
2015-10-09  Ajit Agarwal  <ajitkum@xilinx.com>

	* loop-invariant.c (compute_loop_liveness): New.
	(determine_regs_used): New.
	(find_invariants_to_move): Use of determine_regs_used.
	* tree-ssa-loop-ivopts.c (determine_set_costs): Consider the phi
	arguments for register used.

Signed-off-by:Ajit Agarwal ajitkum@xilinx.com
---
 gcc/loop-invariant.c       | 72 +++++++++++++++++++++++++++++++++++++---------
 gcc/tree-ssa-loop-ivopts.c |  4 +--
 2 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c
index 52c8ae8..e4291c9 100644
--- a/gcc/loop-invariant.c
+++ b/gcc/loop-invariant.c
@@ -1413,6 +1413,19 @@ set_move_mark (unsigned invno, int gain)
     }
 }
 
+static int
+determine_regs_used()
+{
+  unsigned int j;
+  unsigned int reg_used = 2;
+  bitmap_iterator bi;
+
+  EXECUTE_IF_SET_IN_BITMAP (&LOOP_DATA (curr_loop)->regs_live, 0, j, bi)
+    (reg_used) ++;
+
+  return reg_used;
+}
+
 /* Determines which invariants to move.  */
 
 static void
@@ -1433,18 +1446,7 @@ find_invariants_to_move (bool speed, bool call_p)
        registers used; we put some initial bound here to stand for
        induction variables etc.  that we do not detect.  */
     {
-      unsigned int n_regs = DF_REG_SIZE (df);
-
-      regs_used = 2;
-
-      for (i = 0; i < n_regs; i++)
-	{
-	  if (!DF_REGNO_FIRST_DEF (i) && DF_REGNO_LAST_USE (i))
-	    {
-	      /* This is a value that is used but not changed inside loop.  */
-	      regs_used++;
-	    }
-	}
+      regs_used = determine_regs_used();
     }
 
   if (! flag_ira_loop_pressure)
@@ -2055,9 +2057,43 @@ calculate_loop_reg_pressure (void)
     }
 }
 
-\f
+static void
+calculate_loop_liveness (void)
+{
+  basic_block bb;
+  struct loop *loop;
 
-/* Move the invariants out of the loops.  */
+  FOR_EACH_LOOP (loop, 0)
+    if (loop->aux == NULL)
+      {
+        loop->aux = xcalloc (1, sizeof (struct loop_data));
+        bitmap_initialize (&LOOP_DATA (loop)->regs_live, &reg_obstack);
+     }
+
+  FOR_EACH_BB_FN (bb, cfun)
+  {
+    curr_loop = bb->loop_father;
+    if (curr_loop == current_loops->tree_root)
+      continue;
+
+    for (loop = curr_loop;
+         loop != current_loops->tree_root;
+         loop = loop_outer (loop))
+       {
+         int  i;
+         edge e;
+         vec<edge> edges;
+         edges = get_loop_exit_edges (loop);
+         FOR_EACH_VEC_ELT (edges, i, e)
+         {
+           bitmap_ior_into (&LOOP_DATA (loop)->regs_live, DF_LR_OUT(e->src));
+           bitmap_ior_into (&LOOP_DATA (loop)->regs_live, DF_LR_IN(e->dest));
+         }
+      }
+  }
+}
+
+/* Move the invariants  ut of the loops.  */
 
 void
 move_loop_invariants (void)
@@ -2072,6 +2108,14 @@ move_loop_invariants (void)
       calculate_loop_reg_pressure ();
       regstat_free_n_sets_and_refs ();
     }
+  else
+    {
+      df_analyze();
+      regstat_init_n_sets_and_refs ();
+      calculate_loop_liveness();
+      regstat_free_n_sets_and_refs ();
+    }
+
   df_set_flags (DF_EQ_NOTES + DF_DEFER_INSN_RESCAN);
   /* Process the loops, innermost first.  */
   FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 945d34b..9d94c60 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -5736,8 +5736,8 @@ determine_set_costs (struct ivopts_data *data)
 
       if (get_iv (data, op))
 	continue;
-
-      n++;
+      
+      n += gimple_phi_num_args (phi);
     }
 
   EXECUTE_IF_SET_IN_BITMAP (data->relevant, 0, j, bi)
-- 
1.8.2.1


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

end of thread, other threads:[~2015-11-30 22:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08  4:32 [RFC, Patch]: Optimized changes in the register used inside loop for LICM and IVOPTS Ajit Kumar Agarwal
2015-10-08  4:59 ` Bin.Cheng
2015-10-08  5:54   ` Ajit Kumar Agarwal
2015-10-09  2:45     ` Bin.Cheng
2015-10-12  4:25       ` Ajit Kumar Agarwal
2015-11-13  6:13 ` Jeff Law
2015-11-13  6:32   ` Bin.Cheng
2015-11-13 10:18     ` Richard Biener
2015-11-16 17:36   ` Ajit Kumar Agarwal
2015-11-16 23:00     ` Jeff Law
2015-11-29 17:14       ` Ajit Kumar Agarwal
2015-11-30 22:31         ` Jeff Law
2015-11-16 17:57   ` Ajit Kumar Agarwal
2015-11-17  5:37     ` Bin.Cheng

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