From patchwork Mon Oct 26 10:40:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 55526 Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1122008lbq; Mon, 26 Oct 2015 03:40:39 -0700 (PDT) X-Received: by 10.50.50.105 with SMTP id b9mr16703404igo.27.1445856039243; Mon, 26 Oct 2015 03:40:39 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id i9si11755963igm.96.2015.10.26.03.40.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2015 03:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-411462-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-411462-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-411462-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org 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:content-type; q= dns; s=default; b=N6NE5aHZXbzDQcMqsIoLvAkieXBP1637VYCGgSK12rQ2h9 Z5hQ7Ikw5VSTcmZJptYot5+2WSLD/XlTKarxCZomuKKVJTeLtJio+OmEgZqjf92N ed6QKF6nAOsIj/FX8ZR26+/qKHzvEIw6tJERWV28lFOidkxqeTIy2QCZwPTNU= 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:content-type; s= default; bh=AbcaY2xiZja9byG0AP8jbP3Fbzs=; b=QRxFM3gJDwJqEvhH+BoH og/bt7XQqPr2u2Duv+qPpfPYnkiyuyqpKnHDUx02OX6KrqAL6GuiLPVBI4PBbLBy jKjUUpoaR0tS1Iy1qr+WrO601Xv69iS89vuPGw6VU702kGXYjGU+jTuldwqPpPA0 BfOgDr9yNfidJNvXOv90QrA= Received: (qmail 61254 invoked by alias); 26 Oct 2015 10:40:23 -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 61221 invoked by uid 89); 26 Oct 2015 10:40:20 -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) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Oct 2015 10:40:19 +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-34-nJnsX3PUR_-AXFY68HVNgQ-1; Mon, 26 Oct 2015 10:40:15 +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 10:40:12 +0000 Message-ID: <562E030B.7090908@arm.com> Date: Mon, 26 Oct 2015 10:40:11 +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: GCC Patches Subject: [PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases X-MC-Unique: nJnsX3PUR_-AXFY68HVNgQ-1 X-IsSubscribed: yes Hi all, The auto_inc_dec pass can handle 4 types of sequences, described in the comment at the start of auto-inc-dec.c. In two of those: FORM_PRE_ADD and FORM_POST_ADD the resulting sequence is a move followed by a POST_INC or PRE_INC memory operation. In the FORM_POST_ADD case the pass transforms: *a ... b <- a + c into b <- a ... *(b += c) post However, the code in attempt_change that compares the costs of the before and after sequences has an oversight. When calculating the cost of the new sequence it doesn't take into account the cost of the b <- a move. This patch fixes the calculation by calling seq_cost on the result of the emit_move_insn call we do to emit that move. With this patch I've seen less aggressive generation of POST_INC memory instructions on arm, but the post_inc tests we have in the arm testsuite still pass, so I don't think this kills the usage of those instructions on arm, just tames them somewhat. No regressions on SPEC2000 on Cortex-A15. SPECINT 2006 improves by a bit. Bootstrapped and tested on arm, aarch64. Ok for trunk? Thanks, 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. commit 569d1d9b789a38bf4305991d96cbb03d1665e311 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 3b9a1f3..af3f8b3 100644 --- a/gcc/auto-inc-dec.c +++ b/gcc/auto-inc-dec.c @@ -438,24 +438,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 @@ -489,7 +471,23 @@ 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); + + int new_mem_cost = set_src_cost (mem_tmp, mode, speed); + int new_mov_cost = 0; + + /* 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_mov_cost = seq_cost (mov_insn, speed); + } + + new_cost = new_mem_cost + new_mov_cost; /* The first item of business is to see if this is profitable. */ if (old_cost < new_cost) @@ -521,8 +519,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); @@ -547,8 +545,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