This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] fold-const.c: Don't transform X & C into (X >> C') & 1in fold_binary.


Jeffrey A Law <law@redhat.com> writes:
> On Thu, 2005-04-21 at 07:42 +0100, Richard Sandiford wrote:
>> In current sources, both:
>> 
>>     void f1 (int x) { if (x & 4) bar (); }
>> and:
>>     void f2 (int x) { if ((x >> 2) & 1) bar (); }
>> 
>> will be implemented using an "and" with 4 followed by a branch on zero.
>> We definitely want to keep this behaviour.  (I think the do_jump code
>> is effectively providing the canonical form you're talking about,
>> at least as far as branches go.)
> You know, it might be wise to put a test for this in the testsuite if
> we don't have one already.  

Good point.  I couldn't see an existing test, so here's what I installed.
I checked that it passed on mips-sgi-irix6.5.

There was talk downthread about checking how the tests are implemented
outside of a branch context.  It doesn't make much sense to do that for
MIPS because both alternatives (andi followed by sleu, shift followed
by and) are equally cheap.  There's no real reason to prefer one over
the other.

Richard


	* gcc.target/mips/branch-1.c: New test.

Index: testsuite/gcc.target/mips/branch-1.c
===================================================================
RCS file: testsuite/gcc.target/mips/branch-1.c
diff -N testsuite/gcc.target/mips/branch-1.c
*** testsuite/gcc.target/mips/branch-1.c	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.target/mips/branch-1.c	21 Apr 2005 19:55:40 -0000
***************
*** 0 ****
--- 1,11 ----
+ /* We should implement these "if" statements using an "andi" instruction
+    followed by a branch on zero.  */
+ /* { dg-mips-options "-O2 -mno-mips16" } */
+ void bar (void);
+ void f1 (int x) { if (x & 4) bar (); }
+ void f2 (int x) { if ((x >> 2) & 1) bar (); }
+ void f3 (unsigned int x) { if (x & 0x10) bar (); }
+ void f4 (unsigned int x) { if ((x >> 4) & 1) bar (); }
+ /* { dg-final { scan-assembler "\tandi\t.*\tandi\t.*\tandi\t.*\tandi\t" } } */
+ /* { dg-final { scan-assembler-not "\tsrl\t" } } */
+ /* { dg-final { scan-assembler-not "\tsra\t" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]