tree-optimization/101769 - tail recursion creates possibly infinite loop
authorRichard Biener <rguenther@suse.de>
Wed, 4 Aug 2021 07:22:51 +0000 (09:22 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 4 Aug 2021 08:35:27 +0000 (10:35 +0200)
commit4d562591018a51f155a2e5d8b9f3e5860111a327
treed9471d510954643e8739f6edb6e20c5e23eedf27
parent5c73b94fdc46f03c761ee5c66e30e00a2bf9ee91
tree-optimization/101769 - tail recursion creates possibly infinite loop

This makes tail recursion optimization produce a loop structure
manually rather than relying on loop fixup.  That also allows the
loop to be marked as finite (it would eventually blow the stack
if it were not).

2021-08-04  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101769
* tree-tailcall.c (eliminate_tail_call): Add the created loop
for the first recursion and return it via the new output parameter.
(optimize_tail_call): Pass through new output param.
(tree_optimize_tail_calls_1): After creating all latches,
add the created loop to the loop tree.  Do not mark loops for fixup.

* g++.dg/tree-ssa/pr101769.C: New testcase.
gcc/testsuite/g++.dg/tree-ssa/pr101769.C [new file with mode: 0644]
gcc/tree-tailcall.c