public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10735] reassoc: Fix up another ICE with returns_twice call [PR109410]
@ 2023-05-02 20:16 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-05-02 20:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e61e70fbfdcc99cbd23a02a1c789d3290b58d5a8
commit r11-10735-ge61e70fbfdcc99cbd23a02a1c789d3290b58d5a8
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Apr 12 16:55:15 2023 +0200
reassoc: Fix up another ICE with returns_twice call [PR109410]
The following testcase ICEs in reassoc, unlike the last case I've fixed
there here SSA_NAME_USED_IN_ABNORMAL_PHI is not the case anywhere.
build_and_add_sum places new statements after the later appearing definition
of an operand but if both operands are default defs or constants, we place
statement at the start of the function.
If the very first statement of a function is a call to returns_twice
function, this doesn't work though, because that call has to be the first
thing in its basic block, so the following patch splits the entry successor
edge such that the new statements are added into a different block from the
returns_twice call.
I think we should in stage1 reconsider such placements, I think it
unnecessarily enlarges the lifetime of the new lhs if its operand(s)
are used more than once in the function. Unless something sinks those
again. Would be nice to place it closer to the actual uses (or where
they will be placed).
2023-04-12 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/109410
* tree-ssa-reassoc.c (build_and_add_sum): Split edge from entry
block if first statement of the function is a call to returns_twice
function.
* gcc.dg/pr109410.c: New test.
(cherry picked from commit 51856718a82ce60f067910d9037ca255645b37eb)
Diff:
---
gcc/testsuite/gcc.dg/pr109410.c | 19 +++++++++++++++++++
gcc/tree-ssa-reassoc.c | 9 +++++++++
2 files changed, 28 insertions(+)
diff --git a/gcc/testsuite/gcc.dg/pr109410.c b/gcc/testsuite/gcc.dg/pr109410.c
new file mode 100644
index 00000000000..a6401fc100c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109410.c
@@ -0,0 +1,19 @@
+/* PR tree-optimization/109410 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+__attribute__((returns_twice)) int baz (int, int);
+
+int
+bar (int x)
+{
+ return x;
+}
+
+int
+foo (int x, int y)
+{
+ baz (x, y);
+ int a = bar (x);
+ return y || a == 42 || a > 42;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index c8cb7328a63..1cf577af880 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -1520,6 +1520,15 @@ build_and_add_sum (tree type, tree op1, tree op2, enum tree_code opcode)
&& (!op2def || gimple_nop_p (op2def)))
{
gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
+ if (!gsi_end_p (gsi)
+ && is_gimple_call (gsi_stmt (gsi))
+ && (gimple_call_flags (gsi_stmt (gsi)) & ECF_RETURNS_TWICE))
+ {
+ /* Don't add statements before a returns_twice call at the start
+ of a function. */
+ split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
+ gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
+ }
if (gsi_end_p (gsi))
{
gimple_stmt_iterator gsi2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-02 20:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 20:16 [gcc r11-10735] reassoc: Fix up another ICE with returns_twice call [PR109410] Jakub Jelinek
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).