This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Dead store elimination for local memory references
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Jun 2003 00:35:56 +0200
- Subject: [PATCH] Dead store elimination for local memory references
Hello,
this patch makes store motion to remove unused stores to local
variables. It bootstraps it on amd64; on the other hand I am
not really at all sure whether the local_variable_p is correct.
Zdenek
Changelog:
* gcse.c (local_variable_p): New static function.
(build_store_vectors): Arrange for ellimination of dead local memory
references.
Index: gcse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcse.c,v
retrieving revision 1.250
diff -c -3 -p -r1.250 gcse.c
*** gcse.c 12 Jun 2003 04:15:56 -0000 1.250
--- gcse.c 19 Jun 2003 20:34:26 -0000
*************** static void find_moveable_store PARAMS
*** 687,692 ****
--- 687,693 ----
static int compute_store_table PARAMS ((void));
static bool load_kills_store PARAMS ((rtx, rtx));
static bool find_loads PARAMS ((rtx, rtx));
+ static bool local_variable_p (struct ls_expr *ptr);
static bool store_killed_in_insn PARAMS ((rtx, rtx, rtx));
static bool store_killed_after PARAMS ((rtx, rtx, rtx, basic_block,
int *, rtx *));
*************** find_loads (x, store_pattern)
*** 7441,7446 ****
--- 7442,7466 ----
return ret;
}
+ /* Checks if mem in PTR corresponds to a local variable. */
+ static bool
+ local_variable_p (struct ls_expr *ptr)
+ {
+ rtx reg, base;
+
+ for (reg = ptr->pattern_regs; reg; reg = XEXP (reg, 1))
+ {
+ base = find_base_term (XEXP (reg, 0));
+ if (base
+ && GET_CODE (base) == ADDRESS
+ && GET_MODE (base) == Pmode
+ && XEXP (base, 0) == frame_pointer_rtx)
+ return true;
+ }
+
+ return false;
+ }
+
/* Check if INSN kills the store pattern X (is aliased with it).
Return true if it it does. */
*************** static void
*** 7550,7555 ****
--- 7570,7576 ----
build_store_vectors ()
{
basic_block bb;
+ edge e;
int *regs_set_in_block;
rtx insn, st;
struct ls_expr * ptr;
*************** build_store_vectors ()
*** 7621,7626 ****
--- 7642,7666 ----
}
}
+ for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
+ {
+ bb = e->src;
+ if (bb->succ->succ_next)
+ continue;
+
+ for (ptr = first_ls_expr (); ptr != NULL; ptr = next_ls_expr (ptr))
+ {
+ /* If this is a reference to a local variable, add the fake store
+ before end of function. This takes care of dead code ellimination
+ for them. */
+ if (!local_variable_p (ptr))
+ continue;
+
+ if (!TEST_BIT (ae_kill[bb->index], ptr->index))
+ SET_BIT (st_antloc[bb->index], ptr->index);
+ }
+ }
+
free (regs_set_in_block);
if (gcse_file)