diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-03-28 10:48:31 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-03-28 10:48:31 +0100 |
commit | c95f5a0c0719ad5b23f605b4d8f8dd3689a0066b (patch) | |
tree | adf3d4635bb8c0b4018af0ba166f1c59ebe5e881 | |
parent | 9ac0ff5ea5f5a2c96f1599d271a42e226929d30b (diff) | |
download | gcc-c95f5a0c0719ad5b23f605b4d8f8dd3689a0066b.zip gcc-c95f5a0c0719ad5b23f605b4d8f8dd3689a0066b.tar.gz gcc-c95f5a0c0719ad5b23f605b4d8f8dd3689a0066b.tar.bz2 |
ipa-sra: Don't change return type to void if there are musttail calls [PR119484]
The following testcase is rejected, because IPA-SRA decides to
turn bar.constprop call into bar.constprop.isra which returns void.
While there is no explicit lhs on the call, as it is a musttail call
the tailc pass checks if IPA-VRP returns singleton from that function
and the function returns the same value and in that case it still turns
it into a tail call. This can't work with IPA-SRA changing it into
void returning function though.
The following patch fixes this by forcing returning the original type
if there are musttail calls.
2025-03-28 Jakub Jelinek <jakub@redhat.com>
PR ipa/119484
* ipa-sra.cc (isra_analyze_call): Don't set m_return_ignored if
gimple_call_must_tail_p even if it doesn't have lhs.
* c-c++-common/pr119484.c: New test.
-rw-r--r-- | gcc/ipa-sra.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr119484.c | 21 |
2 files changed, 26 insertions, 1 deletions
diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index 5d1703e..1331ba49 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -2242,7 +2242,11 @@ isra_analyze_call (cgraph_edge *cs) BITMAP_FREE (analyzed); } } - else + /* Don't set m_return_ignored for musttail calls. The tailc/musttail passes + compare the returned value against the IPA-VRP return value range if + it is a singleton, but if the call is changed to something which doesn't + return anything, it will always fail. */ + else if (!gimple_call_must_tail_p (call_stmt)) csum->m_return_ignored = true; } diff --git a/gcc/testsuite/c-c++-common/pr119484.c b/gcc/testsuite/c-c++-common/pr119484.c new file mode 100644 index 0000000..6ae7c9a --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr119484.c @@ -0,0 +1,21 @@ +/* PR ipa/119484 */ +/* { dg-do compile { target musttail } } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-times "bar\[.a-z0-9]* \\\(\[^\n\r]*\\\); \\\[tail call\\\] \\\[must tail call\\\]" 1 "optimized" } } */ + +void foo (int); + +[[gnu::noinline]] static int +bar (int x) +{ + foo (x); + return 0; +} + +int +baz (int x) +{ + if (x == 1) + [[gnu::musttail]] return bar (x); + return 0; +} |