From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] middle-end/104402 - split out _Complex compares from COND_EXPRs
Date: Mon, 7 Feb 2022 10:49:28 +0100 (CET) [thread overview]
Message-ID: <20220207094928.69D5713B2D@imap2.suse-dmz.suse.de> (raw)
This makes sure we always have a _Complex compare split to a
different stmt for the compare operand in a COND_EXPR on GIMPLE.
Complex lowering doesn't handle this and the change is something
we want for all kind of compares at some point.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk
sofar.
2022-02-07 Richard Biener <rguenther@suse.de>
PR middle-end/104402
* gimple-expr.cc (is_gimple_condexpr): _Complex typed
compares are not valid.
* tree-cfg.cc (verify_gimple_assign_ternary): For COND_EXPR
check is_gimple_condexpr.
* gcc.dg/torture/pr104402.c: New testcase.
---
gcc/gimple-expr.cc | 20 +++++++++++++-------
gcc/testsuite/gcc.dg/torture/pr104402.c | 8 ++++++++
gcc/tree-cfg.cc | 9 +++++----
3 files changed, 26 insertions(+), 11 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr104402.c
diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc
index 05b12747499..f9a650b5daf 100644
--- a/gcc/gimple-expr.cc
+++ b/gcc/gimple-expr.cc
@@ -602,12 +602,16 @@ is_gimple_lvalue (tree t)
/* Helper for is_gimple_condexpr and is_gimple_condexpr_for_cond. */
static bool
-is_gimple_condexpr_1 (tree t, bool allow_traps)
+is_gimple_condexpr_1 (tree t, bool allow_traps, bool allow_cplx)
{
- return (is_gimple_val (t) || (COMPARISON_CLASS_P (t)
- && (allow_traps || !tree_could_throw_p (t))
- && is_gimple_val (TREE_OPERAND (t, 0))
- && is_gimple_val (TREE_OPERAND (t, 1))));
+ tree op0;
+ return (is_gimple_val (t)
+ || (COMPARISON_CLASS_P (t)
+ && (allow_traps || !tree_could_throw_p (t))
+ && ((op0 = TREE_OPERAND (t, 0)), true)
+ && (allow_cplx || TREE_CODE (TREE_TYPE (op0)) != COMPLEX_TYPE)
+ && is_gimple_val (op0)
+ && is_gimple_val (TREE_OPERAND (t, 1))));
}
/* Return true if T is a GIMPLE condition. */
@@ -615,7 +619,9 @@ is_gimple_condexpr_1 (tree t, bool allow_traps)
bool
is_gimple_condexpr (tree t)
{
- return is_gimple_condexpr_1 (t, true);
+ /* Always split out _Complex type compares since complex lowering
+ doesn't handle this case. */
+ return is_gimple_condexpr_1 (t, true, false);
}
/* Like is_gimple_condexpr, but does not allow T to trap. */
@@ -623,7 +629,7 @@ is_gimple_condexpr (tree t)
bool
is_gimple_condexpr_for_cond (tree t)
{
- return is_gimple_condexpr_1 (t, false);
+ return is_gimple_condexpr_1 (t, false, true);
}
/* Return true if T is a gimple address. */
diff --git a/gcc/testsuite/gcc.dg/torture/pr104402.c b/gcc/testsuite/gcc.dg/torture/pr104402.c
new file mode 100644
index 00000000000..1cb0370e9b2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr104402.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+_Complex int a;
+char b;
+void c() {
+ if (b != 2 + (long)(a != 0 ^ 0))
+ __builtin_abort();
+}
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 260a7fb97c6..e321d929fd0 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -4289,10 +4289,11 @@ verify_gimple_assign_ternary (gassign *stmt)
/* Fallthrough. */
case COND_EXPR:
if (!is_gimple_val (rhs1)
- && verify_gimple_comparison (TREE_TYPE (rhs1),
- TREE_OPERAND (rhs1, 0),
- TREE_OPERAND (rhs1, 1),
- TREE_CODE (rhs1)))
+ && (!is_gimple_condexpr (rhs1)
+ || verify_gimple_comparison (TREE_TYPE (rhs1),
+ TREE_OPERAND (rhs1, 0),
+ TREE_OPERAND (rhs1, 1),
+ TREE_CODE (rhs1))))
return true;
if (!useless_type_conversion_p (lhs_type, rhs2_type)
|| !useless_type_conversion_p (lhs_type, rhs3_type))
--
2.34.1
reply other threads:[~2022-02-07 9:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220207094928.69D5713B2D@imap2.suse-dmz.suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).