From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669973990; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=pcWOCBe3al0OUM2q92EEB47M0tJtvzrVxDwdUh+Sv5M=; b=iQRPglG6HRlpwHHpVur9hBBuAm6SG7WGm00zdsRSGODcBov/UildNBBXYAz5E/6KC6m4Lf /67c8nSg3CqYcJuC7yd17ZJfxIx7g1kOZ2uVtGYqqU22MwqKgIRBBb4aza33w8lssaRtGr c66ta+FEsa9gHTaam2Rngln+oxGfAlY= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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); +} Jakub