From patchwork Tue Nov 19 09:04:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1197312 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514000-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KRphqOrL"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="XSl/bED2"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HKf50g4Bz9sPn for ; Tue, 19 Nov 2019 20:05:00 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=cos RUsEn1gtEqcp3fcCUTgktxDo79cROaVXC/iTS1qKKEgafRNFgxwh+qAlVNqghoIu IPJ9Q+A08y/dI4HdL66B9HJ1E5gePoy85lsaLML4MTIQ43Zr/Y/uHHJhXaplu5FO 5fr16XhCAiDG6146dxfJZkDg8PEdstrdAh1KBKuI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=2+QLUDm32 zkCx17HilQK5yUNoUE=; b=KRphqOrLRSx4RHpSDUPDgt/WnbEpGN57RQaOGqeI7 xU0W/DVzmdHtKVXyLSy5vVs5CUmWpJmboFBKntQBogyff0mh2pE/IrH6Zq6GJUHy eVMI0/86+u9ZlDWu0xavA7HK1UIOEiCEsnsfuataDVGz9CHA72xDQTjXvWRs5ETF 2U= Received: (qmail 105784 invoked by alias); 19 Nov 2019 09:04:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 105775 invoked by uid 89); 19 Nov 2019 09:04:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=disaster X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Nov 2019 09:04:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574154281; 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: content-transfer-encoding:content-transfer-encoding; bh=42AZorkD02w/zksmnVN8hdLOClMd1fNHMAEgrLcTpTU=; b=XSl/bED2OBqBb35PgHkhCwBht+zHUf4V3fa9nu3qDWeD2IBvvnUSgzJA3XkLckxTl81h9q 8GOUyIpJ46eQIpfuaB3E3zgkelWKDsP4On2UNa3ZrHaKV8wDgEZzm6UIyZH4Gqb2sfQ0XZ I9FkG4DsAmIF61ECIJ+Xt2nPVXadrro= 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-382-6LFetOQlPBCjRo2qwOuUDg-1; Tue, 19 Nov 2019 04:04:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2A28102C84F; Tue, 19 Nov 2019 09:04:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B48D648AE; Tue, 19 Nov 2019 09:04:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xAJ94aCu019906; Tue, 19 Nov 2019 10:04:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAJ94ZoA019905; Tue, 19 Nov 2019 10:04:35 +0100 Date: Tue, 19 Nov 2019 10:04:35 +0100 From: Jakub Jelinek To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Use xchg for -Os (PR target/92549) Message-ID: <20191119090435.GE4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! xchg instruction is smaller, in some cases much smaller than 3 moves, (e.g. in the testcase 2 bytes vs. 8 bytes), and is not a performance disaster, but from Agner Fog tables and https://stackoverflow.com/questions/45766444/why-is-xchg-reg-reg-a-3-micro-op-instruction-on-modern-intel-architectures it doesn't seem to be something we'd want to use when optimizing for speed, at least not on Intel. While we have *swap patterns, those are very unlikely to be triggered during combine, usually we have different pseudos in there and the actual need for swapping is only materialized during RA. The following patch does it when optimizing the insn for size only. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-11-19 Jakub Jelinek PR target/92549 * config/i386/i386.md (peephole2 for *swap): New peephole2. * gcc.target/i386/pr92549.c: New test. Jakub --- gcc/config/i386/i386.md.jj 2019-10-28 22:16:14.583008121 +0100 +++ gcc/config/i386/i386.md 2019-11-18 17:06:36.050742545 +0100 @@ -2787,6 +2787,17 @@ (set_attr "amdfam10_decode" "double") (set_attr "bdver1_decode" "double")]) +(define_peephole2 + [(set (match_operand:SWI 0 "register_operand") + (match_operand:SWI 1 "register_operand")) + (set (match_dup 1) + (match_operand:SWI 2 "register_operand")) + (set (match_dup 2) (match_dup 0))] + "peep2_reg_dead_p (3, operands[0]) + && optimize_insn_for_size_p ()" + [(parallel [(set (match_dup 1) (match_dup 2)) + (set (match_dup 2) (match_dup 1))])]) + (define_expand "movstrict" [(set (strict_low_part (match_operand:SWI12 0 "register_operand")) (match_operand:SWI12 1 "general_operand"))] --- gcc/testsuite/gcc.target/i386/pr92549.c.jj 2019-11-18 17:48:35.533177377 +0100 +++ gcc/testsuite/gcc.target/i386/pr92549.c 2019-11-18 17:49:31.888336444 +0100 @@ -0,0 +1,28 @@ +/* PR target/92549 */ +/* { dg-do compile } */ +/* { dg-options "-Os -masm=att" } */ +/* { dg-final { scan-assembler "xchgl" } } */ + +#ifdef __i386__ +#define R , regparm (2) +#else +#define R +#endif + +__attribute__((noipa R)) int +bar (int a, int b) +{ + return b - a + 5; +} + +__attribute__((noipa R)) int +foo (int a, int b) +{ + return 1 + bar (b, a); +} + +int +main () +{ + return foo (39, 3); +}