public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] make sincos take type from intrinsic formal, not from result assignment
@ 2020-10-07 10:49 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2020-10-07 10:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0f8d4b89ea91525c22a2b5f84e8b5d13bd69b0c8

commit 0f8d4b89ea91525c22a2b5f84e8b5d13bd69b0c8
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Wed Oct 7 07:39:27 2020 -0300

    make sincos take type from intrinsic formal, not from result assignment
    
    This is a first step towards enabling the sincos optimization in Ada.
    
    The issue this patch solves is that sincos takes the type to be looked
    up with mathfn_built_in from variables or temporaries passed to sin
    and cos as arguments.  In Ada, sin and cos are declared in an internal
    aux package, with uses thereof in a standard generic package, which
    ensures that the types are not what mathfn_built_in expects.
    
    Taking the type from the intrinsic's formal parameter, as in the
    patch, ensures we get the type associated with the intrinsics,
    regardless of the types used to declare and import them, so the lookup
    of the CEXPI intrinsic for the same type finds it.
    
    
    for  gcc/ChangeLog
    
            * tree-ssa-math-opts.c (execute_cse_sincos_1): Take the type
            for the cexpi/sincos intrinsic interface from formals of other
            intrinsics.

Diff:
---
 gcc/tree-ssa-math-opts.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 4927255d456..faba007ce4c 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1139,7 +1139,7 @@ execute_cse_sincos_1 (tree name)
 {
   gimple_stmt_iterator gsi;
   imm_use_iterator use_iter;
-  tree fndecl, res, type;
+  tree fndecl = NULL_TREE, res, type = NULL_TREE;
   gimple *def_stmt, *use_stmt, *stmt;
   int seen_cos = 0, seen_sin = 0, seen_cexpi = 0;
   auto_vec<gimple *> stmts;
@@ -1147,7 +1147,6 @@ execute_cse_sincos_1 (tree name)
   int i;
   bool cfg_changed = false;
 
-  type = TREE_TYPE (name);
   FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, name)
     {
       if (gimple_code (use_stmt) != GIMPLE_CALL
@@ -1169,15 +1168,34 @@ execute_cse_sincos_1 (tree name)
 	  break;
 
 	default:;
+	  continue;
 	}
-    }
 
+      tree t = TREE_VALUE (TYPE_ARG_TYPES (gimple_call_fntype (use_stmt)));
+      if (!type)
+	type = t;
+      else if (t != type)
+	{
+	  if (!tree_nop_conversion_p (type, t))
+	    return false;
+	  /* If there is more than one type to choose from, prefer one
+	     that has a CEXPI builtin.  */
+	  else if (!fndecl
+		   && (fndecl = mathfn_built_in (t, BUILT_IN_CEXPI)))
+	    type = t;
+	}
+    }
   if (seen_cos + seen_sin + seen_cexpi <= 1)
     return false;
 
+  if (type != TREE_TYPE (name)
+      && !tree_nop_conversion_p (type, TREE_TYPE (name)))
+    return false;
+
   /* Simply insert cexpi at the beginning of top_bb but not earlier than
      the name def statement.  */
-  fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
+  if (!fndecl)
+    fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
   if (!fndecl)
     return false;
   stmt = gimple_build_call (fndecl, 1, name);


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] make sincos take type from intrinsic formal, not from result assignment
@ 2020-10-06 10:45 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2020-10-06 10:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:60f4c1120c99d16e3a80b6ee892c862be0513220

commit 60f4c1120c99d16e3a80b6ee892c862be0513220
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Tue Sep 29 09:50:05 2020 -0300

    make sincos take type from intrinsic formal, not from result assignment
    
    This is a first step towards enabling the sincos optimization in Ada.
    
    The issue this patch solves is that sincos takes the type to be looked
    up with mathfn_built_in from variables or temporaries passed to sin
    and cos as arguments.  In Ada, sin and cos are declared in an internal
    aux package, with uses thereof in a standard generic package, which
    ensures that the types are not what mathfn_built_in expects.
    
    Taking the type from the intrinsic's formal parameter, as in the
    patch, ensures we get the type associated with the intrinsics,
    regardless of the types used to declare and import them, so the lookup
    of the CEXPI intrinsic for the same type finds it.
    
    
    for  gcc/ChangeLog
    
            * tree-ssa-math-opts.c (execute_cse_sincos_1): Take the type
            for the cexpi/sincos intrinsic interface from formals of other
            intrinsics.

Diff:
---
 gcc/tree-ssa-math-opts.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 8423caa3ee3..31fd241e69a 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1139,7 +1139,7 @@ execute_cse_sincos_1 (tree name)
 {
   gimple_stmt_iterator gsi;
   imm_use_iterator use_iter;
-  tree fndecl, res, type;
+  tree fndecl = NULL_TREE, res, type = NULL_TREE;
   gimple *def_stmt, *use_stmt, *stmt;
   int seen_cos = 0, seen_sin = 0, seen_cexpi = 0;
   auto_vec<gimple *> stmts;
@@ -1147,7 +1147,6 @@ execute_cse_sincos_1 (tree name)
   int i;
   bool cfg_changed = false;
 
-  type = TREE_TYPE (name);
   FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, name)
     {
       if (gimple_code (use_stmt) != GIMPLE_CALL
@@ -1169,15 +1168,34 @@ execute_cse_sincos_1 (tree name)
 	  break;
 
 	default:;
+	  continue;
 	}
-    }
 
+      tree t = TREE_VALUE (TYPE_ARG_TYPES (gimple_call_fntype (use_stmt)));
+      if (!type)
+	type = t;
+      else if (t != type)
+	{
+	  if (!tree_nop_conversion_p (type, t))
+	    return false;
+	  /* If there is more than one type to choose from, prefer one
+	     that has a CEXPI builtin.  */
+	  else if (!fndecl
+		   && (fndecl = mathfn_built_in (t, BUILT_IN_CEXPI)))
+	    type = t;
+	}
+    }
   if (seen_cos + seen_sin + seen_cexpi <= 1)
     return false;
 
+  if (type != TREE_TYPE (name)
+      && !tree_nop_conversion_p (type, TREE_TYPE (name)))
+    return false;
+
   /* Simply insert cexpi at the beginning of top_bb but not earlier than
      the name def statement.  */
-  fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
+  if (!fndecl)
+    fndecl = mathfn_built_in (type, BUILT_IN_CEXPI);
   if (!fndecl)
     return false;
   stmt = gimple_build_call (fndecl, 1, name);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-07 10:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 10:49 [gcc(refs/users/aoliva/heads/testme)] make sincos take type from intrinsic formal, not from result assignment Alexandre Oliva
  -- strict thread matches above, loose matches on Subject: below --
2020-10-06 10:45 Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).