From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23010 invoked by alias); 12 Aug 2014 09:24:57 -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 22970 invoked by uid 89); 12 Aug 2014 09:24:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 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; Tue, 12 Aug 2014 09:24:53 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Tue, 12 Aug 2014 10:24:50 +0100 Received: from [10.1.208.33] ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 12 Aug 2014 10:24:50 +0100 Message-ID: <53E9DD61.2050208@arm.com> Date: Tue, 12 Aug 2014 09:24:00 -0000 From: Richard Earnshaw User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: Zhenqiang Chen CC: "gcc-patches@gcc.gnu.org" , Ramana radhakrishnan Subject: Re: [PATCH, ARM] Keep constants in register when expanding References: In-Reply-To: X-MC-Unique: 114081210245018101 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2014-08/txt/msg01098.txt.bz2 On 05/08/14 10:31, Zhenqiang Chen wrote: > Hi, >=20 > For some large constants, ARM will split them during expanding, which > makes impossible to hoist them out the loop or shared by different > references (refer the test case in the patch). >=20 > The patch keeps some constants in registers. If the constant can not > be optimized, the cprop and combine passes can optimize them as what > we do in current expand pass with >=20 > define_insn_and_split "*arm_subsi3_insn" > define_insn_and_split "*arm_andsi3_insn" > define_insn_and_split "*iorsi3_insn" > define_insn_and_split "*arm_xorsi3" >=20 > The patch does not modify addsi3 since the define_insn_and_split > "*arm_addsi3" is only valid when (reload_completed || > !arm_eliminable_register (operands[1])). The cprop and combine passes > can not optimize the large constant if we put it in register, which > will lead to regression. >=20 > For logic operators, the patch skips changes for constants: >=20 > INTVAL (operands[2]) < 0 && const_ok_for_arm (-INTVAL (operands[2]) >=20 > since expand pass always uses "sign-extend" to get the value > (trunc_int_for_mode called from immed_wide_int_const) for rtl, and > logs show most negative values are UNSIGNED when they are TREE node. > And combine pass is smart enough to recover the negative value to > positive value. >=20 > Bootstrap and no make check regression on Chrome book. > For coremark, dhrystone and eembcv1, no any code size and performance > change on Cortex-M4. > No any file in CSiBE has code size change for Cortex-A15 and Cortex-M4. > No Spec2000 performance regression on Chrome book and dumped assemble > codes only show very few difference. >=20 > OK for trunk? >=20 Not yet. I think the principle is sound, but there are some issues that need sorting out. 1) We shouldn't do this when not optimizing; there's no advantage to hoisting out the constants in that case. Indeed, it may not be worth-while at -O1 either. 2) I think you should be using const_ok_for_op rather than working through all the permitted values. If that function isn't doing the right thing, then it probably needs extending to handle those cases as well. 3) Why haven't you handled addsi3? See below for some specific comments. > Thanks! > -Zhenqiang >=20 > ChangeLog: > 2014-08-05 Zhenqiang Chen >=20 > * config/arm/arm.md (subsi3, andsi3, iorsi3, xorsi3): Keep some > large constants in register other than split them. >=20 > testsuite/ChangeLog: > 2014-08-05 Zhenqiang Chen >=20 > * gcc.target/arm/maskdata.c: New test. >=20 >=20 > skip-split.patch >=20 >=20 > diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md > index bd8ea8f..c8b3001 100644 > --- a/gcc/config/arm/arm.md > +++ b/gcc/config/arm/arm.md > @@ -1162,9 +1162,16 @@ > { > if (TARGET_32BIT) > { > - arm_split_constant (MINUS, SImode, NULL_RTX, > - INTVAL (operands[1]), operands[0], > - operands[2], optimize && can_create_pseudo_p ()); > + if (!const_ok_for_arm (INTVAL (operands[1])) > + && can_create_pseudo_p ()) > + { > + operands[1] =3D force_reg (SImode, operands[1]); > + emit_insn (gen_subsi3 (operands[0], operands[1], operands[2])); The final emit_insn shouldn't be be needed. Once you've forced operands[1] into a register, you can just fall out the bottom of the pattern and let the default expansion take over. But... > + } > + else > + arm_split_constant (MINUS, SImode, NULL_RTX, > + INTVAL (operands[1]), operands[0], operands[2], > + optimize && can_create_pseudo_p ()); > DONE; ... You'll need to move the DONE inside the else clause. > } > else /* TARGET_THUMB1 */ > @@ -2077,6 +2084,17 @@ > emit_insn (gen_thumb2_zero_extendqisi2_v6 (operands[0], > operands[1])); > } > + else if (!(const_ok_for_arm (INTVAL (operands[2])) > + || const_ok_for_arm (~INTVAL (operands[2])) > + /* zero_extendhi instruction is efficient enough. */ > + || INTVAL (operands[2]) =3D=3D 0xffff > + || (INTVAL (operands[2]) < 0 > + && const_ok_for_arm (-INTVAL (operands[2])))) > + && can_create_pseudo_p ()) > + { > + operands[2] =3D force_reg (SImode, operands[2]); > + emit_insn (gen_andsi3 (operands[0], operands[1], operands[2])); Same here. > + } > else > arm_split_constant (AND, SImode, NULL_RTX, > INTVAL (operands[2]), operands[0], > @@ -2882,9 +2900,20 @@ > { > if (TARGET_32BIT) > { > - arm_split_constant (IOR, SImode, NULL_RTX, > - INTVAL (operands[2]), operands[0], operands[1], > - optimize && can_create_pseudo_p ()); > + if (!(const_ok_for_arm (INTVAL (operands[2])) > + || (TARGET_THUMB2 > + && const_ok_for_arm (~INTVAL (operands[2]))) > + || (INTVAL (operands[2]) < 0 > + && const_ok_for_arm (-INTVAL (operands[2])))) > + && can_create_pseudo_p ()) > + { > + operands[2] =3D force_reg (SImode, operands[2]); > + emit_insn (gen_iorsi3 (operands[0], operands[1], operands[2])); And here. > + } > + else > + arm_split_constant (IOR, SImode, NULL_RTX, > + INTVAL (operands[2]), operands[0], operands[1], > + optimize && can_create_pseudo_p ()); > DONE; > } > else /* TARGET_THUMB1 */ > @@ -3052,9 +3081,18 @@ > { > if (TARGET_32BIT) > { > - arm_split_constant (XOR, SImode, NULL_RTX, > - INTVAL (operands[2]), operands[0], operands[1], > - optimize && can_create_pseudo_p ()); > + if (!(const_ok_for_arm (INTVAL (operands[2])) > + || (INTVAL (operands[2]) < 0 > + && const_ok_for_arm (-INTVAL (operands[2])))) > + && can_create_pseudo_p ()) > + { > + operands[2] =3D force_reg (SImode, operands[2]); > + emit_insn (gen_xorsi3 (operands[0], operands[1], operands[2])); And here. > + } > + else > + arm_split_constant (XOR, SImode, NULL_RTX, > + INTVAL (operands[2]), operands[0], operands[1], > + optimize && can_create_pseudo_p ()); > DONE; > } > else /* TARGET_THUMB1 */ >=20 > diff --git a/gcc/testsuite/gcc.target/arm/maskdata.c b/gcc/testsuite/gcc.= target/arm/maskdata.c > new file mode 100644 > index 0000000..b4231a4 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/arm/maskdata.c > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-options " -O2 -fno-gcse " } */ > +/* { dg-require-effective-target arm_thumb2_ok } */ > + > +#define MASK 0xfe00ff > +void maskdata (int * data, int len) > +{ > + int i =3D len; > + for (; i > 0; i -=3D 2) > + { > + data[i] &=3D MASK; > + data[i + 1] &=3D MASK; > + } > +} > +/* { dg-final { scan-assembler "254" } } */ > +/* { dg-final { scan-assembler "255" } } */ >=20