From patchwork Sat Feb 13 08:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1440150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vC7Dh2l0; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dd3sf4kHmz9sS8 for ; Sat, 13 Feb 2021 19:47:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74EFF387086F; Sat, 13 Feb 2021 08:47:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74EFF387086F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1613206062; bh=EFf5Eyt6O+x9WyOhqwLjb1ATwqBFJk/704oADsBMzLE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vC7Dh2l0Cl4jTuOcv5oCXXt24KOjhnrdsijPP6d6IwKDo58aJWbRMZUrqygzZeUEB dpNyTiayekRUi9uOmPW1PtexkRbUY2t88goIYRTKLR3p5GpkuEyYJLeacMt+gSVgSZ tKDNmmtAXnSv09etUCed341FMzUSm1g87BPZ+YHU= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 4BA1C386103E for ; Sat, 13 Feb 2021 08:47:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4BA1C386103E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-0KFbejEzOOW0CUf9PtduEQ-1; Sat, 13 Feb 2021 03:47:34 -0500 X-MC-Unique: 0KFbejEzOOW0CUf9PtduEQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36D438018AD; Sat, 13 Feb 2021 08:47:33 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-197.ams2.redhat.com [10.36.112.197]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C04BF1002393; Sat, 13 Feb 2021 08:47:32 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 11D8lOio1630924 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 13 Feb 2021 09:47:30 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 11D8lNU41630923; Sat, 13 Feb 2021 09:47:23 +0100 Date: Sat, 13 Feb 2021 09:47:23 +0100 To: Uros Bizjak Subject: [PATCH] i386: Add combiner splitter to optimize V2SImode memory rotation [PR96166] Message-ID: <20210213084723.GI4020736@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! Since the x86 backend enabled V2SImode vectorization (with TARGET_MMX_WITH_SSE), slp vectorization can kick in and emit movq (%rdi), %xmm1 pshufd $225, %xmm1, %xmm0 movq %xmm0, (%rdi) instead of rolq $32, (%rdi) we used to emit (or emit when slp vectorization is disabled). I think the rotate is both smaller and faster, so this patch adds a combiner splitter to optimize that back. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-02-13 Jakub Jelinek PR target/96166 * config/i386/mmx.md (*mmx_pshufd_1): Add a combine splitter for swap of V2SImode elements in memory into DImode memory rotate by 32. * gcc.target/i386/pr96166.c: New test. Jakub --- gcc/config/i386/mmx.md.jj 2021-02-03 09:10:28.741347389 +0100 +++ gcc/config/i386/mmx.md 2021-02-12 15:27:38.159393941 +0100 @@ -2076,6 +2076,17 @@ (define_insn "*mmx_pshufd_1" (set_attr "length_immediate" "1") (set_attr "mode" "TI")]) +;; Optimize V2SImode load from memory, swapping the elements and +;; storing back into the memory into DImode rotate of the memory by 32. +(define_split + [(set (match_operand:V2SI 0 "memory_operand") + (vec_select:V2SI (match_dup 0) + (parallel [(const_int 1) (const_int 0)])))] + "TARGET_64BIT && (TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())" + [(set (match_dup 0) + (rotate:DI (match_dup 0) (const_int 32)))] + "operands[0] = adjust_address (operands[0], DImode, 0);") + (define_insn "mmx_pswapdv2si2" [(set (match_operand:V2SI 0 "register_operand" "=y,Yv") (vec_select:V2SI --- gcc/testsuite/gcc.target/i386/pr96166.c.jj 2021-02-12 15:36:31.251410875 +0100 +++ gcc/testsuite/gcc.target/i386/pr96166.c 2021-02-12 15:37:26.467792818 +0100 @@ -0,0 +1,21 @@ +/* PR target/96166 */ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O3 -mtune=generic -masm=att" } */ +/* { dg-final { scan-assembler "rolq\\s\\\$32, \\\(%\[re]di\\\)" } } */ + +static inline void +swap (int *x, int *y) +{ + int tmp = *x; + *x = *y; + *y = tmp; +} + +void +bar (int (*x)[2]) +{ + int y[2]; + __builtin_memcpy (&y, x, sizeof *x); + swap (&y[0], &y[1]); + __builtin_memcpy (x, &y, sizeof *x); +}