aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2021-07-20 11:25:43 -0700
committerAndrew Pinski <apinski@marvell.com>2021-07-22 09:14:42 -0700
commit8819419ba1d397c0444d89079ec16657a09914fb (patch)
tree11b8169539ebfab3e39714c711094b654a35e334 /gcc
parent4048d8a08621820dd6cc6035e13de3c3c82af4a5 (diff)
downloadgcc-8819419ba1d397c0444d89079ec16657a09914fb.zip
gcc-8819419ba1d397c0444d89079ec16657a09914fb.tar.gz
gcc-8819419ba1d397c0444d89079ec16657a09914fb.tar.bz2
Fix PR 10153: tail recusion for vector types.
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-optimization/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-optimization/10153 * gcc.c-torture/compile/pr10153-1.c: New test. * gcc.c-torture/compile/pr10153-2.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr10153-1.c7
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr10153-2.c9
-rw-r--r--gcc/tree-tailcall.c10
3 files changed, 22 insertions, 4 deletions
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 0000000..3f2040f
--- /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 0000000..1af4c8e
--- /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 a4d31c9..f2833d2 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)