* [PATCH] Fix PR 10153: tail recusion for vector types.
@ 2021-07-21 19:26 apinski
2021-07-22 11:53 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: apinski @ 2021-07-21 19:26 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
From: Andrew Pinski <apinski@marvell.com>
The problem here is we try to an initialized value
from a scalar constant. For vectors we need to do
a vect_dup instead. This fixes that issue by using
build_{one,zero}_cst instead of integer_{one,zero}_node
when calling create_tailcall_accumulator.
Changes from v1:
* v2: Use build_{one,zero}_cst and get the correct type before.
OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
gcc/ChangeLog:
PR tree-optimize/10153
* tree-tailcall.c (create_tailcall_accumulator):
Don't call fold_convert as the type should be correct already.
(tree_optimize_tail_calls_1): Use build_{one,zero}_cst instead
of integer_{one,zero}_node for the call of create_tailcall_accumulator.
gcc/testsuite/ChangeLog:
PR tree-optimize/10153
* gcc.c-torture/compile/pr10153-1.c: New test.
* gcc.c-torture/compile/pr10153-2.c: New test.
---
gcc/testsuite/gcc.c-torture/compile/pr10153-1.c | 7 +++++++
gcc/testsuite/gcc.c-torture/compile/pr10153-2.c | 9 +++++++++
gcc/tree-tailcall.c | 10 ++++++----
3 files changed, 22 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
new file mode 100644
index 00000000000..3f2040f32a1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
@@ -0,0 +1,7 @@
+typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
+V
+foo (void)
+{
+ V v = { };
+ return v - foo();
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
new file mode 100644
index 00000000000..1af4c8e2a36
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
@@ -0,0 +1,9 @@
+typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
+V
+foo (int t)
+{
+ if (t < 10)
+ return (V){1, 1};
+ V v = { };
+ return v - foo(t - 1);
+}
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index a4d31c90c49..f2833d25ce8 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -1079,8 +1079,7 @@ create_tailcall_accumulator (const char *label, basic_block bb, tree init)
gphi *phi;
phi = create_phi_node (tmp, bb);
- /* RET_TYPE can be a float when -ffast-maths is enabled. */
- add_phi_arg (phi, fold_convert (ret_type, init), single_pred_edge (bb),
+ add_phi_arg (phi, init, single_pred_edge (bb),
UNKNOWN_LOCATION);
return PHI_RESULT (phi);
}
@@ -1157,14 +1156,17 @@ tree_optimize_tail_calls_1 (bool opt_tailcalls)
}
phis_constructed = true;
}
+ tree ret_type = TREE_TYPE (DECL_RESULT (current_function_decl));
+ if (POINTER_TYPE_P (ret_type))
+ ret_type = sizetype;
if (act->add && !a_acc)
a_acc = create_tailcall_accumulator ("add_acc", first,
- integer_zero_node);
+ build_zero_cst (ret_type));
if (act->mult && !m_acc)
m_acc = create_tailcall_accumulator ("mult_acc", first,
- integer_one_node);
+ build_one_cst (ret_type));
}
if (a_acc || m_acc)
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR 10153: tail recusion for vector types.
2021-07-21 19:26 [PATCH] Fix PR 10153: tail recusion for vector types apinski
@ 2021-07-22 11:53 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2021-07-22 11:53 UTC (permalink / raw)
To: Andrew Pinski; +Cc: GCC Patches
On Wed, Jul 21, 2021 at 9:30 PM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> The problem here is we try to an initialized value
> from a scalar constant. For vectors we need to do
> a vect_dup instead. This fixes that issue by using
> build_{one,zero}_cst instead of integer_{one,zero}_node
> when calling create_tailcall_accumulator.
>
> Changes from v1:
> * v2: Use build_{one,zero}_cst and get the correct type before.
>
> OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
OK.
> gcc/ChangeLog:
>
> PR tree-optimize/10153
> * tree-tailcall.c (create_tailcall_accumulator):
> Don't call fold_convert as the type should be correct already.
> (tree_optimize_tail_calls_1): Use build_{one,zero}_cst instead
> of integer_{one,zero}_node for the call of create_tailcall_accumulator.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimize/10153
> * gcc.c-torture/compile/pr10153-1.c: New test.
> * gcc.c-torture/compile/pr10153-2.c: New test.
> ---
> gcc/testsuite/gcc.c-torture/compile/pr10153-1.c | 7 +++++++
> gcc/testsuite/gcc.c-torture/compile/pr10153-2.c | 9 +++++++++
> gcc/tree-tailcall.c | 10 ++++++----
> 3 files changed, 22 insertions(+), 4 deletions(-)
> create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
>
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> new file mode 100644
> index 00000000000..3f2040f32a1
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> @@ -0,0 +1,7 @@
> +typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
> +V
> +foo (void)
> +{
> + V v = { };
> + return v - foo();
> +}
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
> new file mode 100644
> index 00000000000..1af4c8e2a36
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
> @@ -0,0 +1,9 @@
> +typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
> +V
> +foo (int t)
> +{
> + if (t < 10)
> + return (V){1, 1};
> + V v = { };
> + return v - foo(t - 1);
> +}
> diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
> index a4d31c90c49..f2833d25ce8 100644
> --- a/gcc/tree-tailcall.c
> +++ b/gcc/tree-tailcall.c
> @@ -1079,8 +1079,7 @@ create_tailcall_accumulator (const char *label, basic_block bb, tree init)
> gphi *phi;
>
> phi = create_phi_node (tmp, bb);
> - /* RET_TYPE can be a float when -ffast-maths is enabled. */
> - add_phi_arg (phi, fold_convert (ret_type, init), single_pred_edge (bb),
> + add_phi_arg (phi, init, single_pred_edge (bb),
> UNKNOWN_LOCATION);
> return PHI_RESULT (phi);
> }
> @@ -1157,14 +1156,17 @@ tree_optimize_tail_calls_1 (bool opt_tailcalls)
> }
> phis_constructed = true;
> }
> + tree ret_type = TREE_TYPE (DECL_RESULT (current_function_decl));
> + if (POINTER_TYPE_P (ret_type))
> + ret_type = sizetype;
>
> if (act->add && !a_acc)
> a_acc = create_tailcall_accumulator ("add_acc", first,
> - integer_zero_node);
> + build_zero_cst (ret_type));
>
> if (act->mult && !m_acc)
> m_acc = create_tailcall_accumulator ("mult_acc", first,
> - integer_one_node);
> + build_one_cst (ret_type));
> }
>
> if (a_acc || m_acc)
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR 10153: tail recusion for vector types.
2021-07-20 22:02 apinski
@ 2021-07-21 14:12 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2021-07-21 14:12 UTC (permalink / raw)
To: Andrew Pinski; +Cc: GCC Patches
On Wed, Jul 21, 2021 at 12:03 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> The problem here is we try to an initialized value
> from a scalar constant. For vectors we need to do
> a vect_dup instead. This fixes that issue and we
> get the correct code even and it does not crash.
>
> OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
I think the create_tailcall_accumulators should simply
use build_{one,zero}_cst (type) instead of passing down
integer_{zero,one}_node. Then we can even elide the fold_convert ...
> gcc/ChangeLog:
>
> PR tree-optimize/10153
> * tree-tailcall.c (create_tailcall_accumulator):
> For vector types create a duplicated VECTOR_CST
> before calling fold_convert.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimize/10153
> * gcc.c-torture/compile/pr10153-1.c: New test.
> * gcc.c-torture/compile/pr10153-2.c: New test.
> ---
> gcc/testsuite/gcc.c-torture/compile/pr10153-1.c | 7 +++++++
> gcc/testsuite/gcc.c-torture/compile/pr10153-2.c | 9 +++++++++
> gcc/tree-tailcall.c | 3 +++
> 3 files changed, 19 insertions(+)
> create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
>
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> new file mode 100644
> index 00000000000..3f2040f32a1
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
> @@ -0,0 +1,7 @@
> +typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
> +V
> +foo (void)
> +{
> + V v = { };
> + return v - foo();
> +}
> diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
> new file mode 100644
> index 00000000000..1af4c8e2a36
> --- /dev/null
> +++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
> @@ -0,0 +1,9 @@
> +typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
> +V
> +foo (int t)
> +{
> + if (t < 10)
> + return (V){1, 1};
> + V v = { };
> + return v - foo(t - 1);
> +}
> diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
> index a4d31c90c49..9d1a98b1cfd 100644
> --- a/gcc/tree-tailcall.c
> +++ b/gcc/tree-tailcall.c
> @@ -1080,6 +1080,9 @@ create_tailcall_accumulator (const char *label, basic_block bb, tree init)
>
> phi = create_phi_node (tmp, bb);
> /* RET_TYPE can be a float when -ffast-maths is enabled. */
> + /* For vectors create a dup. */
> + if (VECTOR_TYPE_P (ret_type))
> + init = build_vector_from_val (ret_type, fold_convert (TREE_TYPE (ret_type), init));
> add_phi_arg (phi, fold_convert (ret_type, init), single_pred_edge (bb),
> UNKNOWN_LOCATION);
> return PHI_RESULT (phi);
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Fix PR 10153: tail recusion for vector types.
@ 2021-07-20 22:02 apinski
2021-07-21 14:12 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: apinski @ 2021-07-20 22:02 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
From: Andrew Pinski <apinski@marvell.com>
The problem here is we try to an initialized value
from a scalar constant. For vectors we need to do
a vect_dup instead. This fixes that issue and we
get the correct code even and it does not crash.
OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
gcc/ChangeLog:
PR tree-optimize/10153
* tree-tailcall.c (create_tailcall_accumulator):
For vector types create a duplicated VECTOR_CST
before calling fold_convert.
gcc/testsuite/ChangeLog:
PR tree-optimize/10153
* gcc.c-torture/compile/pr10153-1.c: New test.
* gcc.c-torture/compile/pr10153-2.c: New test.
---
gcc/testsuite/gcc.c-torture/compile/pr10153-1.c | 7 +++++++
gcc/testsuite/gcc.c-torture/compile/pr10153-2.c | 9 +++++++++
gcc/tree-tailcall.c | 3 +++
3 files changed, 19 insertions(+)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
new file mode 100644
index 00000000000..3f2040f32a1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-1.c
@@ -0,0 +1,7 @@
+typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
+V
+foo (void)
+{
+ V v = { };
+ return v - foo();
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
new file mode 100644
index 00000000000..1af4c8e2a36
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr10153-2.c
@@ -0,0 +1,9 @@
+typedef int V __attribute__ ((vector_size (2 * sizeof (int))));
+V
+foo (int t)
+{
+ if (t < 10)
+ return (V){1, 1};
+ V v = { };
+ return v - foo(t - 1);
+}
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index a4d31c90c49..9d1a98b1cfd 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -1080,6 +1080,9 @@ create_tailcall_accumulator (const char *label, basic_block bb, tree init)
phi = create_phi_node (tmp, bb);
/* RET_TYPE can be a float when -ffast-maths is enabled. */
+ /* For vectors create a dup. */
+ if (VECTOR_TYPE_P (ret_type))
+ init = build_vector_from_val (ret_type, fold_convert (TREE_TYPE (ret_type), init));
add_phi_arg (phi, fold_convert (ret_type, init), single_pred_edge (bb),
UNKNOWN_LOCATION);
return PHI_RESULT (phi);
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-22 11:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 19:26 [PATCH] Fix PR 10153: tail recusion for vector types apinski
2021-07-22 11:53 ` Richard Biener
-- strict thread matches above, loose matches on Subject: below --
2021-07-20 22:02 apinski
2021-07-21 14:12 ` Richard Biener
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).