From patchwork Tue Apr 27 13:05:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1470682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MJg5MvN7; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FV2742tTlz9t0k for ; Tue, 27 Apr 2021 23:05:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68620398B166; Tue, 27 Apr 2021 13:05:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68620398B166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619528713; bh=5hub8Cb4V8ndvMWQ/fMAuM3hf5oYkuYIPhGnwS7prYI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=MJg5MvN7mbKZWMV0bzmsOsP3Prc1F3FWvBg1oaGrVb2T09fTqHXwD+S9jQ5YCf0Re B4HYUkkl0Q5R5xTIeKOkRDsKlVsqvhSKuivYb9/HCN7Lgn/O321SdcC1jJMnivSF7z 14G0LNfnOMmhiKUQTfLXlmxIg47Xbqf+dkYyOyzw= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 84E08398B166 for ; Tue, 27 Apr 2021 13:05:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 84E08398B166 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-7-ssoE9O19NyCI-TOUrbf_Jg-1; Tue, 27 Apr 2021 09:05:08 -0400 X-MC-Unique: ssoE9O19NyCI-TOUrbf_Jg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED426801106; Tue, 27 Apr 2021 13:05:06 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-114-59.ams2.redhat.com [10.36.114.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A40261145; Tue, 27 Apr 2021 13:05:05 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 13RD53TE1542977 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 15:05:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 13RD53ar1542976; Tue, 27 Apr 2021 15:05:03 +0200 Date: Tue, 27 Apr 2021 15:05:02 +0200 To: Richard Biener Subject: [PATCH] veclower: Fix up vec_shl matching of VEC_PERM_EXPR [PR100239] Message-ID: <20210427130502.GZ1179226@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs at -O0, because lower_vec_perm sees the _1 = { 0, 0, 0, 0, 0, 0, 0, 0 }; _2 = VEC_COND_EXPR <_1, { -1, -1, -1, -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0, 0, 0, 0 }>; _3 = { 6, 0, 0, 0, 0, 0, 0, 0 }; _4 = VEC_PERM_EXPR <{ 0, 0, 0, 0, 0, 0, 0, 0 }, _2, _3>; and as the ISA is SSE2, there is no support for the particular permutation nor for variable mask permutation. But, the code to match vec_shl matches it, because the permutation has the first operand a zero vector and the mask picks all elements randomly from that vector. So, in the end that isn't a vec_shl, but the permutation could be in theory optimized into the first argument. As we keep it as is, it will fail during expansion though, because that for vec_shl correctly requires that it actually is a shift: unsigned firstidx = 0; for (unsigned int i = 0; i < nelt; i++) { if (known_eq (sel[i], nelt)) { if (i == 0 || firstidx) return NULL_RTX; firstidx = i; } else if (firstidx ? maybe_ne (sel[i], nelt + i - firstidx) : maybe_ge (sel[i], nelt)) return NULL_RTX; } if (firstidx == 0) return NULL_RTX; first = firstidx; The if (firstidx == 0) return NULL; is what is missing a counterpart on the lower_vec_perm side. As with optimize != 0 we fold it in other spots, I think it is not needed to optimize this cornercase in lower_vec_perm (which would mean we'd need to recurse on the newly created _4 = { 0, 0, 0, 0, 0, 0, 0, 0 }; whether it is supported or not). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-04-27 Jakub Jelinek PR tree-optimization/100239 * tree-vect-generic.c (lower_vec_perm): Don't accept constant permutations with all indices from the first zero element as vec_shl. * gcc.dg/pr100239.c: New test. Jakub --- gcc/tree-vect-generic.c.jj 2021-01-27 19:30:20.763625450 +0100 +++ gcc/tree-vect-generic.c 2021-04-26 14:41:37.909432994 +0200 @@ -1515,7 +1515,7 @@ lower_vec_perm (gimple_stmt_iterator *gs elements + i - first) : maybe_ge (poly_uint64 (indices[i]), elements)) break; - if (i == elements) + if (first && i == elements) { gimple_assign_set_rhs3 (stmt, mask); update_stmt (stmt); --- gcc/testsuite/gcc.dg/pr100239.c.jj 2021-04-26 14:45:28.517819255 +0200 +++ gcc/testsuite/gcc.dg/pr100239.c 2021-04-26 14:45:09.985029312 +0200 @@ -0,0 +1,12 @@ +/* PR tree-optimization/100239 */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +typedef short __attribute__((__vector_size__ (8 * sizeof (short)))) V; +V v, w; + +void +foo (void) +{ + w = __builtin_shuffle (v != v, 0 < (V) {}, (V) {192} >> 5); +}