From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id AA5763858D20 for ; Thu, 29 Feb 2024 10:16:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA5763858D20 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 AA5763858D20 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=1709201817; cv=none; b=Cb5f8tc0JWYS357bMnGuUPJKo5spBCXstYygfQTzFdfmuqSGozaIGSwxk23mnSZYqLt9ilyE3hTSMqiXnt/3nR2BCJh/TU/vuQlv0cVC4m0FtJ36Tr+OBax+KLuGY2vl/Seepnray5kX01hbs6A3xycfEsXMLnpZzX5u/vDPAXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709201817; c=relaxed/simple; bh=6PeVFxdT8lHOSMvRxEiKGMKJqquxIPUw++aqkHMsucU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=I2+MylV0+jnkEAZGS1G+0wbsk0Ct7xc+V4TjJBZFkvG8tBbl896GzTtc1x5kGMDLU38zHRFoOXyce27/XvB5Dh23xZkc+AxukfDdTYS8gsYCexaDBIuJOM3oeiDfpsSTkYf1I8/OR9F/jk5C8YMwPDGBm+0XYQqipRjDOJLEsFg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 890331F7D2; Thu, 29 Feb 2024 10:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709201814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ky4DwxDfZNmR+kur35Mj5F2aleW/L9wgS/+vb0Masgo=; b=RFbnVbi2EmXBDk0fGX1BYNDoOfAV4wOiicVrT1jn2q6Qz2Sr8hOvQg4fqW/stkr4+q9ctI B/ddvHMPxM8AiszOtC18SFHPreWAubPQ2grhuSLsRxAJpFpEQFn4hOcAiurBf77EW+0x8T o6qHMJSb3zWTWtHf+dOJLQDdr9vhJJc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709201814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ky4DwxDfZNmR+kur35Mj5F2aleW/L9wgS/+vb0Masgo=; b=CcGnI0+Cx8M1WrTy9hodOV9KprLGls1OyAZFeZlJeuHx9o+fzhC4cRZNReKPsZOO8PaaD6 nrrqUlFCokZWt5Aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709201814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ky4DwxDfZNmR+kur35Mj5F2aleW/L9wgS/+vb0Masgo=; b=RFbnVbi2EmXBDk0fGX1BYNDoOfAV4wOiicVrT1jn2q6Qz2Sr8hOvQg4fqW/stkr4+q9ctI B/ddvHMPxM8AiszOtC18SFHPreWAubPQ2grhuSLsRxAJpFpEQFn4hOcAiurBf77EW+0x8T o6qHMJSb3zWTWtHf+dOJLQDdr9vhJJc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709201814; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ky4DwxDfZNmR+kur35Mj5F2aleW/L9wgS/+vb0Masgo=; b=CcGnI0+Cx8M1WrTy9hodOV9KprLGls1OyAZFeZlJeuHx9o+fzhC4cRZNReKPsZOO8PaaD6 nrrqUlFCokZWt5Aw== Date: Thu, 29 Feb 2024 11:16:54 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek , richard.sandiford@arm.com Subject: Re: [PATCH] middle-end/114070 - VEC_COND_EXPR folding Message-ID: <66896q4p-r807-1865-s6q6-p74622o26040@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-2.10 / 50.00]; ARC_NA(0.00)[]; FAKE_REPLY(1.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]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -2.10 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 List-Id: On Thu, 29 Feb 2024, Richard Biener wrote: > 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? I've tried moving vector lowering, first try to after the first forwprop after IPA. That exposes (at least) invariant motion creating unsupported COND_EXPRs - we hoist a vector PHI as _2 ? _3 : _6 and that might lead to unsupported BLKmode moves. I think there's some latent issues to be fixed in passes. A more conservative move is to duplicate vector lowering into the loop/non-loop sections and put it right before vectorization (but there's invariant motion after it, so the above issue will prevail). Since the vectorizer currently cannot handle existing vector code "re-vectorization" is best done on lowered code (after that got some cleanup). Also SLP can interface with existing vectors, but currently only non-BLKmode ones, so that would benefit as well. That said, the quick experiment shows this isn't anything for stage4. Richard. > 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 > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)