optabs.h (enum optab_index): Add new OTI_tan and OTI_atan.
authorRoger Sayle <roger@eyesopen.com>
Mon, 16 Jun 2003 12:53:16 +0000 (12:53 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 16 Jun 2003 12:53:16 +0000 (12:53 +0000)
* optabs.h (enum optab_index): Add new OTI_tan and OTI_atan.
(tan_optab, atan_optab): Define corresponding macros.
* optabs.c (init_optabs): Initialize tan_optab and atan_optab.
* genopinit.c (optabs): Implement tan_optab and atan_optab
using tan?f2 and atan?f2 patterns.
* builtins.c (expand_builtin_mathfn): Handle BUILT_IN_TAN{,F,L}
using tan_optab, and BUILT_IN_ATAN{,F,L} using atan_optab.
Change the default value of errno_set to false.
(expand_builtin): Expand BUILT_IN_TAN{,F,L} and BUILT_IN_ATAN{,F,L}
using expand_builtin_mathfn.

* config/i386/i386.md (atansf2, atandf2, atanxf2, atantf2): New
expander patterns implemented using existing atan2?f3 patterns.

* gcc.dg/i386-387-5.c: New test case.
* gcc.dg/i386-387-6.c: New test case.
* gcc.dg/builtins-23.c: New test case.

From-SVN: r68013

gcc/ChangeLog
gcc/builtins.c
gcc/config/i386/i386.md
gcc/genopinit.c
gcc/optabs.c
gcc/optabs.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-23.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/i386-387-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/i386-387-6.c [new file with mode: 0644]

index 85934ffc5a015a3b5e76044a428e7e37dff9a14d..0cd54a086426c2ead46a00b207cef0a3d36276d7 100644 (file)
@@ -1,3 +1,19 @@
+2003-06-16  Roger Sayle  <roger@eyesopen.com>
+
+       * optabs.h (enum optab_index): Add new OTI_tan and OTI_atan.
+       (tan_optab, atan_optab): Define corresponding macros.
+       * optabs.c (init_optabs): Initialize tan_optab and atan_optab.
+       * genopinit.c (optabs): Implement tan_optab and atan_optab
+       using tan?f2 and atan?f2 patterns.
+       * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_TAN{,F,L}
+       using tan_optab, and BUILT_IN_ATAN{,F,L} using atan_optab.
+       Change the default value of errno_set to false.
+       (expand_builtin): Expand BUILT_IN_TAN{,F,L} and BUILT_IN_ATAN{,F,L}
+       using expand_builtin_mathfn.
+
+       * config/i386/i386.md (atansf2, atandf2, atanxf2, atantf2): New
+       expander patterns implemented using existing atan2?f3 patterns.
+
 2003-06-16  Roger Sayle  <roger@eyesopen.com>
 
        * expr.c (expand_expr <PLUS_EXPR>): If operand_equal_p considers
index 83797491c5d47a67b18c86e40341cb57cf47569f..efc808d9081a310791c01f580223b42d84931a68 100644 (file)
@@ -1702,7 +1702,7 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget)
   tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
   tree arglist = TREE_OPERAND (exp, 1);
   enum machine_mode argmode;
-  bool errno_set = true;
+  bool errno_set = false;
 
   if (!validate_arglist (arglist, REAL_TYPE, VOID_TYPE))
     return 0;
@@ -1744,35 +1744,43 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget)
     case BUILT_IN_SQRT:
     case BUILT_IN_SQRTF:
     case BUILT_IN_SQRTL:
-      builtin_optab = sqrt_optab; break;
+      errno_set = true; builtin_optab = sqrt_optab; break;
     case BUILT_IN_EXP:
     case BUILT_IN_EXPF:
     case BUILT_IN_EXPL:
-      builtin_optab = exp_optab; break;
+      errno_set = true; builtin_optab = exp_optab; break;
     case BUILT_IN_LOG:
     case BUILT_IN_LOGF:
     case BUILT_IN_LOGL:
-      builtin_optab = log_optab; break;
+      errno_set = true; builtin_optab = log_optab; break;
+    case BUILT_IN_TAN:
+    case BUILT_IN_TANF:
+    case BUILT_IN_TANL:
+      builtin_optab = tan_optab; break;
+    case BUILT_IN_ATAN:
+    case BUILT_IN_ATANF:
+    case BUILT_IN_ATANL:
+      builtin_optab = atan_optab; break;
     case BUILT_IN_FLOOR:
     case BUILT_IN_FLOORF:
     case BUILT_IN_FLOORL:
-      errno_set = false ; builtin_optab = floor_optab; break;
+      builtin_optab = floor_optab; break;
     case BUILT_IN_CEIL:
     case BUILT_IN_CEILF:
     case BUILT_IN_CEILL:
-      errno_set = false ; builtin_optab = ceil_optab; break;
+      builtin_optab = ceil_optab; break;
     case BUILT_IN_TRUNC:
     case BUILT_IN_TRUNCF:
     case BUILT_IN_TRUNCL:
-      errno_set = false ; builtin_optab = trunc_optab; break;
+      builtin_optab = trunc_optab; break;
     case BUILT_IN_ROUND:
     case BUILT_IN_ROUNDF:
     case BUILT_IN_ROUNDL:
-      errno_set = false ; builtin_optab = round_optab; break;
+      builtin_optab = round_optab; break;
     case BUILT_IN_NEARBYINT:
     case BUILT_IN_NEARBYINTF:
     case BUILT_IN_NEARBYINTL:
-      errno_set = false ; builtin_optab = nearbyint_optab; break;
+      builtin_optab = nearbyint_optab; break;
     default:
       abort ();
     }
@@ -4416,6 +4424,12 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
     case BUILT_IN_LOG:
     case BUILT_IN_LOGF:
     case BUILT_IN_LOGL:
+    case BUILT_IN_TAN:
+    case BUILT_IN_TANF:
+    case BUILT_IN_TANL:
+    case BUILT_IN_ATAN:
+    case BUILT_IN_ATANF:
+    case BUILT_IN_ATANL:
       /* Treat these like sqrt only if unsafe math optimizations are allowed,
         because of possible accuracy problems.  */
       if (! flag_unsafe_math_optimizations)
index 7ea02a7a7f973b17f398760d4cdd7cc4eb2bcda1..4218fb3a3067fe3cb8f0f496f2b214c8634c2fb8 100644 (file)
   emit_move_insn (operands[2], temp);
   emit_move_insn (operands[7], CONST1_RTX (XFmode));  /* fld1 */
 })
+
+(define_expand "atansf2"
+  [(parallel [(set (match_operand:SF 0 "register_operand" "")
+                  (unspec:SF [(match_dup 2)
+                              (match_operand:SF 1 "register_operand" "")]
+                   UNSPEC_FPATAN))
+             (clobber (match_dup 1))])]
+  "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
+   && flag_unsafe_math_optimizations"
+{
+  operands[2] = gen_reg_rtx (SFmode);
+  emit_move_insn (operands[2], CONST1_RTX (SFmode));  /* fld1 */
+})
+
+(define_expand "atandf2"
+  [(parallel [(set (match_operand:DF 0 "register_operand" "")
+                  (unspec:DF [(match_dup 2)
+                              (match_operand:DF 1 "register_operand" "")]
+                   UNSPEC_FPATAN))
+             (clobber (match_dup 1))])]
+  "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
+   && flag_unsafe_math_optimizations"
+{
+  operands[2] = gen_reg_rtx (DFmode);
+  emit_move_insn (operands[2], CONST1_RTX (DFmode));  /* fld1 */
+})
+
+(define_expand "atanxf2"
+  [(parallel [(set (match_operand:XF 0 "register_operand" "")
+                  (unspec:XF [(match_dup 2)
+                              (match_operand:XF 1 "register_operand" "")]
+                   UNSPEC_FPATAN))
+             (clobber (match_dup 1))])]
+  "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
+   && flag_unsafe_math_optimizations"
+{
+  operands[2] = gen_reg_rtx (XFmode);
+  emit_move_insn (operands[2], CONST1_RTX (XFmode));  /* fld1 */
+})
+
+(define_expand "atantf2"
+  [(parallel [(set (match_operand:TF 0 "register_operand" "")
+                  (unspec:TF [(match_dup 2)
+                              (match_operand:TF 1 "register_operand" "")]
+                   UNSPEC_FPATAN))
+             (clobber (match_dup 1))])]
+  "! TARGET_NO_FANCY_MATH_387 && TARGET_80387
+   && flag_unsafe_math_optimizations"
+{
+  operands[2] = gen_reg_rtx (TFmode);
+  emit_move_insn (operands[2], CONST1_RTX (TFmode));  /* fld1 */
+})
 \f
 ;; Block operation instructions
 
index bba458d5f08e115f72238825759034712e0f8ca0..47f441cf2f72ae73f4956348dcd16e14e2a47866 100644 (file)
@@ -125,6 +125,8 @@ static const char * const optabs[] =
   "cos_optab->handlers[$A].insn_code = CODE_FOR_$(cos$a2$)",
   "exp_optab->handlers[$A].insn_code = CODE_FOR_$(exp$a2$)",
   "log_optab->handlers[$A].insn_code = CODE_FOR_$(log$a2$)",
+  "tan_optab->handlers[$A].insn_code = CODE_FOR_$(tan$a2$)",
+  "atan_optab->handlers[$A].insn_code = CODE_FOR_$(atan$a2$)",
   "strlen_optab->handlers[$A].insn_code = CODE_FOR_$(strlen$a$)",
   "one_cmpl_optab->handlers[$A].insn_code = CODE_FOR_$(one_cmpl$a2$)",
   "ffs_optab->handlers[$A].insn_code = CODE_FOR_$(ffs$a2$)",
index 18d9e2acbb640904024a55cd4518e97647968247..7f1a5a34fd06d2ac2988899141ae2c73aa912829 100644 (file)
@@ -5557,6 +5557,8 @@ init_optabs ()
   cos_optab = init_optab (UNKNOWN);
   exp_optab = init_optab (UNKNOWN);
   log_optab = init_optab (UNKNOWN);
+  tan_optab = init_optab (UNKNOWN);
+  atan_optab = init_optab (UNKNOWN);
   strlen_optab = init_optab (UNKNOWN);
   cbranch_optab = init_optab (UNKNOWN);
   cmov_optab = init_optab (UNKNOWN);
index 22e2422ccd1e906996ecf132fa6b7033b1320985..0c04a9d1b494993449be7c26cf65333c2de512b2 100644 (file)
@@ -149,6 +149,10 @@ enum optab_index
   OTI_trunc,
   OTI_round,
   OTI_nearbyint,
+  /* Tangent */
+  OTI_tan,
+  /* Inverse tangent */
+  OTI_atan,
 
   /* Compare insn; two operands.  */
   OTI_cmp,
@@ -232,6 +236,8 @@ extern GTY(()) optab optab_table[OTI_MAX];
 #define trunc_optab (optab_table[OTI_trunc])
 #define round_optab (optab_table[OTI_round])
 #define nearbyint_optab (optab_table[OTI_nearbyint])
+#define tan_optab (optab_table[OTI_tan])
+#define atan_optab (optab_table[OTI_atan])
 
 #define cmp_optab (optab_table[OTI_cmp])
 #define ucmp_optab (optab_table[OTI_ucmp])
index 4371663f1a55ff95b43a755e75451b487823bcbd..ed61bcf8dd92d30d7011a8bdf56294c1fa2c9981 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-16  Roger Sayle  <roger@eyesopen.com>
+
+       * gcc.dg/i386-387-5.c: New test case.
+       * gcc.dg/i386-387-6.c: New test case.
+       * gcc.dg/builtins-23.c: New test case.
+
 2003-06-15  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.dg/builtins-22.c: New test case.
diff --git a/gcc/testsuite/gcc.dg/builtins-23.c b/gcc/testsuite/gcc.dg/builtins-23.c
new file mode 100644 (file)
index 0000000..f463e17
--- /dev/null
@@ -0,0 +1,12 @@
+/* Related to PR optimization/10764  */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math" } */
+
+double atan(double x);
+
+double foo(double x)
+{
+  return atan(atan(x));
+}
+
diff --git a/gcc/testsuite/gcc.dg/i386-387-5.c b/gcc/testsuite/gcc.dg/i386-387-5.c
new file mode 100644 (file)
index 0000000..8ccc5c9
--- /dev/null
@@ -0,0 +1,7 @@
+/* Verify that -mno-fancy-math-387 works.  */
+/* { dg-do compile { target "i?86-*-*" } } */
+/* { dg-options "-O -ffast-math -mfpmath=387 -mno-fancy-math-387" } */
+/* { dg-final { scan-assembler "call\t_?atan" } } */
+
+double f1(double x) { return __builtin_atan(x); }
+
diff --git a/gcc/testsuite/gcc.dg/i386-387-6.c b/gcc/testsuite/gcc.dg/i386-387-6.c
new file mode 100644 (file)
index 0000000..8eb29a1
--- /dev/null
@@ -0,0 +1,6 @@
+/* Verify that -march overrides -mno-fancy-math-387.  */
+/* { dg-do compile { target "i?86-*-*" } } */
+/* { dg-options "-O -ffast-math -mfpmath=387 -march=i686 -mno-fancy-math-387" } */
+/* { dg-final { scan-assembler "fpatan" } } */
+
+double f1(double x) { return __builtin_atan(x); }