From patchwork Wed Jun 7 10:04:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 772338 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 3wjPKW3NChz9sDC for ; Wed, 7 Jun 2017 20:04:15 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uTur1BSJ"; 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:cc:subject:references :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=PwCRCBeoCsCq5WN0URrcGy0tO5av0CfGys9NL+oqPkZtqpTfyumwy mAM7BoOC1lRd+HPKDaxzjnHtSInLcVBnFzg9Wf8nWKOMVm8cLjBqCwZZZ0bBwzpO z0TnrWFgRjfNF31TkyonkfUY/kirNRVBqgRfJlbjoOC8loM3/OOAA0= 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:cc:subject:references :in-reply-to:content-type:content-transfer-encoding; s=default; bh=p08IRv46qSD9zykBj03/Xsd6ToA=; b=uTur1BSJD1drVVOouEFY72f2kygI +OFyTbHLGyvwReZcENYss/zjvuxNa7CxHllBM0TwU5BEV1RHft7VPjnsewyY1IlF Qd4iv2hpLIi2jPszDwg0MNinD5mLwL0Y6cIeiKMQT+tnF4uWOQ3f87gwk2EvcRDd vE78KixS6uZtdKg= Received: (qmail 14992 invoked by alias); 7 Jun 2017 10:04:01 -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 14979 invoked by uid 89); 7 Jun 2017 10:04:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Jun 2017 10:04:00 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A724380D; Wed, 7 Jun 2017 03:04:02 -0700 (PDT) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8F2713F587; Wed, 7 Jun 2017 03:04:01 -0700 (PDT) Message-ID: <5937CF90.9040506@foss.arm.com> Date: Wed, 07 Jun 2017 11:04:00 +0100 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: Tamar Christina , GCC Patches CC: nd , Ramana Radhakrishnan , Richard Earnshaw , "nickc@redhat.com" Subject: Re: [PATCH][GCC][ARM] Adjust costs so udiv is preferred over sdiv when both are valid. [Patch (2/2)] References: In-Reply-To: On 02/05/17 16:37, Tamar Christina wrote: > Hi All, > > This patch adjusts the cost model so that when both sdiv and udiv are possible > it prefers udiv over sdiv. This was done by making sdiv slightly more expensive > instead of making udiv cheaper to keep the baseline costs of a division the same > as before. > > Similar to aarch64 this patch along with my other two related mid-end changes > makes a big difference in division by constants. > > Given: > > int f2(int x) > { > return ((x * x) % 300) + ((x * x) / 300); > } > > we now generate > > f2: > mul r3, r0, r0 > mov r0, r3 > ldr r1, .L3 > umull r2, r3, r0, r1 > lsr r2, r3, #5 > add r3, r2, r2, lsl #2 > rsb r3, r3, r3, lsl #4 > sub r0, r0, r3, lsl #2 > add r0, r0, r2 > bx lr > > as opposed to > > f2: > mul r3, r0, r0 > mov r0, r3 > ldr r3, .L4 > push {r4, r5} > smull r4, r5, r0, r3 > asr r3, r0, #31 > rsb r3, r3, r5, asr #5 > add r2, r3, r3, lsl #2 > rsb r2, r2, r2, lsl #4 > sub r0, r0, r2, lsl #2 > add r0, r0, r3 > pop {r4, r5} > bx lr > > Bootstrapped and reg tested on arm-none-eabi > with no regressions. > > OK for trunk? > > Thanks, > Tamar > > > gcc/ > 2017-05-02 Tamar Christina > > * config/arm/arm.c (arm_rtx_costs_internal): Make sdiv more expensive than udiv. > > > gcc/testsuite/ > 2017-05-02 Tamar Christina > > * gcc.target/arm/sdiv_costs_1.c: New. We usually try to avoid adjusting the costs in units other than COSTS_N_INSNS. Would adding COSTS_N_INSNS (1) here work? If so, could you also add a comment here to describe why we're adjusting the cost. case MOD: @@ -9280,7 +9282,7 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, /* Fall-through. */ case UMOD: - *cost = LIBCALL_COST (2); + *cost = LIBCALL_COST (2) + (code == MOD ? 1 : 0); Same here. Thanks, Kyrill diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index b24143e32e2f100000f3b150f7ed0df4fabb3cc8..ecc7688b1db6309a4dd694a8e254e64abe14d7e3 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -9258,6 +9258,8 @@ arm_rtx_costs_internal (rtx x, enum rtx_code code, enum rtx_code outer_code, *cost += COSTS_N_INSNS (speed_p ? extra_cost->mult[0].idiv : 0); else *cost = LIBCALL_COST (2); + + *cost += (code == DIV ? 1 : 0); return false; /* All arguments must be in registers. */