From patchwork Sat Oct 27 16:20:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Sawdey X-Patchwork-Id: 989922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-488457-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kqbVKIqC"; 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 42j5gP0p3Nz9sCc for ; Sun, 28 Oct 2018 03:20:16 +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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=EGe7o P4vap7a3O3q6peL7yLu5xyP++HxEUu/Y75ae2CIi+0o8wqJpzzG47gsJWVJjRKBb 9/pMbDMa+jzmnZIz83aFvhDkbIFKc1Pw3qIyQ0PIJ5BqXCRFjXPdhShjQAbshnaq 8CDIa5M9q0K2CwfeeNPmg4A5WiDEyoS3QNLVhM= 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:to:cc :from:subject:date:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=J9C/T6uy+5t QcfSrGdKOlRLmiJs=; b=kqbVKIqCkuRk3PQTFJaneti6EhAM/Qy/mb/nlvrwCDP 4htuo/nk+//OWrM8S5JCKPZNvLRRhOvdqujURAJXGpdRwfRC+4jy395UYjhbryP6 4EpVOrkU0SozbtTVAPRRwnWbPikNy2c2YWNsvWBIlyVxOgPALx5SyB9O8UVqFY0Q = Received: (qmail 90044 invoked by alias); 27 Oct 2018 16:20:10 -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 90028 invoked by uid 89); 27 Oct 2018 16:20:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=phd, compact X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Oct 2018 16:20:08 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9RGJNsZ047932 for ; Sat, 27 Oct 2018 12:20:06 -0400 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ncjbp6sv3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 27 Oct 2018 12:20:06 -0400 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 27 Oct 2018 12:20:04 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sat, 27 Oct 2018 12:20:03 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9RGK2XX32571610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Oct 2018 16:20:02 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87B4EAE060; Sat, 27 Oct 2018 16:20:02 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 29D2CAE05C; Sat, 27 Oct 2018 16:20:02 +0000 (GMT) Received: from [9.85.179.14] (unknown [9.85.179.14]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Sat, 27 Oct 2018 16:20:02 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool , Bill Schmidt , David Edelsohn From: Aaron Sawdey Subject: [PATCH][rs6000] use index form addresses more often for ldbrx/stdbrx Date: Sat, 27 Oct 2018 11:20:01 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 x-cbid: 18102716-2213-0000-0000-0000030B742E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009944; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000268; SDB=6.01108791; UDB=6.00574387; IPR=6.00888878; MB=3.00023931; MTD=3.00000008; XFM=3.00000015; UTC=2018-10-27 16:20:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18102716-2214-0000-0000-00005C0AB386 Message-Id: X-IsSubscribed: yes At Segher's suggestion, I looked into changing the predicates on bswapdi2_{load,store} from memory_operand to indexed_or_indirect_operand and putting some code into bswapdi2 to make the address indirect if it wasn't already. The motivating case for this was the code I was seeing for the gpr expansion of strncmp. Before I would typically see something like this: addi 9,3,8 ldbrx 10,0,9 addi 9,4,8 ldbrx 8,0,9 subf. 9,8,10 bne 0,.L13 cmpb 10,10,9 cmpdi 0,10,0 bne 0,.L9 addi 9,3,16 ldbrx 10,0,9 addi 9,4,16 ldbrx 8,0,9 subf. 9,8,10 bne 0,.L13 cmpb 10,10,9 cmpdi 0,10,0 bne 0,.L9 For each comparison block it is doing the add separately and using 0 for one input of the ldbrx. After this change, it is more like this: ldbrx 8,3,27 ldbrx 7,4,27 cmpb 9,8,9 cmpb 10,8,7 orc. 9,9,10 bne 0,.L13 ldbrx 8,3,24 ldbrx 7,4,24 cmpb 10,8,9 cmpb 9,8,7 orc. 9,10,9 bne 0,.L13 Here it has created temps with constants and hoisted them out of a loop, but I have other cases where it will update them if there is more register pressure. in either case the code is more compact and makes full use of the indexed addressing of ldbrx. Bootstrap/regtest passed on ppc64le targeting power7/power8/power9, ok for trunk? Thanks! Aaron 2018-10-27 Aaron Sawdey * config/rs6000/rs6000.md (bswapdi2): Force address into register if not in one already. (bswapdi2_load): Change predicate to indexed_or_indirect_operand. (bswapdi2_store): Ditto. Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 265393) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -2512,9 +2512,27 @@ if (TARGET_POWERPC64 && TARGET_LDBRX) { if (MEM_P (src)) - emit_insn (gen_bswapdi2_load (dest, src)); + { + rtx addr = XEXP (src, 0); + if (!legitimate_indirect_address_p (addr, reload_completed) + && !legitimate_indexed_address_p (addr, reload_completed)) + { + addr = force_reg (Pmode, addr); + src = replace_equiv_address_nv (src, addr); + } + emit_insn (gen_bswapdi2_load (dest, src)); + } else if (MEM_P (dest)) - emit_insn (gen_bswapdi2_store (dest, src)); + { + rtx addr = XEXP (dest, 0); + if (!legitimate_indirect_address_p (addr, reload_completed) + && !legitimate_indexed_address_p (addr, reload_completed)) + { + addr = force_reg (Pmode, addr); + dest = replace_equiv_address_nv (dest, addr); + } + emit_insn (gen_bswapdi2_store (dest, src)); + } else if (TARGET_P9_VECTOR) emit_insn (gen_bswapdi2_xxbrd (dest, src)); else @@ -2535,13 +2553,13 @@ ;; Power7/cell has ldbrx/stdbrx, so use it directly (define_insn "bswapdi2_load" [(set (match_operand:DI 0 "gpc_reg_operand" "=r") - (bswap:DI (match_operand:DI 1 "memory_operand" "Z")))] + (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand" "Z")))] "TARGET_POWERPC64 && TARGET_LDBRX" "ldbrx %0,%y1" [(set_attr "type" "load")]) (define_insn "bswapdi2_store" - [(set (match_operand:DI 0 "memory_operand" "=Z") + [(set (match_operand:DI 0 "indexed_or_indirect_operand" "=Z") (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "r")))] "TARGET_POWERPC64 && TARGET_LDBRX" "stdbrx %1,%y0"