From patchwork Mon Aug 28 21:34:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pat Haugen X-Patchwork-Id: 806775 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-461051-incoming=patchwork.ozlabs.org@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.b="hE2L06oq"; 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 3xh4my3f59z9t2M for ; Tue, 29 Aug 2017 07:35:12 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:date:mime-version:content-type:message-id; q=dns; s=default; b=Ow6EJW5+rIzeCEE4ZgPqi34bRrcmR4szoGgDBRo/X3EBdtBK4b SfuSjOjJ7CWH0MhsQY5pkzxNldk7OW7w59xTQXpleitocSUcTbPBZScaVEB8J4LM U5gGaU/SKk20ihJRSjP9rpZp/WmSwXD2mZZDBiqtB6MzfXtkRpCLlXR/Y= 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:from :subject:to:cc:date:mime-version:content-type:message-id; s= default; bh=ceABui6EqFo2l7TcGrQDxQzTgKo=; b=hE2L06oqVvpJ1/Oi70GV joqGgfU7pL1tSxSpgxfDy8VRVIEU5edVJVS8sql7jEdIFOYHVJG0dubAeVUCXl30 mui0lVEIXtnDqPOkF+UL6nDS0gC3wLIrGCJNjn69r7vzmdAJ9K1/d7puQDlKiBav +ef51NEHczJeu3Z4sK41d3U= Received: (qmail 80165 invoked by alias); 28 Aug 2017 21:34:36 -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 80141 invoked by uid 89); 28 Aug 2017 21:34:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=crs 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; Mon, 28 Aug 2017 21:34:24 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7SLXxbw049142 for ; Mon, 28 Aug 2017 17:34:21 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmnx0suj3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 28 Aug 2017 17:34:21 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Aug 2017 15:34:20 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 Aug 2017 15:34:17 -0600 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7SLYHfv64290978; Mon, 28 Aug 2017 14:34:17 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 65A2B6A03B; Mon, 28 Aug 2017 15:34:17 -0600 (MDT) Received: from oc1687012634.ibm.com (unknown [9.10.86.124]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 290056A041; Mon, 28 Aug 2017 15:34:17 -0600 (MDT) From: Pat Haugen Subject: [PATCH, rs6000] Stop non-volatile CR usage from killing shrink-wrap To: GCC Patches Cc: Segher Boessenkool , David Edelsohn Date: Mon, 28 Aug 2017 16:34:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17082821-0008-0000-0000-0000087D1B6E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007629; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000226; SDB=6.00908974; UDB=6.00455817; IPR=6.00689225; BA=6.00005557; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016907; XFM=3.00000015; UTC=2017-08-28 21:34:19 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082821-0009-0000-0000-000043BFEE47 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-28_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708280335 X-IsSubscribed: yes The following patch allows shrink-wrapping to succeed in the presence of non-volatile CR save/restore. The movesi_from_cr define_insn used to list all CRs as used, even though it's only the non-volatile values that we are interested in saving/restoring. This prevented the prolog from being moved past the early exit test because that compare was defining a register used in the prolog (a volatile CR). The patch removes the mentions of the volatile CRs and renames the functions involved so that it's hopefully clear they are for prolog generation only. Bootstrap/regtest on powerpc64le-linux with no new regressions. Ok for trunk? -Pat 2017-08-28 Pat Haugen * config/rs6000/rs6000.c (rs6000_emit_prolog_move_from_cr): Rename from rs6000_emit_move_from_cr and call renamed function. (rs6000_emit_prologue): Call renamed functions. * config/rs6000/rs6000.md (prolog_movesi_from_cr): Rename from prolog_movesi_from_cr, remove volatile CRs. testsuite/ChangeLog: 2017-08-28 Pat Haugen * gcc.target/powerpc/cr_shrink-wrap.c: New. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 251389) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -26083,10 +26083,14 @@ rs6000_emit_savres_rtx (rs6000_stack_t * return insn; } -/* Emit code to store CR fields that need to be saved into REG. */ +/* Emit prolog code to store CR fields that need to be saved into REG. This + function should only be called when moving the non-volatile CRs to REG, it + is not a general purpose routine to move the entire set of CRs to REG. + Specifically, gen_prolog_movesi_from_cr() does not contain uses of the + volatile CRs. */ static void -rs6000_emit_move_from_cr (rtx reg) +rs6000_emit_prolog_move_from_cr (rtx reg) { /* Only the ELFv2 ABI allows storing only selected fields. */ if (DEFAULT_ABI == ABI_ELFv2 && TARGET_MFCRF) @@ -26117,7 +26121,7 @@ rs6000_emit_move_from_cr (rtx reg) as well, using logical operations to combine the values. */ } - emit_insn (gen_movesi_from_cr (reg)); + emit_insn (gen_prolog_movesi_from_cr (reg)); } /* Return whether the split-stack arg pointer (r12) is used. */ @@ -26857,7 +26861,7 @@ rs6000_emit_prologue (void) { cr_save_rtx = gen_rtx_REG (SImode, cr_save_regno); START_USE (cr_save_regno); - rs6000_emit_move_from_cr (cr_save_rtx); + rs6000_emit_prolog_move_from_cr (cr_save_rtx); } /* Do any required saving of fpr's. If only one or two to save, do @@ -27095,7 +27099,7 @@ rs6000_emit_prologue (void) { START_USE (0); cr_save_rtx = gen_rtx_REG (SImode, 0); - rs6000_emit_move_from_cr (cr_save_rtx); + rs6000_emit_prolog_move_from_cr (cr_save_rtx); } /* Saving CR requires a two-instruction sequence: one instruction @@ -27182,7 +27186,7 @@ rs6000_emit_prologue (void) /* ??? We might get better performance by using multiple mfocrf instructions. */ crsave = gen_rtx_REG (SImode, 0); - emit_insn (gen_movesi_from_cr (crsave)); + emit_insn (gen_prolog_movesi_from_cr (crsave)); for (i = 0; i < 8; i++) if (!call_used_regs[CR0_REGNO + i]) Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 251389) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -13032,12 +13032,14 @@ (define_insn "*movesi_from_cr_one" }" [(set_attr "type" "mfcrf")]) -(define_insn "movesi_from_cr" +;; Don't include the volatile CRs since their values are not used wrt CR save +;; in the prolog and doing so prevents shrink-wrapping because we can't move the +;; prolog past an insn (early exit test) that defines a register used in the +;; prolog. +(define_insn "prolog_movesi_from_cr" [(set (match_operand:SI 0 "gpc_reg_operand" "=r") - (unspec:SI [(reg:CC CR0_REGNO) (reg:CC CR1_REGNO) - (reg:CC CR2_REGNO) (reg:CC CR3_REGNO) - (reg:CC CR4_REGNO) (reg:CC CR5_REGNO) - (reg:CC CR6_REGNO) (reg:CC CR7_REGNO)] + (unspec:SI [(reg:CC CR2_REGNO) (reg:CC CR3_REGNO) + (reg:CC CR4_REGNO)] UNSPEC_MOVESI_FROM_CR))] "" "mfcr %0" Index: gcc/testsuite/gcc.target/powerpc/cr_shrink-wrap.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/cr_shrink-wrap.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/cr_shrink-wrap.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-pro_and_epilogue" } */ + +void foo(int i) +{ + if (i > 0) + /* Non-volatile CR kill on true path should not prevent shrink-wrap. */ + asm ("" : : : "cr2", "cr3"); +} + +/* { dg-final { scan-rtl-dump-times "Performing shrink-wrapping" 1 "pro_and_epilogue" } } */