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: Tweak to gengtype



On 20/01/2005, at 2:24 PM, Steven Bosscher wrote:


Hi,

The following patch tweaks gengtype a bit to produce "!=" instead
of "<" in a loop test.  That results in slightly better code in a
few cases, e.g.:

BEFORE					AFTER
gt_ggc_mx_def_optype_d:			gt_ggc_mx_def_optype_d:
.LFB210:				.LFB210:
        cmpq    $1, %rdi		        cmpq    $1, %rdi
        pushq   %rbx			        pushq   %rbx
.LCFI13:				.LCFI13:
        movq    %rdi, %rbx		        movq    %rdi, %rbx
        ja      .L59			        ja      .L59
.L57:					.L57:
        popq    %rbx			        popq    %rbx
        ret				        ret
        .p2align 4,,7			        .p2align 4,,7
.L59:					.L59:
        call    ggc_set_mark		        call    ggc_set_mark
        testl   %eax, %eax		        testl   %eax, %eax
        .p2align 4,,6			        .p2align 4,,6
        jne     .L57			        jne     .L57
        movl    (%rbx), %eax		        movl    (%rbx), %eax
        xorl    %edx, %edx		        xorl    %edx, %edx
        testl   %eax, %eax		        testl   %eax, %eax
        mov     %eax, %ecx		        mov     %eax, %ecx
        je      .L57			        je      .L57
        .p2align 4,,7			        .p2align 4,,7
.L56:					.L56:
        incq    %rdx			        incq    %rdx
        cmpq    %rcx, %rdx		        cmpq    %rcx, %rdx
        jae     .L57		      |	        jne     .L56
        incq    %rdx		      |	        popq    %rbx
        cmpq    %rcx, %rdx	      |	        ret
        jb      .L56		      <
        .p2align 4,,3		      <
        jmp     .L57		      <
.LFE210:				.LFE210:

I doubt that this really makes any difference to performance, but I don't think it'll hurt performance either, so it's OK.


The reason I noticed this is the following marker function:

void
gt_ggc_mx_use_optype_d (void *x_p)
{
   struct use_optype_d * const x = (struct use_optype_d *)x_p;
   if (ggc_test_and_set_mark (x))
     {
       {
         size_t i0;
         for (i0 = 0; i0 < (size_t)(((*x)).num_uses); i0++) {
         }
       }
     }
}

I don't know how to avoid the empty loop, and GCC doesn't know how
to remove it :-/  Ideas, anyone?

GCC should really be able to remove a trivial empty loop like this one. It's easy to prove that it (a) really is empty and (b) is guaranteed to terminate. (The second condition is a bit harder, but all the logic should be there.) Do you know why it's not being removed?


Anyway, this patch below is a good idea regardless, I think.
Bootstrapped&tested on x86_64-suse-linux-gnu.  OK?

Gr.
Steven

	* gengtype.c (walk_type): Produce `not equal to' compares for loop
	tests, instead of `less than'.

Index: gengtype.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gengtype.c,v
retrieving revision 1.68
diff -u -3 -p -r1.68 gengtype.c
--- gengtype.c 22 Nov 2004 12:23:49 -0000 1.68
+++ gengtype.c 20 Jan 2005 22:09:45 -0000
@@ -1679,7 +1679,7 @@ walk_type (type_p t, struct walk_type_da
oprintf (d->of, "%*sif (%s != NULL) {\n", d->indent, "", d->val);
d->indent += 2;
oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
- oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
+ oprintf (d->of, "%*sfor (i%d = 0; i%d != (size_t)(", d->indent, "",
loopcounter, loopcounter);
output_escaped_param (d, length, "length");
oprintf (d->of, "); i%d++) {\n", loopcounter);
@@ -1715,7 +1715,7 @@ walk_type (type_p t, struct walk_type_da
oprintf (d->of, "%*s{\n", d->indent, "");
d->indent += 2;
oprintf (d->of, "%*ssize_t i%d;\n", d->indent, "", loopcounter);
- oprintf (d->of, "%*sfor (i%d = 0; i%d < (size_t)(", d->indent, "",
+ oprintf (d->of, "%*sfor (i%d = 0; i%d != (size_t)(", d->indent, "",
loopcounter, loopcounter);
if (length)
output_escaped_param (d, length, "length");

Attachment: smime.p7s
Description: S/MIME cryptographic signature


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