From patchwork Fri Dec 2 09:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 28824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp737166wrr; Fri, 2 Dec 2022 01:40:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5x2Szgonf0bvBIdYrYfSV1kc2hQal/C2atoq4dGja3Oyw4qrNultGsPR8ixuUbQDzrVTUO X-Received: by 2002:a17:906:32d1:b0:7b2:af38:ef00 with SMTP id k17-20020a17090632d100b007b2af38ef00mr57227154ejk.546.1669974036473; Fri, 02 Dec 2022 01:40:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669974036; cv=none; d=google.com; s=arc-20160816; b=uJnN0Bc5xRqF5ZITBciYWMvJ6gh+cAoa3Py+bUkY2URIV6upi+U4f7p0h65CbeIIPf 7oa3t57hk0f2pvnQ2kiLCMo9yBm3FIdYmOhSpePkhN8QjqkclRbnV9SXilLoTZqYNyWH b3ekYcJfQX58lWDxuhTSVma23UPaosMIPYVj9on7YpTHaL2VQo7TyKKuq/x7p/59ROtj zFI28fHIHePeYUKXRfG3KvoNX+BKYis6lbrU4nGGuZtEoGqJv9GBlkBtmyYYei2CkDjB nd2uAmMg+PLO4NK5RbfB+FwIZ2MySwfqBPSE5Y+SBZiLeufgwx4oGw0SaIV/QlCeveDv AkbA== 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:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=pcWOCBe3al0OUM2q92EEB47M0tJtvzrVxDwdUh+Sv5M=; b=orzs6ZRm+NU4NCVa14315Z3qHmvzxS2HglGcSXKbxxg5i0waORFb+jhHfeFNFSlyQg l53D+YCaj+7bzQBiHgs7MM35F3qOqFH089u1zKKjH+6BOOMGZ5RlW3kr3eZsVkBP09w9 A1ncqaq0LGTV015XcN8fjwMtO0wHqrTGYvpVrKeOngOHb54GH3oBCM7qMcQWmj28rS3w yOHA+4rluCcO8mbbFF9HMtzOoCD5SlnFi5hBo7BjVRdVqHuQZ+uCAFAUcy9Yfg1zhoZj 2BUH6vkNp8WhC1fDKIpD9z6MqZEfB6yj5rJ0Z2sHMDv11D6EzlbirYSlgocRkrbbJqq4 XvHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YizWOmsb; 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 gt15-20020a1709072d8f00b0073d92f83e06si6674669ejc.887.2022.12.02.01.40.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 01:40:36 -0800 (PST) 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=YizWOmsb; 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 49CE43858C33 for ; Fri, 2 Dec 2022 09:40:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49CE43858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669974035; bh=pcWOCBe3al0OUM2q92EEB47M0tJtvzrVxDwdUh+Sv5M=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YizWOmsbPn/Nbzqf28p3BRNJZK6vmJu30kYQJX1J9X53kO/9iPx/7OctJKPUctQ+n QxroVu+FwJvcdTGOfMSZkQdSikvrs2x88WpBDe8cAPSV49FcSb2kSdcjQ0sLuI5XmU 9HQEg7QICuJFlZdpPMZ8dcLv2kkH7jY2jei+u8gI= 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 546713858C62 for ; Fri, 2 Dec 2022 09:39:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 546713858C62 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-315-2ySyWM4vPd-_aEnN2zrphg-1; Fri, 02 Dec 2022 04:39:46 -0500 X-MC-Unique: 2ySyWM4vPd-_aEnN2zrphg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B09D101A52A; Fri, 2 Dec 2022 09:39:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EC5140E80E3; Fri, 2 Dec 2022 09:39:45 +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 2B29ddvd1504546 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 2 Dec 2022 10:39:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B29dcVr1504545; Fri, 2 Dec 2022 10:39:38 +0100 Date: Fri, 2 Dec 2022 10:39:38 +0100 To: Uros Bizjak , Richard Biener , richard.sandiford@arm.com, Roger Sayle Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Save/restore recog_data in ix86_vector_duplicate_value [PR106577] Message-ID: References: <002201d8ae8b$d11fa9b0$735efd10$@nextmovesoftware.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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?1751094695026334543?= X-GMAIL-MSGID: =?utf-8?q?1751094695026334543?= Hi! On Tue, Aug 16, 2022 at 09:14:06AM +0100, Richard Sandiford via Gcc-patches wrote: > IMO the correct low-effort fix is to save and restore recog_data > in ix86_vector_duplicate_value. It's a relatively big copy, > but the current code is pretty wasteful anyway (allocating at > least a new SET and INSN for every query). Compared to the > overhead of doing that, a copy to and from the stack shouldn't > be too bad. The following patch does that. It isn't the first spot in the compiler that does that, not even the first spot in the i386 backend. In i386-expand.cc beyond these 2 recog_memoized calls there is one in expand_vselect, but I think it is unlikely we'd run into these issues trying to expand new permutations from splitters. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-02 Jakub Jelinek PR target/106577 * config/i386/i386-expand.cc (ix86_vector_duplicate_value): Save/restore recog_data around recog_memoized calls. * gcc.target/i386/pr106577.c: New test. Jakub --- gcc/config/i386/i386-expand.cc.jj 2022-12-01 09:29:15.233466321 +0100 +++ gcc/config/i386/i386-expand.cc 2022-12-01 14:05:55.901157211 +0100 @@ -15187,6 +15187,10 @@ ix86_vector_duplicate_value (machine_mod bool ok; rtx_insn *insn; rtx dup; + /* Save/restore recog_data in case this is called from splitters + or other routines where recog_data needs to stay valid across + force_reg. See PR106577. */ + recog_data_d recog_data_save = recog_data; /* First attempt to recognize VAL as-is. */ dup = gen_vec_duplicate (mode, val); @@ -15212,6 +15216,7 @@ ix86_vector_duplicate_value (machine_mod ok = recog_memoized (insn) >= 0; gcc_assert (ok); } + recog_data = recog_data_save; return true; } --- gcc/testsuite/gcc.target/i386/pr106577.c.jj 2022-12-01 14:13:03.973872383 +0100 +++ gcc/testsuite/gcc.target/i386/pr106577.c 2022-12-01 14:13:03.973872383 +0100 @@ -0,0 +1,10 @@ +/* PR target/106577 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2 -mavx" } */ + +int i; +void +foo (void) +{ + i ^= !(((unsigned __int128)0xf0f0f0f0f0f0f0f0 << 64 | 0xf0f0f0f0f0f0f0f0) & i); +}