From patchwork Thu Mar 23 08:31:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 73893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2787751wrt; Thu, 23 Mar 2023 01:32:27 -0700 (PDT) X-Google-Smtp-Source: AK7set8AsmkrXnlfDc3VjzJlah1VlGxZE6SBOKxA3MujASWrqTFBAzmTygXIJrZKB+E+82+umBq9 X-Received: by 2002:a05:6402:8ce:b0:4fd:1ff0:2291 with SMTP id d14-20020a05640208ce00b004fd1ff02291mr9444304edz.18.1679560347106; Thu, 23 Mar 2023 01:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679560347; cv=none; d=google.com; s=arc-20160816; b=ASGCbKgBdht2bONEKmGvs4cf/V3H5G4nI4SbExFx+mp1hwUntmjMLdwAVFu4D/fpaF EVrA3dUp4mg5FI5pkTJaKLF/kFG8nMI0C9ofuXleSjPkfXAuRoNtGudAxmDdA3fzqaJP WrDgW6YtdkjZvqkO/seJMHL6ZBSecTu5D2mfsAwmUIhRt11VXJiLt8VxfCFnGFMpiyWx 9R+qkmPXw1eDk+azKU4ahQft1+7cc9vJHZFgvQcJ++5/3/kMvEBETdsp+BnrDfYcPFki V+e8Ge4Km0u0YuPOC0WYx9Uf3IKAE/j2OLg/giMY94fTXuuMDoV/CsjeTlO8XRYJynzZ H7Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=SCx6KWQ3O/y6HWt80w5EbRi1TfgGkpRrHsk87OF8hYQ=; b=wAcz5cYgOhCSAEteRteQTI7wEbdV8IaTT9msdXmlSs01LGtfo7HN960su1/1dqvXZL zMpnaqnhybo70D5B508YaOFQikl3NM3hJNFjCE6vfwCgT5il923xgoqkiUThdf8XGtPK Fk0MhZf6LDOgJx0cob3wARtPD/Qz1sUIS1i3eqO3LW3RL1hqxBOCEnNok9wQLwSamGTZ 19zGxoiYgkYa7nL/IJ61Jfm2zeRlzx0ScqTexEZk7BX9i6kQx2Vv98yYfgKpmGiJmE6D ZCLEYQz06s0K/oCQiux8eBuVrtUdoC9y1h2HdUQqsGOmao4/ZPJvAhpqcpMmvKW/88Tc qjZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Afphl1ki; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n22-20020a05640206d600b004acd42c5911si19783090edy.241.2023.03.23.01.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 01:32:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Afphl1ki; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 197B938515C9 for ; Thu, 23 Mar 2023 08:32:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 197B938515C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679560346; bh=SCx6KWQ3O/y6HWt80w5EbRi1TfgGkpRrHsk87OF8hYQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Afphl1kiK1WF8stAJ75gPupprxK/hzPqUBh+zgByCX+OcpCAPmhLJV41nAMVOpWUA YBR1oEiZ0PlHcDyIwSpgCnVWGcLlHFP5Ai3vrMltR5j435uR7oOHMI8kBk4xj1a3QP 5WDjyxItXC5Ruc6xxN8lCn5uH7WsHhUTQw27p4ps= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 15C5A38515C9 for ; Thu, 23 Mar 2023 08:31:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15C5A38515C9 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-131-u6V-ovvzNSa5anmpvuK96g-1; Thu, 23 Mar 2023 04:31:14 -0400 X-MC-Unique: u6V-ovvzNSa5anmpvuK96g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AC0C185A790; Thu, 23 Mar 2023 08:31:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 481471731B; Thu, 23 Mar 2023 08:31:14 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32N8VBQw3571123 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Mar 2023 09:31:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32N8VAB43571122; Thu, 23 Mar 2023 09:31:10 +0100 Date: Thu, 23 Mar 2023 09:31:10 +0100 To: Richard Biener , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-vect-generic: Fix up expand_vector_condition [PR109176] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761146670536596875?= X-GMAIL-MSGID: =?utf-8?q?1761146670536596875?= 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. 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? 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. Jakub --- 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); +}