From patchwork Mon Oct 26 11:52:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 535882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 950D3141310 for ; Mon, 26 Oct 2015 22:52:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Iehgaicx; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=oUdoLuod3DttQbeg2 yO1s30MmGKFNhWgDiffHOX6BsYuRV3doIth3VVLmaNFokQMhE3qMZ5ls4B3Fk2Y3 TyGnq9OWs6WEbVFJXYY2wkWlS7mF64EiKuvV5YCkQ8pZrPJqjEP4tfJV7XhtFNMb CjRC0QSlhEWsYCGnprjE6hOeSM= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=KtSE9L1A15gBwpSZfMpwrUl sH3o=; b=IehgaicxDMUiw9vSvZVSY33m9bHJBR3cFZ2O+G3vhO+YGX7BlfwrmBP jybX5qSr/jPMYw02hClrMxUqqikhANYZOSxw+vFL0EJxpoltaqtIsRRW/2jtoofY +1/PbDVE2x0hEQxzFZnsY6++xQRiLjyCpZg0Pw1mmSm7L40tZGjA= Received: (qmail 1476 invoked by alias); 26 Oct 2015 11:52:20 -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 1466 invoked by uid 89); 26 Oct 2015 11:52:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Oct 2015 11:52:18 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-15-zXoBCzS1RAihDa2VLE6Gvw-1; Mon, 26 Oct 2015 11:52:12 +0000 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 26 Oct 2015 11:52:12 +0000 Message-ID: <562E13EC.3010305@arm.com> Date: Mon, 26 Oct 2015 11:52:12 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Bernd Schmidt , GCC Patches , richard.sandiford@arm.com Subject: Re: [PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases References: <562E030B.7090908@arm.com> <562E0AB4.7050809@redhat.com> <562E0E48.1020603@redhat.com> In-Reply-To: <562E0E48.1020603@redhat.com> X-MC-Unique: zXoBCzS1RAihDa2VLE6Gvw-1 X-IsSubscribed: yes On 26/10/15 11:28, Bernd Schmidt wrote: > On 10/26/2015 12:12 PM, Bernd Schmidt wrote: >> >> But isn't that balanced by the fact that it doesn't seem to take into >> account the gain of removing the inc_insn either? So I think this can't >> be right. > > Argh, misread the code. The patch is OK with the change I suggested. > Thanks! Here's what I committed with r229344. Kyrill 2015-10-26 Kyrylo Tkachov * auto-inc-dec.c (insert_move_insn_before): Delete. (attempt_change): Remember to cost the simple move in the FORM_PRE_ADD and FORM_POST_ADD cases. > > Bernd > commit cc7c4748eac1f9d59ceb5393132c098aba99765d Author: Kyrylo Tkachov Date: Fri Oct 16 13:46:51 2015 +0100 [auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c index e003b13..9f7c8e0 100644 --- a/gcc/auto-inc-dec.c +++ b/gcc/auto-inc-dec.c @@ -439,24 +439,6 @@ move_dead_notes (rtx_insn *to_insn, rtx_insn *from_insn, rtx pattern) } } - -/* Create a mov insn DEST_REG <- SRC_REG and insert it before - NEXT_INSN. */ - -static rtx_insn * -insert_move_insn_before (rtx_insn *next_insn, rtx dest_reg, rtx src_reg) -{ - rtx_insn *insns; - - start_sequence (); - emit_move_insn (dest_reg, src_reg); - insns = get_insns (); - end_sequence (); - emit_insn_before (insns, next_insn); - return insns; -} - - /* Change mem_insn.mem_loc so that uses NEW_ADDR which has an increment of INC_REG. To have reached this point, the change is a legitimate one from a dataflow point of view. The only questions @@ -490,8 +472,21 @@ attempt_change (rtx new_addr, rtx inc_reg) old_cost = (set_src_cost (mem, mode, speed) + set_rtx_cost (PATTERN (inc_insn.insn), speed)); + new_cost = set_src_cost (mem_tmp, mode, speed); + /* In the FORM_PRE_ADD and FORM_POST_ADD cases we emit an extra move + whose cost we should account for. */ + if (inc_insn.form == FORM_PRE_ADD + || inc_insn.form == FORM_POST_ADD) + { + start_sequence (); + emit_move_insn (inc_insn.reg_res, inc_insn.reg0); + mov_insn = get_insns (); + end_sequence (); + new_cost += seq_cost (mov_insn, speed); + } + /* The first item of business is to see if this is profitable. */ if (old_cost < new_cost) { @@ -522,8 +517,8 @@ attempt_change (rtx new_addr, rtx inc_reg) /* Replace the addition with a move. Do it at the location of the addition since the operand of the addition may change before the memory reference. */ - mov_insn = insert_move_insn_before (inc_insn.insn, - inc_insn.reg_res, inc_insn.reg0); + gcc_assert (mov_insn); + emit_insn_before (mov_insn, inc_insn.insn); move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0); regno = REGNO (inc_insn.reg_res); @@ -548,8 +543,8 @@ attempt_change (rtx new_addr, rtx inc_reg) break; case FORM_POST_ADD: - mov_insn = insert_move_insn_before (mem_insn.insn, - inc_insn.reg_res, inc_insn.reg0); + gcc_assert (mov_insn); + emit_insn_before (mov_insn, mem_insn.insn); move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0); /* Do not move anything to the mov insn because the instruction