This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix call-cdce (PR tree-optimization/37353)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 9 Sep 2008 17:56:09 -0400
- Subject: [PATCH] Fix call-cdce (PR tree-optimization/37353)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The testcase below ICEs, because tree-call-cdce.c VEC_alloc a 64 entry
vector and then VEC_quick_pushes all the call-cdce candidate GIMPLE_CALLs
into it, which obviously breaks if there are more than 64 such calls.
While it could be fixed just by using VEC_safe_push instead of
VEC_quick_push, while touching it I took the liberty to do a few cleanups as
well - I see no reason why we need to use a global variable for the vector,
and we can/should IMHO in the common case when there are no such calls in
the whole function save a heap VEC_alloc/VEC_free.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2008-09-09 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/37353
* tree-call-cdce.c (cond_dead_built_in_calls): Remove.
(shrink_wrap_conditional_dead_built_in_calls): Add calls argument, use
calls instead of cond_dead_built_in_calls.
(tree_call_cdce): Add cond_dead_built_in_calls automatic variable,
initalize the vector only before adding first entry. Use VEC_safe_push
instead of VEC_quick_push. Pass cond_dead_built_in_calls to
shrink_wrap_conditional_dead_built_in_calls call.
* gcc.dg/pr37353.c: New test.
--- gcc/tree-call-cdce.c.jj 2008-09-05 12:56:32.000000000 +0200
+++ gcc/tree-call-cdce.c 2008-09-09 21:50:23.000000000 +0200
@@ -99,8 +99,6 @@ typedef struct input_domain
bool is_ub_inclusive;
} inp_domain;
-static VEC (gimple, heap) *cond_dead_built_in_calls;
-
/* A helper function to construct and return an input
domain object. LB is the lower bound, HAS_LB is
a boolean flag indicating if the lower bound exists,
@@ -844,18 +842,18 @@ shrink_wrap_one_built_in_call (gimple bi
wrapping transformation. */
static bool
-shrink_wrap_conditional_dead_built_in_calls (void)
+shrink_wrap_conditional_dead_built_in_calls (VEC (gimple, heap) *calls)
{
bool changed = false;
unsigned i = 0;
- unsigned n = VEC_length (gimple, cond_dead_built_in_calls);
+ unsigned n = VEC_length (gimple, calls);
if (n == 0)
return false;
for (; i < n ; i++)
{
- gimple bi_call = VEC_index (gimple, cond_dead_built_in_calls, i);
+ gimple bi_call = VEC_index (gimple, calls, i);
changed |= shrink_wrap_one_built_in_call (bi_call);
}
@@ -870,8 +868,7 @@ tree_call_cdce (void)
basic_block bb;
gimple_stmt_iterator i;
bool something_changed = false;
- cond_dead_built_in_calls = VEC_alloc (gimple, heap, 64);
-
+ VEC (gimple, heap) *cond_dead_built_in_calls = NULL;
FOR_EACH_BB (bb)
{
/* Collect dead call candidates. */
@@ -887,12 +884,18 @@ tree_call_cdce (void)
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
fprintf (dump_file, "\n");
}
- VEC_quick_push (gimple, cond_dead_built_in_calls, stmt);
+ if (cond_dead_built_in_calls == NULL)
+ cond_dead_built_in_calls = VEC_alloc (gimple, heap, 64);
+ VEC_safe_push (gimple, heap, cond_dead_built_in_calls, stmt);
}
}
}
- something_changed = shrink_wrap_conditional_dead_built_in_calls ();
+ if (cond_dead_built_in_calls == NULL)
+ return 0;
+
+ something_changed
+ = shrink_wrap_conditional_dead_built_in_calls (cond_dead_built_in_calls);
VEC_free (gimple, heap, cond_dead_built_in_calls);
--- gcc/testsuite/gcc.dg/pr37353.c.jj 2008-09-09 21:32:16.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr37353.c 2008-09-09 21:31:59.000000000 +0200
@@ -0,0 +1,15 @@
+/* PR tree-optimization/37353 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern double exp (double);
+
+#define A exp (arg);
+#define B A A A A A A A A A A
+#define C B B B B B B B B B B
+
+void
+foo (double arg)
+{
+ C
+}
Jakub