diff mbox

[sh] Add flag_unsafe_math_optimizations to sincossf3

Message ID 87d1vmos7v.fsf@e105548-lin.cambridge.arm.com
State New
Headers show

Commit Message

Richard Sandiford Nov. 7, 2015, 1:27 p.m. UTC
builtins.c uses the following code to guard expansions involving optabs:

    CASE_FLT_FN (BUILT_IN_EXP):
    CASE_FLT_FN (BUILT_IN_EXP10):
    CASE_FLT_FN (BUILT_IN_POW10):
    CASE_FLT_FN (BUILT_IN_EXP2):
    CASE_FLT_FN (BUILT_IN_EXPM1):
    CASE_FLT_FN (BUILT_IN_LOGB):
    CASE_FLT_FN (BUILT_IN_LOG):
    CASE_FLT_FN (BUILT_IN_LOG10):
    CASE_FLT_FN (BUILT_IN_LOG2):
    CASE_FLT_FN (BUILT_IN_LOG1P):
    CASE_FLT_FN (BUILT_IN_TAN):
    CASE_FLT_FN (BUILT_IN_ASIN):
    CASE_FLT_FN (BUILT_IN_ACOS):
    CASE_FLT_FN (BUILT_IN_ATAN):
    CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
      /* Treat these like sqrt only if unsafe math optimizations are allowed,
	 because of possible accuracy problems.  */
      if (! flag_unsafe_math_optimizations)
	break;
    [...]
    CASE_FLT_FN (BUILT_IN_ILOGB):
      if (! flag_unsafe_math_optimizations)
	break;
    [...]
    CASE_FLT_FN (BUILT_IN_ATAN2):
    CASE_FLT_FN (BUILT_IN_LDEXP):
    CASE_FLT_FN (BUILT_IN_SCALB):
    CASE_FLT_FN (BUILT_IN_SCALBN):
    CASE_FLT_FN (BUILT_IN_SCALBLN):
      if (! flag_unsafe_math_optimizations)
	break;
    [...]
    CASE_FLT_FN (BUILT_IN_SIN):
    CASE_FLT_FN (BUILT_IN_COS):
      if (! flag_unsafe_math_optimizations)
	break;
    [...]
    CASE_FLT_FN (BUILT_IN_SINCOS):
      if (! flag_unsafe_math_optimizations)
	break;

I think it's really up to the optab to decide whether it's safe
for !flag_unsafe_math_optimizations or not, and AFAICT, all optabs
but sh.md:sincossf3 already check.  This patch makes the sh pattern
check too.

Tested on sh-elf.  OK to install?

Thanks,
Richard


gcc/
	* config/sh/sh.md (sincossf3): Require flag_unsafe_math_optimizations.

Comments

Oleg Endo Nov. 7, 2015, 1:34 p.m. UTC | #1
On Sat, 2015-11-07 at 13:27 +0000, Richard Sandiford wrote:
> builtins.c uses the following code to guard expansions involving
> optabs:
> 
>     CASE_FLT_FN (BUILT_IN_EXP):
>     CASE_FLT_FN (BUILT_IN_EXP10):
>     CASE_FLT_FN (BUILT_IN_POW10):
>     CASE_FLT_FN (BUILT_IN_EXP2):
>     CASE_FLT_FN (BUILT_IN_EXPM1):
>     CASE_FLT_FN (BUILT_IN_LOGB):
>     CASE_FLT_FN (BUILT_IN_LOG):
>     CASE_FLT_FN (BUILT_IN_LOG10):
>     CASE_FLT_FN (BUILT_IN_LOG2):
>     CASE_FLT_FN (BUILT_IN_LOG1P):
>     CASE_FLT_FN (BUILT_IN_TAN):
>     CASE_FLT_FN (BUILT_IN_ASIN):
>     CASE_FLT_FN (BUILT_IN_ACOS):
>     CASE_FLT_FN (BUILT_IN_ATAN):
>     CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
>       /* Treat these like sqrt only if unsafe math optimizations are
> allowed,
> 	 because of possible accuracy problems.  */
>       if (! flag_unsafe_math_optimizations)
> 	break;
>     [...]
>     CASE_FLT_FN (BUILT_IN_ILOGB):
>       if (! flag_unsafe_math_optimizations)
> 	break;
>     [...]
>     CASE_FLT_FN (BUILT_IN_ATAN2):
>     CASE_FLT_FN (BUILT_IN_LDEXP):
>     CASE_FLT_FN (BUILT_IN_SCALB):
>     CASE_FLT_FN (BUILT_IN_SCALBN):
>     CASE_FLT_FN (BUILT_IN_SCALBLN):
>       if (! flag_unsafe_math_optimizations)
> 	break;
>     [...]
>     CASE_FLT_FN (BUILT_IN_SIN):
>     CASE_FLT_FN (BUILT_IN_COS):
>       if (! flag_unsafe_math_optimizations)
> 	break;
>     [...]
>     CASE_FLT_FN (BUILT_IN_SINCOS):
>       if (! flag_unsafe_math_optimizations)
> 	break;
> 
> I think it's really up to the optab to decide whether it's safe
> for !flag_unsafe_math_optimizations or not, and AFAICT, all optabs
> but sh.md:sincossf3 already check.  This patch makes the sh pattern
> check too.

In sh.c (sh_option_override) TARGET_FSCA is enabled only when
 flag_unsafe_math_optimizations != 0.  Thus another check in the
patterns is not done.  However, there is PR 67723 and the fix for it
will probably be checking all the necessary flags in the pattern
conditions or something like that.  Thus, please feel free to commit.

Cheers,
Oleg
diff mbox

Patch

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 557a0f0..0c3b9f2 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -13722,7 +13722,7 @@  label:
 	(unspec:SF [(match_operand:SF 2 "fp_arith_reg_operand")] UNSPEC_FCOSA))
    (set (match_operand:SF 1 "nonimmediate_operand")
 	(unspec:SF [(match_dup 2)] UNSPEC_FSINA))]
-  "TARGET_FPU_ANY && TARGET_FSCA"
+  "TARGET_FPU_ANY && TARGET_FSCA && flag_unsafe_math_optimizations"
 {
   rtx scaled = gen_reg_rtx (SFmode);
   rtx truncated = gen_reg_rtx (SImode);