From patchwork Mon Nov 6 14:30:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1860199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=J4D+Y23q; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=7Ofz5MCf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPDKv73ZRz1yQ9 for ; Tue, 7 Nov 2023 01:30:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C434E385703A for ; Mon, 6 Nov 2023 14:30:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 9A3193857701 for ; Mon, 6 Nov 2023 14:30:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A3193857701 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A3193857701 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699281044; cv=none; b=xynRKsqLamtCcNU+5OXadX8WHlDMXbw9ERhP0teuKIOtz/pPIBU6y7z0n3amPuNoKNm4mM0ADfmdxQ9LoG+sWpluLNEdBhsez/5kx9Qyyfhf4/CI4F745tVoj9vRJpD+7meLLIiP8We7iEr/nbEI820aEWd+1gJDqYbx1NCegzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699281044; c=relaxed/simple; bh=gW4D2qhyEMzNwiu4j9VgIPmWkxeBC8ajVFxswLRvKgs=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=IXaFC+jZGp2p6LAF1zi3jCjmoa4x3w0gn/B5t7CvvKb6bk46T2EEiQyll+voWE1x0+ebBoUnD7/I+Cup8TnqQG90lt7GWdj2vExCGYgiwot1k7SMsRL6eLGa3ak1Jj+rSdaMFZpXehqCj4MhmXdNA8P/G7cKRng1yw4AkKzXSTs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B344521D2D for ; Mon, 6 Nov 2023 14:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699281041; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HoiiwLdIa9s1UyjZdmriCauqPPvr6rlrNDYLVEtnpZ4=; b=J4D+Y23qL9UY4TCWhuG0gb5ifdBVApw1bV1oiv/3aRjLYbLDqdivVKLcYJ+0g42L+Gvjbk 1YP6yoxsumVGRJWrvUcOFUnxLqiLZBxleduQ4aFkp/IPD2s1LPCRmEALrVcXD+Lxc1YKi8 G73vjBnzRetCipp8LKA+hmvNuaJfZ+c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699281041; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=HoiiwLdIa9s1UyjZdmriCauqPPvr6rlrNDYLVEtnpZ4=; b=7Ofz5MCfdgYBo+g13U6YjZEJ2x7kNhRFjPzY/SYdtCja02xAmyoRo/49NCq3d2jNZuecMO HVWlj5jOUDgMSPBA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 6F6522C258 for ; Mon, 6 Nov 2023 14:30:41 +0000 (UTC) Date: Mon, 6 Nov 2023 14:30:41 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112405 - SIMD clone calls with (loop) mask User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20231106143055.C434E385703A@sourceware.org> The following fixes the mask argument generation for SIMD clone calls under either loop masking or when the actual call is not masked but only a inbranch simd clone is available. The issue was that we tried to directly convert the vector mask to the call argument type but SIMD clone masks require 1 or 0 (which could be even float) values for mask elements so we have to resort to a VEC_COND_EXPR to generate them just like we do for regular passing of the mask. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112405 * tree-vect-stmts.cc (vectorizable_simd_clone_call): Properly handle invariant and/or loop mask passing. --- gcc/tree-vect-stmts.cc | 62 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index eefb1eec1ef..65883e04ad7 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -4814,36 +4814,42 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, else mask = vect_build_all_ones_mask (vinfo, stmt_info, masktype); - if (!useless_type_conversion_p (TREE_TYPE (mask), masktype)) + gassign *new_stmt; + if (SCALAR_INT_MODE_P (bestn->simdclone->mask_mode)) { - gassign *new_stmt; - if (bestn->simdclone->mask_mode != VOIDmode) - { - /* This means we are dealing with integer mask modes. - First convert to an integer type with the same size as - the current vector type. */ - unsigned HOST_WIDE_INT intermediate_size - = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (mask))); - tree mid_int_type = - build_nonstandard_integer_type (intermediate_size, 1); - mask = build1 (VIEW_CONVERT_EXPR, mid_int_type, mask); - new_stmt - = gimple_build_assign (make_ssa_name (mid_int_type), - mask); - gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); - /* Then zero-extend to the mask mode. */ - mask = fold_build1 (NOP_EXPR, masktype, - gimple_get_lhs (new_stmt)); - } - else - mask = build1 (VIEW_CONVERT_EXPR, masktype, mask); - - new_stmt = gimple_build_assign (make_ssa_name (masktype), - mask); - vect_finish_stmt_generation (vinfo, stmt_info, - new_stmt, gsi); - mask = gimple_assign_lhs (new_stmt); + /* This means we are dealing with integer mask modes. + First convert to an integer type with the same size as + the current vector type. */ + unsigned HOST_WIDE_INT intermediate_size + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (mask))); + tree mid_int_type = + build_nonstandard_integer_type (intermediate_size, 1); + mask = build1 (VIEW_CONVERT_EXPR, mid_int_type, mask); + new_stmt + = gimple_build_assign (make_ssa_name (mid_int_type), + mask); + gsi_insert_before (gsi, new_stmt, GSI_SAME_STMT); + /* Then zero-extend to the mask mode. */ + mask = fold_build1 (NOP_EXPR, masktype, + gimple_get_lhs (new_stmt)); + } + else if (bestn->simdclone->mask_mode == VOIDmode) + { + tree one = fold_convert (TREE_TYPE (masktype), + integer_one_node); + tree zero = fold_convert (TREE_TYPE (masktype), + integer_zero_node); + mask = build3 (VEC_COND_EXPR, masktype, mask, + build_vector_from_val (masktype, one), + build_vector_from_val (masktype, zero)); } + else + gcc_unreachable (); + + new_stmt = gimple_build_assign (make_ssa_name (masktype), mask); + vect_finish_stmt_generation (vinfo, stmt_info, + new_stmt, gsi); + mask = gimple_assign_lhs (new_stmt); vargs.safe_push (mask); } }