From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7480F38515ED; Sat, 19 Feb 2022 08:02:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7480F38515ED MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9596] veclower: Fix up -fcompare-debug issue in expand_vector_comparison [PR104307] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 73b30d18a04bd6efa7e25c28dac1c863dc1cb06e X-Git-Newrev: c81d1a061e5cfab6bd276c5be4cd6161b11e6d44 Message-Id: <20220219080214.7480F38515ED@sourceware.org> Date: Sat, 19 Feb 2022 08:02:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Feb 2022 08:02:14 -0000 https://gcc.gnu.org/g:c81d1a061e5cfab6bd276c5be4cd6161b11e6d44 commit r11-9596-gc81d1a061e5cfab6bd276c5be4cd6161b11e6d44 Author: Jakub Jelinek Date: Tue Feb 1 16:02:54 2022 +0100 veclower: Fix up -fcompare-debug issue in expand_vector_comparison [PR104307] The following testcase fails -fcompare-debug, because expand_vector_comparison since r11-1786-g1ac9258cca8030745d3c0b8f63186f0adf0ebc27 sets vec_cond_expr_only when it sees some use other than VEC_COND_EXPR that uses the lhs in its condition. Obviously we should ignore debug stmts when doing so, e.g. by not pushing them to uses. That would be a 2 liner change, but while looking at it, I'm also worried about VEC_COND_EXPRs that would use the lhs in more than one operand, like VEC_COND_EXPR or VEC_COND_EXPR (sure, they ought to be folded, but what if they weren't). Because if something like that happens, then FOR_EACH_IMM_USE_FAST would push the same stmt multiple times and expand_vector_condition can return true even when it modifies it (for vector bool masking). And lastly, it seems quite wasteful to safe_push statements that will just cause vec_cond_expr_only = false; and break; in the second loop, both for cases like 1000 immediate non-VEC_COND_EXPR uses and for cases like 999 VEC_COND_EXPRs with lhs in cond followed by a single non-VEC_COND_EXPR use. So this patch only pushes VEC_COND_EXPRs there. 2022-02-01 Jakub Jelinek PR middle-end/104307 * tree-vect-generic.c (expand_vector_comparison): Don't push debug stmts to uses vector, just set vec_cond_expr_only to false for non-VEC_COND_EXPRs instead of pushing them into uses. Treat VEC_COND_EXPRs that use lhs not just in rhs1, but rhs2 or rhs3 too like non-VEC_COND_EXPRs. * gcc.target/i386/pr104307.c: New test. (cherry picked from commit e9bf6d6b0e1d67df6dcee042fbe37ab72c3a38d7) Diff: --- gcc/testsuite/gcc.target/i386/pr104307.c | 6 +++++ gcc/tree-vect-generic.c | 38 +++++++++++++++++--------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/gcc/testsuite/gcc.target/i386/pr104307.c b/gcc/testsuite/gcc.target/i386/pr104307.c new file mode 100644 index 00000000000..1301539851c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr104307.c @@ -0,0 +1,6 @@ +/* PR middle-end/104307 */ +/* { dg-do compile } */ +/* { dg-require-effective-target int128 } */ +/* { dg-options "-O2 -mavx512f -fcompare-debug " } */ + +#include "pr78669.c" diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c index 3348545d18b..0828ff97569 100644 --- a/gcc/tree-vect-generic.c +++ b/gcc/tree-vect-generic.c @@ -380,29 +380,31 @@ expand_vector_comparison (gimple_stmt_iterator *gsi, tree type, tree op0, feeding a VEC_COND_EXPR statement. */ auto_vec uses; FOR_EACH_IMM_USE_FAST (use_p, iterator, lhs) - uses.safe_push (USE_STMT (use_p)); - - for (unsigned i = 0; i < uses.length (); i ++) { - gassign *use = dyn_cast (uses[i]); - if (use != NULL + gimple *use = USE_STMT (use_p); + if (is_gimple_debug (use)) + continue; + if (is_gimple_assign (use) && gimple_assign_rhs_code (use) == VEC_COND_EXPR - && gimple_assign_rhs1 (use) == lhs) - { - gimple_stmt_iterator it = gsi_for_stmt (use); - if (!expand_vector_condition (&it, dce_ssa_names)) - { - vec_cond_expr_only = false; - break; - } - } + && gimple_assign_rhs1 (use) == lhs + && gimple_assign_rhs2 (use) != lhs + && gimple_assign_rhs3 (use) != lhs) + uses.safe_push (use); else - { - vec_cond_expr_only = false; - break; - } + vec_cond_expr_only = false; } + if (vec_cond_expr_only) + for (gimple *use : uses) + { + gimple_stmt_iterator it = gsi_for_stmt (use); + if (!expand_vector_condition (&it, dce_ssa_names)) + { + vec_cond_expr_only = false; + break; + } + } + if (!uses.is_empty () && vec_cond_expr_only) return NULL_TREE;