diff mbox

PR49799: Don't generate illegal bit field extraction instruction

Message ID CAEe8uECJSOzSpmJcCw1WK_P0Ae=_zFunT6_75d0HCf2Ct_uyLA@mail.gmail.com
State New
Headers show

Commit Message

Carrot Wei July 28, 2011, 8:40 a.m. UTC
Test case added.

Tested with
make check-gcc RUNTESTFLAGS="--target_board=arm-sim/thumb/arch=armv7-a
arm.exp=pr49799.c"
make check-gcc RUNTESTFLAGS="--target_board=arm-sim/arch=armv7-a
arm.exp=pr49799.c"

It fails without this patch and passes with this patch.

OK for trunk and 4.6 now?

thanks
Carrot

ChangeLog:
2011-07-28  Wei Guozhi  <carrot@google.com>

        PR rtl-optimization/49799
        * combine.c (make_compound_operation): Check if the bit field is valid
        before change it to bit field extraction.


ChangeLog:
2011-07-28  Wei Guozhi  <carrot@google.com>

        PR rtl-optimization/49799
        * pr49799.c : New test case.




On Thu, Jul 28, 2011 at 4:04 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Jul 28, 2011 at 03:38:07PM +0800, Carrot Wei wrote:
>> OK for trunk and 4.6?
>>
>> ChangeLog:
>> 2011-07-28  Wei Guozhi  <carrot@google.com>
>>
>>         PR rtl-optimization/49799
>>         * combine.c (make_compound_operation): Check if the bit field is valid
>>         before change it to bit field extraction.
>
> Looks good to me, handling SHIFT_COUNT_TRUNCATED here isn't IMHO necessary
> and the checking whether shift count is in the right range matches other rtx
> simplifications (e.g. in simplify-rtx.c).
> Though, you should add a testcase, probably
> /* PR rtl-optimization/49799 */
> /* { dg-do assemble } */
> /* { dg-options "-O2 -w" } */
>
> plus not sure if for arm you don't want to force this -march=armv7-a
> into dg-options too or just leave it as is.
>
>        Jakub
>

Comments

Jakub Jelinek July 28, 2011, 8:47 a.m. UTC | #1
On Thu, Jul 28, 2011 at 04:40:53PM +0800, Carrot Wei wrote:
> ChangeLog:
> 2011-07-28  Wei Guozhi  <carrot@google.com>
> 
>         PR rtl-optimization/49799
>         * pr49799.c : New test case.

Space shouldn't be between .c and :.  And the filename should be
relative to gcc/testsuite/ dir, so either gcc.target/arm/pr49799.c, or
better gcc.dg/pr49799.c.

Putting the testcase just into gcc.target/arm means it won't be tested
on other targets, while there is nothing arm specific about the testcase
except that you force -march in dg-options for arm.
You can do that with
/* PR rtl-optimization/49799 */
/* { dg-do assemble } */
/* { dg-options "-O2 -w" } */
/* { dg-options "-O2 -w -march=armv7-a" { target arm*-*-* } } */
or similar.

Ok with those changes.

	Jakub
Richard Earnshaw July 28, 2011, 12:42 p.m. UTC | #2
On 28/07/11 09:40, Carrot Wei wrote:
> Index: pr49799.c
> ===================================================================
> --- pr49799.c	(revision 0)
> +++ pr49799.c	(revision 0)
> @@ -0,0 +1,25 @@
> +/* PR rtl-optimization/49799 */
> +/* { dg-do assemble } */
> +/* { dg-options "-O2 -w -march=armv7-a" } */

No, don't force the architecture like this.  Just let multilib variant
handling deal with it.

Once you've done that, then this test isn't cpu specific and can be
moved to c-torture/compile.

R.
diff mbox

Patch

Index: gcc/combine.c
===================================================================
--- gcc/combine.c	(revision 176733)
+++ gcc/combine.c	(working copy)
@@ -7787,6 +7787,7 @@  make_compound_operation (rtx x, enum rtx
 	  && GET_CODE (lhs) == ASHIFT
 	  && CONST_INT_P (XEXP (lhs, 1))
 	  && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1))
+	  && INTVAL (XEXP (lhs, 1)) >= 0
 	  && INTVAL (rhs) < mode_width)
 	{
 	  new_rtx = make_compound_operation (XEXP (lhs, 0), next_code);


Index: pr49799.c
===================================================================
--- pr49799.c	(revision 0)
+++ pr49799.c	(revision 0)
@@ -0,0 +1,25 @@ 
+/* PR rtl-optimization/49799 */
+/* { dg-do assemble } */
+/* { dg-options "-O2 -w -march=armv7-a" } */
+
+static __inline int bar(int a)
+{
+    int tmp;
+
+    if (a <= 0) a ^= 0xFFFFFFFF;
+
+    return tmp - 1;
+}
+
+void foo(short *K)
+{
+    short tmp;
+    short *pptr, P[14];
+
+    pptr = P;
+    tmp = bar(*K);
+    *pptr = (*K << tmp) >> 16;
+
+    if (*P < tmp)
+        *K++ = 0;
+}