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: 73341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2258856wrt; Wed, 22 Mar 2023 03:16:54 -0700 (PDT) X-Google-Smtp-Source: AK7set/RvT5T+4Y2xidg0Uuq1y+yHc3a5Y7LEzVPOlY6FjlXOXEK0bhBmphAB6tybpSBO7lXBF1W X-Received: by 2002:a17:906:a04c:b0:933:1967:a98a with SMTP id bg12-20020a170906a04c00b009331967a98amr5787409ejb.17.1679480214903; Wed, 22 Mar 2023 03:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679480214; cv=none; d=google.com; s=arc-20160816; b=HAZh3zRcisayz0hYWNvsNsV+ekxHiRlBfobalrp88LLGxk4XljPH4i2xGv0PvGYMvm V+hk+QxZicmn4dZ42SCkWmjMWN86nE95FzRzTzSeZoHl2O0xvKCUaF3HG32fq65nYrMa GuG2qhrqzzJ3Vg4cd0MWlxEpyBoIEl3fRIkyOno7KLSdCKufgpI5w9wF/c+MMJj/s2UA 1O/WvvRp4xkJuhrG+5MU24tBzYfwNbVBofGXQZdnlTqiK6X5BdFTxI8ICCv2P5uc0PPq ExYuF7giMIMQKtijM898YGsgynuKHtTwBrNLYZ2ssu5uUhHTrB+WzGnOu+RdwYFxMaa/ sgIw== 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=7PuIbVNLg3KnW7qQho0Wlratmx67EIGDTFZ/CF2sgLo=; b=gmyivv9YW5c6fpIRtO3YyeWqxH3o7jk0gGS77FQpu0yZzjAeLCXjRGXK+OkrMKcCDa +UsV5fPqCh0wHvrZhBF0mpG7bQFHRMCGHll01SX5yEhiSr0zqpYFTVjDocXS4HSfA0lx t0G/WfwWX5k4+xHFZ7531dFJJlCmlVojrJJTz7ZrYdINqnJbq2yWkoYrtmQK6oKV8FPC It24BfKJFL2Bq8SVaHUYQGG0o6mjWILXJnAXR1tutHlPh7kp10i3AE462/nq1LXoPqQJ zfvE5uZW0U2n+NiI6QktFId/tJAjhm1JAV6hnnUhVeS87LK6tB14dugcPJnFcDU0xgul vtqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yUiTBHuS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ho39-20020a1709070ea700b0093a09d32b52si5156531ejc.422.2023.03.22.03.16.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 03:16:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yUiTBHuS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B27D83858418 for ; Wed, 22 Mar 2023 10:16:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B27D83858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679480213; 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=yUiTBHuSoamU7QeVFpg2uX5TlqNypPLQD5ShvmtGHszeb9vTD/UWBO/u6aTOW1HRF jEfzOcWYN6fOq4/cot6E8JjozdsdllB5NV/0noSgrqEaQwKy8xG05fn4qOMaZKpzht 5AfRc5TSFoS88cbOF73h+DrJJ9400glrl+IOBkPg= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761062645598661098?= X-GMAIL-MSGID: =?utf-8?q?1761062645598661098?= 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