public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] strub: handle volatile promoted args in internal strub [PR112938]
@ 2023-12-12 20:23 Alexandre Oliva
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2023-12-12 20:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c80d19ed755692e8d1d04686f36f7065ce008f80

commit c80d19ed755692e8d1d04686f36f7065ce008f80
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Tue Dec 12 00:08:27 2023 -0300

    strub: handle volatile promoted args in internal strub [PR112938]
    
    When generating code for an internal strub wrapper, don't clear the
    DECL_NOT_GIMPLE_REG_P flag of volatile args, and gimplify them both
    before and after any conversion.
    
    While at that, move variable TMP into narrower scopes so that it's
    more trivial to track where ARG lives.
    
    
    for  gcc/ChangeLog
    
            PR middle-end/112938
            * ipa-strub.cc (pass_ipa_strub::execute): Handle promoted
            volatile args in internal strub.  Simplify.
    
    for  gcc/testsuite/ChangeLog
    
            PR middle-end/112938
            * gcc.dg/strub-internal-volatile.c: New.

Diff:
---
 gcc/ipa-strub.cc                               | 29 +++++++++++++++++++-------
 gcc/testsuite/gcc.dg/strub-internal-volatile.c | 10 +++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index 8ec6824e8a8..45294b0b46b 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -3203,7 +3203,6 @@ pass_ipa_strub::execute (function *)
 		   i++, arg = DECL_CHAIN (arg), nparm = DECL_CHAIN (nparm))
 		{
 		  tree save_arg = arg;
-		  tree tmp = arg;
 
 		  /* Arrange to pass indirectly the parms, if we decided to do
 		     so, and revert its type in the wrapper.  */
@@ -3211,10 +3210,9 @@ pass_ipa_strub::execute (function *)
 		    {
 		      tree ref_type = TREE_TYPE (nparm);
 		      TREE_ADDRESSABLE (arg) = true;
-		      tree addr = build1 (ADDR_EXPR, ref_type, arg);
-		      tmp = arg = addr;
+		      arg = build1 (ADDR_EXPR, ref_type, arg);
 		    }
-		  else
+		  else if (!TREE_THIS_VOLATILE (arg))
 		    DECL_NOT_GIMPLE_REG_P (arg) = 0;
 
 		  /* Convert the argument back to the type used by the calling
@@ -3223,16 +3221,31 @@ pass_ipa_strub::execute (function *)
 		     double to be passed on unchanged to the wrapped
 		     function.  */
 		  if (TREE_TYPE (nparm) != DECL_ARG_TYPE (nparm))
-		    arg = fold_convert (DECL_ARG_TYPE (nparm), arg);
+		    {
+		      tree tmp = arg;
+		      /* If ARG is e.g. volatile, we must copy and
+			 convert in separate statements.  ???  Should
+			 we drop volatile from the wrapper
+			 instead?  */
+		      if (!is_gimple_val (arg))
+			{
+			  tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						(TREE_TYPE (arg)), "arg");
+			  gimple *stmt = gimple_build_assign (tmp, arg);
+			  gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+			}
+		      arg = fold_convert (DECL_ARG_TYPE (nparm), tmp);
+		    }
 
 		  if (!is_gimple_val (arg))
 		    {
-		      tmp = create_tmp_reg (TYPE_MAIN_VARIANT
-					    (TREE_TYPE (arg)), "arg");
+		      tree tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						 (TREE_TYPE (arg)), "arg");
 		      gimple *stmt = gimple_build_assign (tmp, arg);
 		      gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+		      arg = tmp;
 		    }
-		  vargs.quick_push (tmp);
+		  vargs.quick_push (arg);
 		  arg = save_arg;
 		}
 	    /* These strub arguments are adjusted later.  */
diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
new file mode 100644
index 00000000000..cdfca67616b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target strub } */
+
+void __attribute__ ((strub("internal")))
+f(volatile short) {
+}
+
+void g(void) {
+  f(0);
+}

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

* [gcc(refs/users/aoliva/heads/testme)] strub: handle volatile promoted args in internal strub [PR112938]
@ 2023-12-14 12:47 Alexandre Oliva
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2023-12-14 12:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b1f753296e773faec250cc40d4261b46302b7fe9

commit b1f753296e773faec250cc40d4261b46302b7fe9
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Thu Dec 14 03:21:03 2023 -0300

    strub: handle volatile promoted args in internal strub [PR112938]
    
    When generating code for an internal strub wrapper, don't clear the
    DECL_NOT_GIMPLE_REG_P flag of volatile args, and gimplify them both
    before and after any conversion.
    
    While at that, move variable TMP into narrower scopes so that it's
    more trivial to track where ARG lives.
    
    
    for  gcc/ChangeLog
    
            PR middle-end/112938
            * ipa-strub.cc (pass_ipa_strub::execute): Handle promoted
            volatile args in internal strub.  Simplify.
    
    for  gcc/testsuite/ChangeLog
    
            PR middle-end/112938
            * gcc.dg/strub-internal-volatile.c: New.

Diff:
---
 gcc/ipa-strub.cc                               | 29 +++++++++++++++++++-------
 gcc/testsuite/gcc.dg/strub-internal-volatile.c | 10 +++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index 8ec6824e8a8..45294b0b46b 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -3203,7 +3203,6 @@ pass_ipa_strub::execute (function *)
 		   i++, arg = DECL_CHAIN (arg), nparm = DECL_CHAIN (nparm))
 		{
 		  tree save_arg = arg;
-		  tree tmp = arg;
 
 		  /* Arrange to pass indirectly the parms, if we decided to do
 		     so, and revert its type in the wrapper.  */
@@ -3211,10 +3210,9 @@ pass_ipa_strub::execute (function *)
 		    {
 		      tree ref_type = TREE_TYPE (nparm);
 		      TREE_ADDRESSABLE (arg) = true;
-		      tree addr = build1 (ADDR_EXPR, ref_type, arg);
-		      tmp = arg = addr;
+		      arg = build1 (ADDR_EXPR, ref_type, arg);
 		    }
-		  else
+		  else if (!TREE_THIS_VOLATILE (arg))
 		    DECL_NOT_GIMPLE_REG_P (arg) = 0;
 
 		  /* Convert the argument back to the type used by the calling
@@ -3223,16 +3221,31 @@ pass_ipa_strub::execute (function *)
 		     double to be passed on unchanged to the wrapped
 		     function.  */
 		  if (TREE_TYPE (nparm) != DECL_ARG_TYPE (nparm))
-		    arg = fold_convert (DECL_ARG_TYPE (nparm), arg);
+		    {
+		      tree tmp = arg;
+		      /* If ARG is e.g. volatile, we must copy and
+			 convert in separate statements.  ???  Should
+			 we drop volatile from the wrapper
+			 instead?  */
+		      if (!is_gimple_val (arg))
+			{
+			  tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						(TREE_TYPE (arg)), "arg");
+			  gimple *stmt = gimple_build_assign (tmp, arg);
+			  gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+			}
+		      arg = fold_convert (DECL_ARG_TYPE (nparm), tmp);
+		    }
 
 		  if (!is_gimple_val (arg))
 		    {
-		      tmp = create_tmp_reg (TYPE_MAIN_VARIANT
-					    (TREE_TYPE (arg)), "arg");
+		      tree tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						 (TREE_TYPE (arg)), "arg");
 		      gimple *stmt = gimple_build_assign (tmp, arg);
 		      gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+		      arg = tmp;
 		    }
-		  vargs.quick_push (tmp);
+		  vargs.quick_push (arg);
 		  arg = save_arg;
 		}
 	    /* These strub arguments are adjusted later.  */
diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
new file mode 100644
index 00000000000..34d4ec8b383
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target strub } */
+
+void __attribute__ ((strub("internal")))
+f(volatile short s) {
+}
+
+void g(void) {
+  f(0);
+}

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

* [gcc(refs/users/aoliva/heads/testme)] strub: handle volatile promoted args in internal strub [PR112938]
@ 2023-12-12  2:38 Alexandre Oliva
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2023-12-12  2:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e050430d5fbee5b5594d13ccd077797e69c30275

commit e050430d5fbee5b5594d13ccd077797e69c30275
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Mon Dec 11 15:17:03 2023 -0300

    strub: handle volatile promoted args in internal strub [PR112938]
    
    When generating code for an internal strub wrapper, don't clear the
    DECL_NOT_GIMPLE_REG_P flag of volatile args, and gimplify them both
    before and after any conversion.
    
    While at that, move variable TMP into narrower scopes so that it's
    more trivial to track where ARG lives.
    
    
    for  gcc/ChangeLog
    
            PR middle-end/112938
            * ipa-strub.cc (pass_ipa_strub::execute): Handle promoted
            volatile args in internal strub.  Simplify.
    
    for  gcc/testsuite/ChangeLog
    
            PR middle-end/112938
            * gcc.dg/strub-internal-volatile.c: New.

Diff:
---
 gcc/ipa-strub.cc                               | 29 +++++++++++++++++++-------
 gcc/testsuite/gcc.dg/strub-internal-volatile.c | 10 +++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index 8ec6824e8a8..45294b0b46b 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -3203,7 +3203,6 @@ pass_ipa_strub::execute (function *)
 		   i++, arg = DECL_CHAIN (arg), nparm = DECL_CHAIN (nparm))
 		{
 		  tree save_arg = arg;
-		  tree tmp = arg;
 
 		  /* Arrange to pass indirectly the parms, if we decided to do
 		     so, and revert its type in the wrapper.  */
@@ -3211,10 +3210,9 @@ pass_ipa_strub::execute (function *)
 		    {
 		      tree ref_type = TREE_TYPE (nparm);
 		      TREE_ADDRESSABLE (arg) = true;
-		      tree addr = build1 (ADDR_EXPR, ref_type, arg);
-		      tmp = arg = addr;
+		      arg = build1 (ADDR_EXPR, ref_type, arg);
 		    }
-		  else
+		  else if (!TREE_THIS_VOLATILE (arg))
 		    DECL_NOT_GIMPLE_REG_P (arg) = 0;
 
 		  /* Convert the argument back to the type used by the calling
@@ -3223,16 +3221,31 @@ pass_ipa_strub::execute (function *)
 		     double to be passed on unchanged to the wrapped
 		     function.  */
 		  if (TREE_TYPE (nparm) != DECL_ARG_TYPE (nparm))
-		    arg = fold_convert (DECL_ARG_TYPE (nparm), arg);
+		    {
+		      tree tmp = arg;
+		      /* If ARG is e.g. volatile, we must copy and
+			 convert in separate statements.  ???  Should
+			 we drop volatile from the wrapper
+			 instead?  */
+		      if (!is_gimple_val (arg))
+			{
+			  tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						(TREE_TYPE (arg)), "arg");
+			  gimple *stmt = gimple_build_assign (tmp, arg);
+			  gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+			}
+		      arg = fold_convert (DECL_ARG_TYPE (nparm), tmp);
+		    }
 
 		  if (!is_gimple_val (arg))
 		    {
-		      tmp = create_tmp_reg (TYPE_MAIN_VARIANT
-					    (TREE_TYPE (arg)), "arg");
+		      tree tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						 (TREE_TYPE (arg)), "arg");
 		      gimple *stmt = gimple_build_assign (tmp, arg);
 		      gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+		      arg = tmp;
 		    }
-		  vargs.quick_push (tmp);
+		  vargs.quick_push (arg);
 		  arg = save_arg;
 		}
 	    /* These strub arguments are adjusted later.  */
diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
new file mode 100644
index 00000000000..cdfca67616b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target strub } */
+
+void __attribute__ ((strub("internal")))
+f(volatile short) {
+}
+
+void g(void) {
+  f(0);
+}

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

* [gcc(refs/users/aoliva/heads/testme)] strub: handle volatile promoted args in internal strub [PR112938]
@ 2023-12-11 22:57 Alexandre Oliva
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 2023-12-11 22:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:967171ba3a1092acfa8493fba7bcd6c8ded31b77

commit 967171ba3a1092acfa8493fba7bcd6c8ded31b77
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Mon Dec 11 15:17:03 2023 -0300

    strub: handle volatile promoted args in internal strub [PR112938]
    
    When generating code for an internal strub wrapper, don't clear the
    DECL_NOT_GIMPLE_REG_P flag of volatile args, and gimplify them both
    before and after any conversion.
    
    While at that, move variable TMP into narrower scopes so that it's
    more trivial to track where ARG lives.
    
    
    for  gcc/ChangeLog
    
            PR middle-end/112938
            * ipa-strub.cc (pass_ipa_strub::execute): Handle promoted
            volatile args in internal strub.  Simplify.
    
    for  gcc/testsuite/ChangeLog
    
            PR middle-end/112938
            * gcc.dg/strub-internal-volatile.c: New.

Diff:
---
 gcc/ipa-strub.cc                               | 29 +++++++++++++++++++-------
 gcc/testsuite/gcc.dg/strub-internal-volatile.c | 10 +++++++++
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index 8ec6824e8a8..45294b0b46b 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -3203,7 +3203,6 @@ pass_ipa_strub::execute (function *)
 		   i++, arg = DECL_CHAIN (arg), nparm = DECL_CHAIN (nparm))
 		{
 		  tree save_arg = arg;
-		  tree tmp = arg;
 
 		  /* Arrange to pass indirectly the parms, if we decided to do
 		     so, and revert its type in the wrapper.  */
@@ -3211,10 +3210,9 @@ pass_ipa_strub::execute (function *)
 		    {
 		      tree ref_type = TREE_TYPE (nparm);
 		      TREE_ADDRESSABLE (arg) = true;
-		      tree addr = build1 (ADDR_EXPR, ref_type, arg);
-		      tmp = arg = addr;
+		      arg = build1 (ADDR_EXPR, ref_type, arg);
 		    }
-		  else
+		  else if (!TREE_THIS_VOLATILE (arg))
 		    DECL_NOT_GIMPLE_REG_P (arg) = 0;
 
 		  /* Convert the argument back to the type used by the calling
@@ -3223,16 +3221,31 @@ pass_ipa_strub::execute (function *)
 		     double to be passed on unchanged to the wrapped
 		     function.  */
 		  if (TREE_TYPE (nparm) != DECL_ARG_TYPE (nparm))
-		    arg = fold_convert (DECL_ARG_TYPE (nparm), arg);
+		    {
+		      tree tmp = arg;
+		      /* If ARG is e.g. volatile, we must copy and
+			 convert in separate statements.  ???  Should
+			 we drop volatile from the wrapper
+			 instead?  */
+		      if (!is_gimple_val (arg))
+			{
+			  tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						(TREE_TYPE (arg)), "arg");
+			  gimple *stmt = gimple_build_assign (tmp, arg);
+			  gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+			}
+		      arg = fold_convert (DECL_ARG_TYPE (nparm), tmp);
+		    }
 
 		  if (!is_gimple_val (arg))
 		    {
-		      tmp = create_tmp_reg (TYPE_MAIN_VARIANT
-					    (TREE_TYPE (arg)), "arg");
+		      tree tmp = create_tmp_reg (TYPE_MAIN_VARIANT
+						 (TREE_TYPE (arg)), "arg");
 		      gimple *stmt = gimple_build_assign (tmp, arg);
 		      gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
+		      arg = tmp;
 		    }
-		  vargs.quick_push (tmp);
+		  vargs.quick_push (arg);
 		  arg = save_arg;
 		}
 	    /* These strub arguments are adjusted later.  */
diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
new file mode 100644
index 00000000000..cdfca67616b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target strub } */
+
+void __attribute__ ((strub("internal")))
+f(volatile short) {
+}
+
+void g(void) {
+  f(0);
+}

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

end of thread, other threads:[~2023-12-14 12:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-12 20:23 [gcc(refs/users/aoliva/heads/testme)] strub: handle volatile promoted args in internal strub [PR112938] Alexandre Oliva
  -- strict thread matches above, loose matches on Subject: below --
2023-12-14 12:47 Alexandre Oliva
2023-12-12  2:38 Alexandre Oliva
2023-12-11 22:57 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).