This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Remove parameters after converting call to gcc_unreachable
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: gcc-patches at gcc dot gnu dot org, jakub at redhat dot com
- Date: Wed, 4 Feb 2015 20:47:20 +0100
- Subject: Remove parameters after converting call to gcc_unreachable
- Authentication-results: sourceware.org; auth=none
Hi,
this is second attempt to fix the issue with arguments being passed
to builtlin_unreachable after https://gcc.gnu.org/ml/gcc-patches/2014-12/msg01025.html
As suggested, I fixup the IL right after redirection instead waiting for tree-ssa-dce.
Bootstrapped/regtested x86_64-linux, OK?
PR middle-end/64922
* gimple.c: Include gimple-ssa.h
(maybe_remove_unused_call_args): New function.
* gimple.h (maybe_remove_unused_call_args): Declare.
* craph.c (cgraph_edge::redirect_call_stmt_to_callee): Use it.
* tree-ssa-pre.c (eliminate_dom_walker::before_dom_children): Likewise.
* gimple-fold.c (gimple_fold_call): Likewise.
Index: gimple.c
===================================================================
--- gimple.c (revision 220411)
+++ gimple.c (working copy)
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.
#include "ipa-ref.h"
#include "lto-streamer.h"
#include "cgraph.h"
+#include "gimple-ssa.h"
/* All the tuples have their operand vector (if present) at the very bottom
@@ -2950,3 +2951,20 @@ gimple_seq_discard (gimple_seq seq)
ggc_free (stmt);
}
}
+
+/* See if STMT now calls function that takes no parameters and if so, drop
+ call arguments. This is used when devirtualization machinery redirects
+ to __builtiln_unreacahble or __cfa_pure_virutal. */
+
+void
+maybe_remove_unused_call_args (struct function *fn, gimple stmt)
+{
+ tree decl = gimple_call_fndecl (stmt);
+ if (TYPE_ARG_TYPES (TREE_TYPE (decl))
+ && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))) == void_type_node
+ && gimple_call_num_args (stmt))
+ {
+ gimple_set_num_ops (stmt, 3);
+ update_stmt_fn (fn, stmt);
+ }
+}
Index: gimple.h
===================================================================
--- gimple.h (revision 220411)
+++ gimple.h (working copy)
@@ -1404,6 +1404,7 @@ extern void sort_case_labels (vec<tree>)
extern void preprocess_case_label_vec_for_gimple (vec<tree>, tree, tree *);
extern void gimple_seq_set_location (gimple_seq, location_t);
extern void gimple_seq_discard (gimple_seq);
+extern void maybe_remove_unused_call_args (struct function *, gimple);
/* Formal (expression) temporary table handling: multiple occurrences of
the same scalar expression are evaluated into the same temporary. */
Index: cgraph.c
===================================================================
--- cgraph.c (revision 220411)
+++ cgraph.c (working copy)
@@ -1324,7 +1324,8 @@ cgraph_edge::redirect_call_stmt_to_calle
(int64_t)e->count);
gcc_assert (e2->speculative);
push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
- new_stmt = gimple_ic (e->call_stmt, dyn_cast<cgraph_node *> (ref->referred),
+ new_stmt = gimple_ic (e->call_stmt,
+ dyn_cast<cgraph_node *> (ref->referred),
e->count || e2->count
? RDIV (e->count * REG_BR_PROB_BASE,
e->count + e2->count)
@@ -1464,6 +1465,9 @@ cgraph_edge::redirect_call_stmt_to_calle
update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
}
+ maybe_remove_unused_call_args (DECL_STRUCT_FUNCTION (e->caller->decl),
+ new_stmt);
+
e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt, false);
if (symtab->dump_file)
Index: tree-ssa-pre.c
===================================================================
--- tree-ssa-pre.c (revision 220411)
+++ tree-ssa-pre.c (working copy)
@@ -4406,6 +4406,7 @@ eliminate_dom_walker::before_dom_childre
cgraph_node::get (fn)->name ());
}
gimple_call_set_fndecl (call_stmt, fn);
+ maybe_remove_unused_call_args (cfun, call_stmt);
gimple_set_modified (stmt, true);
}
}
Index: gimple-fold.c
===================================================================
--- gimple-fold.c (revision 220411)
+++ gimple-fold.c (working copy)
@@ -3120,6 +3120,7 @@ gimple_fold_call (gimple_stmt_iterator *
}
gimple_call_set_lhs (stmt, NULL_TREE);
}
+ maybe_remove_unused_call_args (cfun, stmt);
}
else
{