From patchwork Wed Aug 13 15:29:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 379673 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 D09C114008F for ; Thu, 14 Aug 2014 01:30:26 +1000 (EST) 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; q=dns; s=default; b=CpRSehkGsi5XPKL5W IEiU1z5yIXwRexWr7D85JBg47v/zccE20eGr9iPCr/cnFfKrpWUNCk1O90Euwm8B Mq9lS5b89GjglSd4GGKDXruDbceNuZTT1yKPlxGHHvG8W42/3CFSsjoahyHHh4Kh MlNW5xI1gGvbzXVAYs8MHQs+Do= 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; s=default; bh=70Fdqr3goh54el5N70TT/nz g9Es=; b=k43w4vTb8QxH8CtaNqh+PeJvF2UYp8P/wIXOEvaIJlwtUhL7760gm68 GSNDQBuL+n7Fx1atd9F0NcrPmovWKPv0dvhOApJ+D+3uOY9YasD/3SL1V3tYJ49c kDvyfbhlrS1XjLB/r5qJ/45MaNwpxDfPpi2TqXi2OYn67rmhjAIw= Received: (qmail 18283 invoked by alias); 13 Aug 2014 15:30:18 -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 18175 invoked by uid 89); 13 Aug 2014 15:30:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Aug 2014 15:30:04 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Wed, 13 Aug 2014 16:30:02 +0100 Received: from [10.1.208.24] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 13 Aug 2014 16:30:00 +0100 Message-ID: <53EB8477.80208@arm.com> Date: Wed, 13 Aug 2014 16:29:59 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Richard Henderson , Richard Earnshaw CC: gcc-patches Subject: Re: [PATCH, AArch64] Use MOVN to generate 64-bit negative immediates where sensible References: <000001cf6ae4$059c2280$10d46780$@bolton@arm.com> <537605FF.8070700@arm.com> <53E363C2.4000405@arm.com> <53E37532.60101@arm.com> <53E3779C.1020709@arm.com> <53E3D467.2020509@redhat.com> In-Reply-To: <53E3D467.2020509@redhat.com> X-MC-Unique: 114081316300202701 X-IsSubscribed: yes On 07/08/14 20:32, Richard Henderson wrote: > On 08/07/2014 02:57 AM, Kyrill Tkachov wrote: >> + if (one_match > zero_match) >> + { >> + /* Set either first three quarters or all but the third. */ >> + mask = 0xffffll << (16 - first_not_ffff_match); >> + emit_insn (gen_rtx_SET (VOIDmode, dest, >> + GEN_INT (val | mask | 0xffffffff00000000ull))); >> + >> + /* Now insert other two quarters. */ >> + for (i = first_not_ffff_match + 16, mask <<= (first_not_ffff_match << 1); >> + i < 64; i += 16, mask <<= 16) >> { >> if ((val & mask) != mask) >> + emit_insn (gen_insv_immdi (dest, GEN_INT (i), >> + GEN_INT ((val >> i) & 0xffff))); >> } >> + return; >> } >> >> if (zero_match == 2) > You should not place this three instruction sequence before the two instruction > sequences that follow. I.e. place this just before simple_sequence. Hi Richard, Is the attached patch ok? It just moves the section as you suggested. I did a build of the Linux kernel with and without this patch to make sure no code-gen was accidentally affected. > > I do wonder if we should be memo-izing these computations so that we only have > to do the complex search for a sequence only once for each constant... We'd need to store a mapping from constant to RTXes and everytime we have a "cache hit" we'd have to tweak them to make sure the registers involved are correct. I had a quick play with this but ended up with LRA ICEs :( Might look at it later on, but it's not high on my priorities right now. Thanks, Kyrill 2014-08-13 Kyrylo Tkachov * config/aarch64/aarch64.c (aarch64_expand_mov_immediate): Move one_match > zero_match case to just before simple_sequence. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 20debb9..a4e7158 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -1136,24 +1136,6 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) return; } - if (one_match > zero_match) - { - /* Set either first three quarters or all but the third. */ - mask = 0xffffll << (16 - first_not_ffff_match); - emit_insn (gen_rtx_SET (VOIDmode, dest, - GEN_INT (val | mask | 0xffffffff00000000ull))); - - /* Now insert other two quarters. */ - for (i = first_not_ffff_match + 16, mask <<= (first_not_ffff_match << 1); - i < 64; i += 16, mask <<= 16) - { - if ((val & mask) != mask) - emit_insn (gen_insv_immdi (dest, GEN_INT (i), - GEN_INT ((val >> i) & 0xffff))); - } - return; - } - if (zero_match == 2) goto simple_sequence; @@ -1270,6 +1252,24 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) } } + if (one_match > zero_match) + { + /* Set either first three quarters or all but the third. */ + mask = 0xffffll << (16 - first_not_ffff_match); + emit_insn (gen_rtx_SET (VOIDmode, dest, + GEN_INT (val | mask | 0xffffffff00000000ull))); + + /* Now insert other two quarters. */ + for (i = first_not_ffff_match + 16, mask <<= (first_not_ffff_match << 1); + i < 64; i += 16, mask <<= 16) + { + if ((val & mask) != mask) + emit_insn (gen_insv_immdi (dest, GEN_INT (i), + GEN_INT ((val >> i) & 0xffff))); + } + return; + } + simple_sequence: first = true; mask = 0xffff;