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: 61353 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 A1B723858C39 for ; Fri, 2 Dec 2022 09:40:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1B723858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669974020; 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=bOw3BTwrfsd8bN2EpEZ0aMKAtLssVZwhWIoDqfHKqJGuVXrmhDN5E2PLKx7TBrY8N u8xd+ANsJeAdNOMHQRC6fhpSZXWWoWrv9wxQLP+l2wzvVTNYNz+xy6S9P3Gj6exSMf XWOHI6xwfRm8jNuhsU+zM09aGKe/Pz79r8yQIv6Y= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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); +}