Commit 04b80dbb by Richard Sandiford Committed by Richard Sandiford

gcc/

	* builtins.c (expand_builtin_mathfn, expand_builtin_mathfn_2)
	(expand_builtin_mathfn_ternary, expand_builtin_mathfn_3)
	(expand_builtin_int_roundingfn_2): Keep the original target around
	for the fallback case.

From-SVN: r194801
parent 635b0b0c
2013-01-02 Richard Sandiford <rdsandiford@googlemail.com> 2013-01-02 Richard Sandiford <rdsandiford@googlemail.com>
* builtins.c (expand_builtin_mathfn, expand_builtin_mathfn_2)
(expand_builtin_mathfn_ternary, expand_builtin_mathfn_3)
(expand_builtin_int_roundingfn_2): Keep the original target around
for the fallback case.
2013-01-02 Richard Sandiford <rdsandiford@googlemail.com>
* tree-vrp.c (range_fits_type_p): Require the MSB of the double_int * tree-vrp.c (range_fits_type_p): Require the MSB of the double_int
to be clear for sign changes. to be clear for sign changes.
...@@ -2031,7 +2031,7 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget) ...@@ -2031,7 +2031,7 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget)
if (optab_handler (builtin_optab, mode) != CODE_FOR_nothing if (optab_handler (builtin_optab, mode) != CODE_FOR_nothing
&& (!errno_set || !optimize_insn_for_size_p ())) && (!errno_set || !optimize_insn_for_size_p ()))
{ {
target = gen_reg_rtx (mode); rtx result = gen_reg_rtx (mode);
/* Wrap the computation of the argument in a SAVE_EXPR, as we may /* Wrap the computation of the argument in a SAVE_EXPR, as we may
need to expand the argument again. This way, we will not perform need to expand the argument again. This way, we will not perform
...@@ -2042,20 +2042,20 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget) ...@@ -2042,20 +2042,20 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget)
start_sequence (); start_sequence ();
/* Compute into TARGET. /* Compute into RESULT.
Set TARGET to wherever the result comes back. */ Set RESULT to wherever the result comes back. */
target = expand_unop (mode, builtin_optab, op0, target, 0); result = expand_unop (mode, builtin_optab, op0, result, 0);
if (target != 0) if (result != 0)
{ {
if (errno_set) if (errno_set)
expand_errno_check (exp, target); expand_errno_check (exp, result);
/* Output the entire sequence. */ /* Output the entire sequence. */
insns = get_insns (); insns = get_insns ();
end_sequence (); end_sequence ();
emit_insn (insns); emit_insn (insns);
return target; return result;
} }
/* If we were unable to expand via the builtin, stop the sequence /* If we were unable to expand via the builtin, stop the sequence
...@@ -2078,7 +2078,7 @@ static rtx ...@@ -2078,7 +2078,7 @@ static rtx
expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget) expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget)
{ {
optab builtin_optab; optab builtin_optab;
rtx op0, op1, insns; rtx op0, op1, insns, result;
int op1_type = REAL_TYPE; int op1_type = REAL_TYPE;
tree fndecl = get_callee_fndecl (exp); tree fndecl = get_callee_fndecl (exp);
tree arg0, arg1; tree arg0, arg1;
...@@ -2134,7 +2134,7 @@ expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget) ...@@ -2134,7 +2134,7 @@ expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget)
if (optab_handler (builtin_optab, mode) == CODE_FOR_nothing) if (optab_handler (builtin_optab, mode) == CODE_FOR_nothing)
return NULL_RTX; return NULL_RTX;
target = gen_reg_rtx (mode); result = gen_reg_rtx (mode);
if (! flag_errno_math || ! HONOR_NANS (mode)) if (! flag_errno_math || ! HONOR_NANS (mode))
errno_set = false; errno_set = false;
...@@ -2151,29 +2151,29 @@ expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget) ...@@ -2151,29 +2151,29 @@ expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget)
start_sequence (); start_sequence ();
/* Compute into TARGET. /* Compute into RESULT.
Set TARGET to wherever the result comes back. */ Set RESULT to wherever the result comes back. */
target = expand_binop (mode, builtin_optab, op0, op1, result = expand_binop (mode, builtin_optab, op0, op1,
target, 0, OPTAB_DIRECT); result, 0, OPTAB_DIRECT);
/* If we were unable to expand via the builtin, stop the sequence /* If we were unable to expand via the builtin, stop the sequence
(without outputting the insns) and call to the library function (without outputting the insns) and call to the library function
with the stabilized argument list. */ with the stabilized argument list. */
if (target == 0) if (result == 0)
{ {
end_sequence (); end_sequence ();
return expand_call (exp, target, target == const0_rtx); return expand_call (exp, target, target == const0_rtx);
} }
if (errno_set) if (errno_set)
expand_errno_check (exp, target); expand_errno_check (exp, result);
/* Output the entire sequence. */ /* Output the entire sequence. */
insns = get_insns (); insns = get_insns ();
end_sequence (); end_sequence ();
emit_insn (insns); emit_insn (insns);
return target; return result;
} }
/* Expand a call to the builtin trinary math functions (fma). /* Expand a call to the builtin trinary math functions (fma).
...@@ -2187,7 +2187,7 @@ static rtx ...@@ -2187,7 +2187,7 @@ static rtx
expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget) expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget)
{ {
optab builtin_optab; optab builtin_optab;
rtx op0, op1, op2, insns; rtx op0, op1, op2, insns, result;
tree fndecl = get_callee_fndecl (exp); tree fndecl = get_callee_fndecl (exp);
tree arg0, arg1, arg2; tree arg0, arg1, arg2;
enum machine_mode mode; enum machine_mode mode;
...@@ -2214,7 +2214,7 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget) ...@@ -2214,7 +2214,7 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget)
if (optab_handler (builtin_optab, mode) == CODE_FOR_nothing) if (optab_handler (builtin_optab, mode) == CODE_FOR_nothing)
return NULL_RTX; return NULL_RTX;
target = gen_reg_rtx (mode); result = gen_reg_rtx (mode);
/* Always stabilize the argument list. */ /* Always stabilize the argument list. */
CALL_EXPR_ARG (exp, 0) = arg0 = builtin_save_expr (arg0); CALL_EXPR_ARG (exp, 0) = arg0 = builtin_save_expr (arg0);
...@@ -2227,15 +2227,15 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget) ...@@ -2227,15 +2227,15 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget)
start_sequence (); start_sequence ();
/* Compute into TARGET. /* Compute into RESULT.
Set TARGET to wherever the result comes back. */ Set RESULT to wherever the result comes back. */
target = expand_ternary_op (mode, builtin_optab, op0, op1, op2, result = expand_ternary_op (mode, builtin_optab, op0, op1, op2,
target, 0); result, 0);
/* If we were unable to expand via the builtin, stop the sequence /* If we were unable to expand via the builtin, stop the sequence
(without outputting the insns) and call to the library function (without outputting the insns) and call to the library function
with the stabilized argument list. */ with the stabilized argument list. */
if (target == 0) if (result == 0)
{ {
end_sequence (); end_sequence ();
return expand_call (exp, target, target == const0_rtx); return expand_call (exp, target, target == const0_rtx);
...@@ -2246,7 +2246,7 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget) ...@@ -2246,7 +2246,7 @@ expand_builtin_mathfn_ternary (tree exp, rtx target, rtx subtarget)
end_sequence (); end_sequence ();
emit_insn (insns); emit_insn (insns);
return target; return result;
} }
/* Expand a call to the builtin sin and cos math functions. /* Expand a call to the builtin sin and cos math functions.
...@@ -2298,7 +2298,7 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget) ...@@ -2298,7 +2298,7 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget)
/* Before working hard, check whether the instruction is available. */ /* Before working hard, check whether the instruction is available. */
if (optab_handler (builtin_optab, mode) != CODE_FOR_nothing) if (optab_handler (builtin_optab, mode) != CODE_FOR_nothing)
{ {
target = gen_reg_rtx (mode); rtx result = gen_reg_rtx (mode);
/* Wrap the computation of the argument in a SAVE_EXPR, as we may /* Wrap the computation of the argument in a SAVE_EXPR, as we may
need to expand the argument again. This way, we will not perform need to expand the argument again. This way, we will not perform
...@@ -2309,37 +2309,35 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget) ...@@ -2309,37 +2309,35 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget)
start_sequence (); start_sequence ();
/* Compute into TARGET. /* Compute into RESULT.
Set TARGET to wherever the result comes back. */ Set RESULT to wherever the result comes back. */
if (builtin_optab == sincos_optab) if (builtin_optab == sincos_optab)
{ {
int result; int ok;
switch (DECL_FUNCTION_CODE (fndecl)) switch (DECL_FUNCTION_CODE (fndecl))
{ {
CASE_FLT_FN (BUILT_IN_SIN): CASE_FLT_FN (BUILT_IN_SIN):
result = expand_twoval_unop (builtin_optab, op0, 0, target, 0); ok = expand_twoval_unop (builtin_optab, op0, 0, result, 0);
break; break;
CASE_FLT_FN (BUILT_IN_COS): CASE_FLT_FN (BUILT_IN_COS):
result = expand_twoval_unop (builtin_optab, op0, target, 0, 0); ok = expand_twoval_unop (builtin_optab, op0, result, 0, 0);
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
} }
gcc_assert (result); gcc_assert (ok);
} }
else else
{ result = expand_unop (mode, builtin_optab, op0, result, 0);
target = expand_unop (mode, builtin_optab, op0, target, 0);
}
if (target != 0) if (result != 0)
{ {
/* Output the entire sequence. */ /* Output the entire sequence. */
insns = get_insns (); insns = get_insns ();
end_sequence (); end_sequence ();
emit_insn (insns); emit_insn (insns);
return target; return result;
} }
/* If we were unable to expand via the builtin, stop the sequence /* If we were unable to expand via the builtin, stop the sequence
...@@ -2348,9 +2346,7 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget) ...@@ -2348,9 +2346,7 @@ expand_builtin_mathfn_3 (tree exp, rtx target, rtx subtarget)
end_sequence (); end_sequence ();
} }
target = expand_call (exp, target, target == const0_rtx); return expand_call (exp, target, target == const0_rtx);
return target;
} }
/* Given an interclass math builtin decl FNDECL and it's argument ARG /* Given an interclass math builtin decl FNDECL and it's argument ARG
...@@ -2819,7 +2815,7 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target) ...@@ -2819,7 +2815,7 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target)
/* There's no easy way to detect the case we need to set EDOM. */ /* There's no easy way to detect the case we need to set EDOM. */
if (!flag_errno_math) if (!flag_errno_math)
{ {
target = gen_reg_rtx (mode); rtx result = gen_reg_rtx (mode);
/* Wrap the computation of the argument in a SAVE_EXPR, as we may /* Wrap the computation of the argument in a SAVE_EXPR, as we may
need to expand the argument again. This way, we will not perform need to expand the argument again. This way, we will not perform
...@@ -2830,13 +2826,13 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target) ...@@ -2830,13 +2826,13 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target)
start_sequence (); start_sequence ();
if (expand_sfix_optab (target, op0, builtin_optab)) if (expand_sfix_optab (result, op0, builtin_optab))
{ {
/* Output the entire sequence. */ /* Output the entire sequence. */
insns = get_insns (); insns = get_insns ();
end_sequence (); end_sequence ();
emit_insn (insns); emit_insn (insns);
return target; return result;
} }
/* If we were unable to expand via the builtin, stop the sequence /* If we were unable to expand via the builtin, stop the sequence
...@@ -2863,9 +2859,7 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target) ...@@ -2863,9 +2859,7 @@ expand_builtin_int_roundingfn_2 (tree exp, rtx target)
return convert_to_mode (mode, target, 0); return convert_to_mode (mode, target, 0);
} }
target = expand_call (exp, target, target == const0_rtx); return expand_call (exp, target, target == const0_rtx);
return target;
} }
/* Expand a call to the powi built-in mathematical function. Return NULL_RTX if /* Expand a call to the powi built-in mathematical function. Return NULL_RTX if
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment