From patchwork Mon May 2 11:16:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 53389 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 D30BC3858418 for ; Mon, 2 May 2022 11:17:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D30BC3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651490236; bh=f6loq50SlfRM1L8zkPKZJf5/C4h5lnoiwACNo5/LTFA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Vvjnee2sEgwdtPNQI25kj7n+eP8Fatkr/GZ80GYrkAyA+E8rhCzhICD0y04KmQko1 8H/n8vAsvvBn6b/A1cl3tpeEFCmPTAkgNswQRmuVxPbsOy22K5WP4ioQsf9PMnP5o8 I3lifxfcccNfSauw494HZVdnmmQcvt2cvwSbQ5kQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 325FF3858D33 for ; Mon, 2 May 2022 11:16:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 325FF3858D33 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D00001F896 for ; Mon, 2 May 2022 11:16:46 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BDAC0133E5 for ; Mon, 2 May 2022 11:16:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MpghLZ69b2LTVgAAMHmgww (envelope-from ) for ; Mon, 02 May 2022 11:16:46 +0000 Date: Mon, 2 May 2022 13:16:46 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/104240 - SLP discovery with swapped comparisons MIME-Version: 1.0 Message-Id: <20220502111646.BDAC0133E5@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following extends SLP discovery to handle swapped operands in comparisons. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-05-02 Richard Biener PR tree-optimization/104240 * tree-vect-slp.cc (op1_op0_map): New. (vect_get_operand_map): Handle compares. (vect_build_slp_tree_1): Support swapped operands for tcc_comparison. * gcc.dg/vect/bb-slp-pr104240.c: New testcase. --- gcc/testsuite/gcc.dg/vect/bb-slp-pr104240.c | 14 ++++++++++++++ gcc/tree-vect-slp.cc | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr104240.c diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr104240.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr104240.c new file mode 100644 index 00000000000..78905a468e0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr104240.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target vect_cond_mixed } */ + +void foo (int *c, float *x, float *y) +{ + c[0] = x[0] < y[0]; + c[1] = y[1] > x[1]; + c[2] = x[2] < y[2]; + c[3] = x[3] < y[3]; +} + +/* { dg-final { scan-tree-dump "optimized: basic block" "slp2" } } */ diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 0d400c00df1..2685bc10347 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -462,6 +462,7 @@ static const int cond_expr_maps[3][5] = { static const int arg1_map[] = { 1, 1 }; static const int arg2_map[] = { 1, 2 }; static const int arg1_arg4_map[] = { 2, 1, 4 }; +static const int op1_op0_map[] = { 2, 1, 0 }; /* For most SLP statements, there is a one-to-one mapping between gimple arguments and child nodes. If that is not true for STMT, @@ -482,6 +483,9 @@ vect_get_operand_map (const gimple *stmt, unsigned char swap = 0) if (gimple_assign_rhs_code (assign) == COND_EXPR && COMPARISON_CLASS_P (gimple_assign_rhs1 (assign))) return cond_expr_maps[swap]; + if (TREE_CODE_CLASS (gimple_assign_rhs_code (assign)) == tcc_comparison + && swap) + return op1_op0_map; } gcc_assert (!swap); if (auto call = dyn_cast (stmt)) @@ -1116,6 +1120,12 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, && (alt_stmt_code == PLUS_EXPR || alt_stmt_code == MINUS_EXPR) && rhs_code == alt_stmt_code) + && !(first_stmt_code.is_tree_code () + && rhs_code.is_tree_code () + && (TREE_CODE_CLASS (tree_code (first_stmt_code)) + == tcc_comparison) + && (swap_tree_comparison (tree_code (first_stmt_code)) + == tree_code (rhs_code))) && !(STMT_VINFO_GROUPED_ACCESS (stmt_info) && (first_stmt_code == ARRAY_REF || first_stmt_code == BIT_FIELD_REF @@ -1313,6 +1323,12 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, continue; } } + + if (rhs_code.is_tree_code () + && TREE_CODE_CLASS ((tree_code)rhs_code) == tcc_comparison + && (swap_tree_comparison ((tree_code)first_stmt_code) + == (tree_code)rhs_code)) + swap[i] = 1; } matches[i] = true; @@ -1326,7 +1342,8 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, with the permute we are going to use. */ if (alt_stmt_code != ERROR_MARK && (!alt_stmt_code.is_tree_code () - || TREE_CODE_CLASS (tree_code (alt_stmt_code)) != tcc_reference)) + || (TREE_CODE_CLASS (tree_code (alt_stmt_code)) != tcc_reference + && TREE_CODE_CLASS (tree_code (alt_stmt_code)) != tcc_comparison))) { *two_operators = true; }