From patchwork Tue Feb 1 09:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50615 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36B623857C6A for ; Tue, 1 Feb 2022 09:19:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36B623857C6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643707171; bh=QEliWvzns0m+ZrvqrymYqYexHdQmwqCYTSapkzR6jf0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ro2lM5Yi/ZBySsDVgb5nK4dvLSdWiJ3QxjcoUJiAd+CfBpXU56OdSiCsqde3EU3kt twrm1YdYpou1YQXv5V4OZqRwYpHkUdjZKDTNQ0HpmFjfJ3Wue+QU0Y33ozUPUbMOyD sOWaO4PeXW/eT/sAHMYrXxraB65Lv4f/cIsl9eEY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CFC733858D35 for ; Tue, 1 Feb 2022 09:19:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CFC733858D35 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-610-xqqrNJKDPIKHDp4KoUq-gA-1; Tue, 01 Feb 2022 04:18:54 -0500 X-MC-Unique: xqqrNJKDPIKHDp4KoUq-gA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 871692F26; Tue, 1 Feb 2022 09:18:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A6E95E4B2; Tue, 1 Feb 2022 09:18:52 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 2119IoIn3078398 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 1 Feb 2022 10:18:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 2119In4Y3078397; Tue, 1 Feb 2022 10:18:49 +0100 Date: Tue, 1 Feb 2022 10:18:49 +0100 To: Richard Biener Subject: [PATCH] veclower: Fix up -fcompare-debug issue in expand_vector_comparison [PR104307] Message-ID: <20220201091849.GT2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! 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. As expand_vector_condition modifies the IL, it checks the condition again as before. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-02-01 Jakub Jelinek PR middle-end/104307 * tree-vect-generic.cc (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. Jakub --- gcc/tree-vect-generic.cc.jj 2022-01-20 11:30:45.641577244 +0100 +++ gcc/tree-vect-generic.cc 2022-01-31 18:01:29.062568721 +0100 @@ -436,29 +436,43 @@ expand_vector_comparison (gimple_stmt_it 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) + { + if (is_gimple_assign (use) + && gimple_assign_rhs_code (use) == VEC_COND_EXPR + && gimple_assign_rhs1 (use) == lhs + && gimple_assign_rhs2 (use) != lhs + && gimple_assign_rhs3 (use) != lhs) + { + gimple_stmt_iterator it = gsi_for_stmt (use); + if (!expand_vector_condition (&it, dce_ssa_names)) + { + vec_cond_expr_only = false; + break; + } + } + else + { + vec_cond_expr_only = false; + break; + } + } + if (!uses.is_empty () && vec_cond_expr_only) return NULL_TREE; --- gcc/testsuite/gcc.target/i386/pr104307.c.jj 2022-01-31 17:34:42.163145798 +0100 +++ gcc/testsuite/gcc.target/i386/pr104307.c 2022-01-31 17:35:14.111696698 +0100 @@ -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"