From patchwork Wed Mar 22 10:16:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 66737 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 550743858C1F for ; Wed, 22 Mar 2023 10:16:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 550743858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679480198; bh=7PuIbVNLg3KnW7qQho0Wlratmx67EIGDTFZ/CF2sgLo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lkDvi1GG57KuG34qaYBgC6kXMG+kZjWKQaBSeQhfcGwIk+x8FkcEuakviSch5lTAt 39SNWhG8soYJJ1sJFyt2Mph8V9R5PbWfXN+knK3MKcFIrjljhNnmCylue+gycteeVy N53/kBnSJfBHKYWt3rgCUsu155i0FmA10lHpbUKI= 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 502C03858C1F for ; Wed, 22 Mar 2023 10:16:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 502C03858C1F Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-H5n4ySffOr68rfxaLQr8VA-1; Wed, 22 Mar 2023 06:16:08 -0400 X-MC-Unique: H5n4ySffOr68rfxaLQr8VA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5F5EC1C02D3A; Wed, 22 Mar 2023 10:16:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B72F2027040; Wed, 22 Mar 2023 10:16:07 +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 32MAG5jr3389978 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Mar 2023 11:16:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32MAG46W3389977; Wed, 22 Mar 2023 11:16:04 +0100 Date: Wed, 22 Mar 2023 11:16:03 +0100 To: Richard Biener , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Fix up fneg/fadd simplification [PR109230] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase is miscompiled on aarch64-linux. match.pd has a simplification for addsub, where it negates one of the vectors in twice as large floating point element vector (effectively negating every other element) and then doing addition. But a requirement for that is that the permutation picks the right elements, in particular 0, nelts+1, 2, nelts+3, 4, nelts+5, ... The pattern tests this with sel.series_p (0, 2, 0, 2) check, which as documented verifies that the even elements of the permutation mask are identity, but doesn't say anything about the others. The following patch fixes it by also checking that the odd elements start at nelts + 1 with the same step of 2. Bootstrapped/regtested on aarch64-linux, x86_64-linux and i686-linux, ok for trunk? 2023-03-22 Jakub Jelinek PR tree-optimization/109230 * match.pd (fneg/fadd simplify): Verify also odd permutation indexes. * gcc.dg/pr109230.c: New test. Jakub --- gcc/match.pd.jj 2023-02-18 12:38:30.967022708 +0100 +++ gcc/match.pd 2023-03-21 19:59:40.209634256 +0100 @@ -8096,6 +8096,7 @@ and, scalar_mode inner_mode = GET_MODE_INNER (vec_mode); } (if (sel.series_p (0, 2, 0, 2) + && sel.series_p (1, 2, nelts + 1, 2) && GET_MODE_2XWIDER_MODE (inner_mode).exists (&wide_elt_mode) && multiple_p (GET_MODE_NUNITS (vec_mode), 2, &wide_nunits) && related_vector_mode (vec_mode, wide_elt_mode, --- gcc/testsuite/gcc.dg/pr109230.c.jj 2023-03-21 20:03:52.811979268 +0100 +++ gcc/testsuite/gcc.dg/pr109230.c 2023-03-21 20:03:35.884224342 +0100 @@ -0,0 +1,31 @@ +/* PR tree-optimization/109230 */ +/* { dg-do run } */ +/* { dg-options "-O2 -Wno-psabi" } */ + +#if __SIZEOF_FLOAT__ == __SIZEOF_INT__ +typedef float V __attribute__((vector_size (4 * sizeof (float)))); +typedef int VI __attribute__((vector_size (4 * sizeof (float)))); + +__attribute__((noipa)) V +foo (V x, V y) +{ + V a = x - y; + V b = y + x; + return __builtin_shuffle (b, a, (VI) { 0, 5, 2, 3 }); +} + +int +main () +{ + V a = (V) { 1.0f, 2.0f, 3.0f, 4.0f }; + V b = (V) { 8.0f, 9.0f, 10.0f, 11.0f }; + V c = foo (a, b); + if (c[0] != 9.0f || c[1] != -7.0f || c[2] != 13.0f || c[3] != 15.0f) + __builtin_abort (); +} +#else +int +main () +{ +} +#endif