+2016-11-21 Richard Sandiford <richard.sandiford@arm.com>
+
+ * tree-tailcall.c (process_assignment): Simplify the check for
+ a valid copy, allowing the source to be a local variable as
+ well as an SSA name.
+ (find_tail_calls): Allow copies between local variables to follow
+ the call. Allow the result to be stored in any local variable,
+ even if it's an aggregate.
+ (eliminate_tail_call): Check whether the result is an SSA name
+ before updating its SSA_NAME_DEF_STMT.
+
2016-11-21 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/78324
conversions that can never produce extra code between the function
call and the function return. */
if ((rhs_class == GIMPLE_SINGLE_RHS || gimple_assign_cast_p (stmt))
- && (TREE_CODE (src_var) == SSA_NAME))
+ && src_var == *ass_var)
{
/* Reject a tailcall if the type conversion might need
additional code. */
return false;
}
- if (src_var != *ass_var)
- return false;
-
*ass_var = dest;
return true;
}
break;
}
+ /* Allow simple copies between local variables, even if they're
+ aggregates. */
+ if (is_gimple_assign (stmt)
+ && auto_var_in_fn_p (gimple_assign_lhs (stmt), cfun->decl)
+ && auto_var_in_fn_p (gimple_assign_rhs1 (stmt), cfun->decl))
+ continue;
+
/* If the statement references memory or volatile operands, fail. */
if (gimple_references_memory_p (stmt)
|| gimple_has_volatile_ops (stmt))
return;
}
- /* If the LHS of our call is not just a simple register, we can't
- transform this into a tail or sibling call. This situation happens,
- in (e.g.) "*p = foo()" where foo returns a struct. In this case
- we won't have a temporary here, but we need to carry out the side
- effect anyway, so tailcall is impossible.
+ /* If the LHS of our call is not just a simple register or local
+ variable, we can't transform this into a tail or sibling call.
+ This situation happens, in (e.g.) "*p = foo()" where foo returns a
+ struct. In this case we won't have a temporary here, but we need
+ to carry out the side effect anyway, so tailcall is impossible.
??? In some situations (when the struct is returned in memory via
invisible argument) we could deal with this, e.g. by passing 'p'
itself as that argument to foo, but it's too early to do this here,
and expand_call() will not handle it anyway. If it ever can, then
we need to revisit this here, to allow that situation. */
- if (ass_var && !is_gimple_reg (ass_var))
+ if (ass_var
+ && !is_gimple_reg (ass_var)
+ && !auto_var_in_fn_p (ass_var, cfun->decl))
return;
/* We found the call, check whether it is suitable. */
call = gsi_stmt (t->call_gsi);
rslt = gimple_call_lhs (call);
- if (rslt != NULL_TREE)
+ if (rslt != NULL_TREE && TREE_CODE (rslt) == SSA_NAME)
{
/* Result of the call will no longer be defined. So adjust the
SSA_NAME_DEF_STMT accordingly. */