From: Richard Biener Date: Mon, 7 Feb 2022 08:31:07 +0000 (+0100) Subject: middle-end/104402 - split out _Complex compares from COND_EXPRs X-Git-Tag: releases/gcc-10.4.0~277 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa26d65dfb41e527bd0db3af3ec2a6ac052019f4;p=thirdparty%2Fgcc.git middle-end/104402 - split out _Complex compares from COND_EXPRs 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. 2022-02-07 Richard Biener PR middle-end/104402 * gimple-expr.c (is_gimple_condexpr): _Complex typed compares are not valid. * tree-cfg.c (verify_gimple_assign_ternary): For COND_EXPR check is_gimple_condexpr. * gcc.dg/torture/pr104402.c: New testcase. (cherry picked from commit 70430001b74d0f67386a6b3642c857b3389cd5d0) --- diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c index 44a0b8790f54..141bc0cd0cf8 100644 --- a/gcc/gimple-expr.c +++ b/gcc/gimple-expr.c @@ -612,12 +612,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. */ @@ -625,7 +629,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. */ @@ -633,7 +639,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 000000000000..1cb0370e9b25 --- /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.c b/gcc/tree-cfg.c index 1af59fc6fe9a..d16ed3e88556 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -4243,10 +4243,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))