From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 83673385B516 for ; Thu, 23 Mar 2023 08:48:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83673385B516 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id BA0FA339C9; Thu, 23 Mar 2023 08:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1679561316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dHVk/At9A47Z7965/akMfs8li8+YlT4KFOFtFpiaIEU=; b=oWzDqCmslB12u4fmfpb7aBs2oxdXYrsDoeD6emERXvr4hP6Ndf939ycbUSCKV2JzsKxGAs F2fmZBnZy9WAwnEDDu8DnGTpN1dggSRbjob1J6+iRyzllwulq+/4+86Na9T30lDocWc1Ig 3zUexOHC/3STDuiys7Daraz1AM52qvY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1679561316; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dHVk/At9A47Z7965/akMfs8li8+YlT4KFOFtFpiaIEU=; b=Rerlwsl8UDtArWvPivbQNINfPQpZ10N+D+aTvvbsmiBQBVCGj814rhEgcu+0o05AFBzYHZ RkUpFKgV7nVe7FCw== 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 A55982C141; Thu, 23 Mar 2023 08:48:36 +0000 (UTC) Date: Thu, 23 Mar 2023 08:48:36 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: Richard Sandiford , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-vect-generic: Fix up expand_vector_condition [PR109176] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP 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, 23 Mar 2023, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs on aarch64-linux, because > expand_vector_condition attempts to piecewise lower SVE > d_3 = a_1(D) < b_2(D); > _5 = VEC_COND_EXPR ; > which isn't possible - nunits_for_known_piecewise_op ICEs but > the rest of the code assumes constant number of elements too. > > expand_vector_condition attempts to find if a (rhs1) is a SSA_NAME > for comparison and calls expand_vec_cond_expr_p (type, TREE_TYPE (a1), code) > where a1 is one of the operands of the comparison and code is the comparison > code. That one indeed isn't supported here, but what aarch64 SVE supports > are the individual statements, comparison (expand_vec_cmp_expr_p) and > expand_vec_cond_expr_p (type, TREE_TYPE (a), SSA_NAME), the latter because > that function starts with > if (VECTOR_BOOLEAN_TYPE_P (cmp_op_type) > && get_vcond_mask_icode (TYPE_MODE (value_type), > TYPE_MODE (cmp_op_type)) != CODE_FOR_nothing) > return true; > > In an earlier version of the patch (in the PR), we did this > if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (a)) > && expand_vec_cond_expr_p (type, TREE_TYPE (a), ERROR_MARK)) > return true; > before the code == SSA_NAME handling plus some further tweaks later. > While that fixed the ICE, it broke quite a few tests on x86 and some on > aarch64 too. The problem is that expand_vector_comparison doesn't lower > comparisons which aren't supported and only feed VEC_COND_EXPR first operand > and expand_vector_condition succeeds for those, so with the above mentioned > change we'd verify the VEC_COND_EXPR is implementable using optab alone, > but nothing would verify the tcc_comparison which relied on > expand_vector_condition to verify. Ah, indeed - all a bit twisty. > So, the following patch instead queries whether optabs can handle the > comparison and VEC_COND_EXPR together (if a (rhs1) is a comparison; > otherwise as before it checks only the VEC_COND_EXPR) and if that fails, > also checks whether the two operations could be supported individually > and only if even that fails does the piecewise lowering. > > Bootstrapped/regtested on x86_64-linux, i686-linux and aarch64-linux, ok for > trunk? OK. Thanks for digging into it. Richard. > 2023-03-23 Jakub Jelinek > > PR tree-optimization/109176 > * tree-vect-generic.cc (expand_vector_condition): If a has > vector boolean type and is a comparison, also check if both > the comparison and VEC_COND_EXPR could be successfully expanded > individually. > > * gcc.target/aarch64/sve/pr109176.c: New test. > > --- gcc/tree-vect-generic.cc.jj 2023-03-21 13:28:21.354671095 +0100 > +++ gcc/tree-vect-generic.cc 2023-03-22 12:53:27.853986127 +0100 > @@ -1063,6 +1063,15 @@ expand_vector_condition (gimple_stmt_ite > return true; > } > > + /* If a has vector boolean type and is a comparison, above > + expand_vec_cond_expr_p might fail, even if both the comparison and > + VEC_COND_EXPR could be supported individually. See PR109176. */ > + if (a_is_comparison > + && VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (a)) > + && expand_vec_cond_expr_p (type, TREE_TYPE (a), SSA_NAME) > + && expand_vec_cmp_expr_p (TREE_TYPE (a1), TREE_TYPE (a), code)) > + return true; > + > /* Handle vector boolean types with bitmasks. If there is a comparison > and we can expand the comparison into the vector boolean bitmask, > or otherwise if it is compatible with type, we can transform > --- gcc/testsuite/gcc.target/aarch64/sve/pr109176.c.jj 2023-03-22 12:19:21.672218631 +0100 > +++ gcc/testsuite/gcc.target/aarch64/sve/pr109176.c 2023-03-22 12:19:21.672218631 +0100 > @@ -0,0 +1,12 @@ > +/* PR tree-optimization/109176 */ > +/* { dg-do compile } */ > +/* { dg-additional-options "-O2" } */ > + > +#include > + > +svbool_t > +foo (svint8_t a, svint8_t b, svbool_t c) > +{ > + svbool_t d = svcmplt_s8 (svptrue_pat_b8 (SV_ALL), a, b); > + return svsel_b (d, c, d); > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)