From patchwork Thu Feb 29 08:35:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1906229 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=RodnWFsr; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vY8LltMU; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=RodnWFsr; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vY8LltMU; 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 4Tll1l2JPGz20Qg for ; Thu, 29 Feb 2024 19:36:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 050F13858C32 for ; Thu, 29 Feb 2024 08:36:25 +0000 (GMT) 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.223.131]) by sourceware.org (Postfix) with ESMTPS id B48973858CDA for ; Thu, 29 Feb 2024 08:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B48973858CDA 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 B48973858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709195722; cv=none; b=M1Q0cDyDC5Tgeu4QRj4p/MC7158yLr4Ou5Q+neYdK1n2Nxm6/HWzxE6eccuL67pJaRmScGiP/PNyw05nYovZ3IQSoIg9JL1J3sDok6lo+opwf4fPoIsl7j7iZ9og487etDMgki+ypWGPElWPs4TbJAF/QaZKRFKkaIm6BC1R7Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709195722; c=relaxed/simple; bh=ezooX7z+L6bTsF8EVb8xlxDk+0d+Q9APG2udtWQciJ0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=mt3zGOmYUeiYFYiU5GOeGZ/27grVI/y8Xbcmu0YuM6ndt3Zhv4bSJN+43XTkcmq10V6lzBg5Lm+w9R8h/JuOssirbcDG3ZfQg3/TvBBC2pCn8a1QRxBWx5PFnvHKVoZbw+cjWGEKvfBxjBXFixE+8oT97ZFL+iQ3lsjd+dSc9V0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C1DA51F7CA; Thu, 29 Feb 2024 08:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709195705; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=14K9E+AkmBuvOiMBwY7kkEZdjPxRvZ5I/zIwXKtjSDw=; b=RodnWFsrOtNo0hHT1soNbpEOzFUX3w7N9MtOVZFuI6fv2sd6oiiEWwYIZQXfTV8t1rFFCn t9gZuDiciK/bann2XH+X9KygkrDpIFNcO4bS+f5zcHJfOp0pqN7fPpWIpjd0rfa9K2MpfZ XK7qkuqOd5ZJTcMWt3jA1izJkcWrgOI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709195705; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=14K9E+AkmBuvOiMBwY7kkEZdjPxRvZ5I/zIwXKtjSDw=; b=vY8LltMUE2gJtrHMvcxxqb+p3EDWEd6yYBxee0DEkAqdRLYFNsvw08G1oK/xXGQqtMHOg4 5e1d9+/GJCUAXZDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709195705; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=14K9E+AkmBuvOiMBwY7kkEZdjPxRvZ5I/zIwXKtjSDw=; b=RodnWFsrOtNo0hHT1soNbpEOzFUX3w7N9MtOVZFuI6fv2sd6oiiEWwYIZQXfTV8t1rFFCn t9gZuDiciK/bann2XH+X9KygkrDpIFNcO4bS+f5zcHJfOp0pqN7fPpWIpjd0rfa9K2MpfZ XK7qkuqOd5ZJTcMWt3jA1izJkcWrgOI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709195705; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=14K9E+AkmBuvOiMBwY7kkEZdjPxRvZ5I/zIwXKtjSDw=; b=vY8LltMUE2gJtrHMvcxxqb+p3EDWEd6yYBxee0DEkAqdRLYFNsvw08G1oK/xXGQqtMHOg4 5e1d9+/GJCUAXZDg== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 9ACA41329E; Thu, 29 Feb 2024 08:35:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id LI0rJLlB4GX+VwAAn2gu4w (envelope-from ); Thu, 29 Feb 2024 08:35:05 +0000 Date: Thu, 29 Feb 2024 09:35:05 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek , richard.sandiford@arm.com Subject: [PATCH] middle-end/114070 - VEC_COND_EXPR folding MIME-Version: 1.0 Message-Id: <20240229083505.9ACA41329E@imap2.dmz-prg2.suse.org> Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-0.999]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.993]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-11.0 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.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 The following amends the PR114070 fix to optimistically allow the folding when we cannot expand the current vec_cond using vcond_mask and we're still before vector lowering. This leaves a small window between vectorization and lowering where we could break vec_conds that can be expanded via vcond{,u,eq}, most susceptible is the loop unrolling pass which applies VN and thus possibly folding to the unrolled body of a vectorized loop. This gets back the folding for targets that cannot do vectorization. It doesn't get back the folding for x86 with AVX512 for example since that can handle the original IL but not the folded since it misses some vcond_mask expanders. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. As said for stage1 I want to move vector lowering before vectorization. While I'm not entirely happy with this patch it forces us into the correct direction, getting vcond_mask and vcmp{,u,eq} patterns implemented. We could use canonicalize_math_p () to close the vectorizer -> vector lowering gap but this only works when that pass is run (not with -Og or when disabled). We could add a new PROP_vectorizer_il and disable the folding if the vectorizer ran. Or we could simply live with the regression. Any preferences? Thanks, Richard. PR middle-end/114070 * match.pd ((c ? a : b) op d --> c ? (a op d) : (b op d)): Allow the folding if before lowering and the current IL isn't supported with vcond_mask. --- gcc/match.pd | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index f3fffd8dec2..4edba7c84fb 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5153,7 +5153,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op (vec_cond:s @0 @1 @2) (vec_cond:s @0 @3 @4)) (if (TREE_CODE_CLASS (op) != tcc_comparison || types_match (type, TREE_TYPE (@1)) - || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)) + || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK) + || (optimize_vectors_before_lowering_p () + /* The following is optimistic on the side of non-support, we are + missing the legacy vcond{,u,eq} cases. Do this only when + lowering will be able to fixup.. */ + && !expand_vec_cond_expr_p (TREE_TYPE (@1), + TREE_TYPE (@0), ERROR_MARK))) (vec_cond @0 (op! @1 @3) (op! @2 @4)))) /* (c ? a : b) op d --> c ? (a op d) : (b op d) */ @@ -5161,13 +5167,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op (vec_cond:s @0 @1 @2) @3) (if (TREE_CODE_CLASS (op) != tcc_comparison || types_match (type, TREE_TYPE (@1)) - || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)) + || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK) + || (optimize_vectors_before_lowering_p () + && !expand_vec_cond_expr_p (TREE_TYPE (@1), + TREE_TYPE (@0), ERROR_MARK))) (vec_cond @0 (op! @1 @3) (op! @2 @3)))) (simplify (op @3 (vec_cond:s @0 @1 @2)) (if (TREE_CODE_CLASS (op) != tcc_comparison || types_match (type, TREE_TYPE (@1)) - || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)) + || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK) + || (optimize_vectors_before_lowering_p () + && !expand_vec_cond_expr_p (TREE_TYPE (@1), + TREE_TYPE (@0), ERROR_MARK))) (vec_cond @0 (op! @3 @1) (op! @3 @2))))) #if GIMPLE