From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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 10:04:00 -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: 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: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2017-06/txt/msg00413.txt.bz2 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. 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. */ 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