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]

Re: [PATCH] doloop_optimize miscompiles openssl


On Mon, 25 Sep 2000, Geoff Keating wrote:
> Franz Sirl <Franz.Sirl-kernel@lauterbach.com> writes:
> > 	* doloop.c (doloop_modify): Prevent delete_insn() from
> > 	deleting too much.  Prefer loop->top over loop->start as
> > 	target for the new JUMP insn.
> >
> > Index: gcc/doloop.c
> > ===================================================================
> > RCS file: /cvs/gcc/egcs/gcc/doloop.c,v
> > retrieving revision 1.2
> > diff -u -p -r1.2 doloop.c
> > --- doloop.c	2000/08/14 20:55:11	1.2
> > +++ doloop.c	2000/09/24 22:00:04
> > @@ -416,11 +416,14 @@ doloop_modify (loop, iterations, iterati
> >      }
> >
> >    /* Discard original jump to continue loop.  The original compare
> > -     result may still be live, so it cannot be discarded explicitly.  */
> > +     result may still be live, so it cannot be discarded explicitly.
> > +     Don't delete too much, increment the use count of the target label.
> >  */ +  LABEL_NUSES (JUMP_LABEL (jump_insn))++;
> >    delete_insn (jump_insn);
> > +  LABEL_NUSES (JUMP_LABEL (jump_insn))--;
> >
> > -  /* Emit the label that will delimit the start of the loop.  */
> > -  emit_label_after (start_label, loop->start);
> > +  /* Emit the label that will delimit the top of the loop.  */
> > +  emit_label_after (start_label, loop->top ? loop->top : loop->start);
> >    LABEL_NUSES (start_label)++;
>
> Franz,
>
> would it work to simply emit the start_label before calling
> delete_insn?  After all, the label that jump_insn branches to is
> really not used after this transformation, right?

Yes, it works. In the meantime I found another bug with the appended 
testcase, it seems testing for loop_info->has_multiple_exit_targets is not 
enough for ruling out unsuitable loops. For the testcase 
loop_info->has_multiple_exit_targets is 0, but loop->exit_counmt is 3.

Franz.

	* doloop.c (doloop_modify): Prevent delete_insn() from
	deleting too much.  Prefer loop->top over loop->start as
	target for the new JUMP insn.
	(doloop_valid_p): Ignore loop with exit_count > 1.


Index: gcc/doloop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/doloop.c,v
retrieving revision 1.2
diff -u -p -r1.2 doloop.c
--- gcc/doloop.c	2000/08/14 20:55:11	1.2
+++ gcc/doloop.c	2000/09/25 21:43:34
@@ -281,7 +281,7 @@ doloop_valid_p (loop, jump_insn)
      statement within a loop will generate multiple loop exits.
      Another example of a loop that currently generates multiple exit
      targets is for (i = 0; i < (foo ? 8 : 4); i++) { }.  */
-  if (loop_info->has_multiple_exit_targets)
+  if (loop_info->has_multiple_exit_targets || loop->exit_count > 1)
     {
       if (loop_dump_stream)
 	fprintf (loop_dump_stream,
@@ -415,13 +415,13 @@ doloop_modify (loop, iterations, iterati
       fputs (" iterations).", loop_dump_stream);
     }
 
+  /* Emit the label that will delimit the top of the loop.  */
+  emit_label_after (start_label, loop->top ? loop->top : loop->start);
+  LABEL_NUSES (start_label)++;
+
   /* Discard original jump to continue loop.  The original compare
      result may still be live, so it cannot be discarded explicitly.  */
   delete_insn (jump_insn);
-
-  /* Emit the label that will delimit the start of the loop.  */
-  emit_label_after (start_label, loop->start);
-  LABEL_NUSES (start_label)++;
 
   counter_reg = XEXP (condition, 0);
   if (GET_CODE (counter_reg) == PLUS)
unsigned long bn_add_words(unsigned long *r, unsigned long *a, unsigned long *b, int n)
        {
        unsigned long long ll=0;

        if (n <= 0) return((unsigned long)0);

        for (;;)
                {
                ll+=(unsigned long long)a[0]+b[0];
                r[0]=(unsigned long)ll&(0xffffffffL);
                ll>>=32;
                if (--n <= 0) break;

                ll+=(unsigned long long)a[1]+b[1];
                r[1]=(unsigned long)ll&(0xffffffffL);
                ll>>=32;
                if (--n <= 0) break;

                ll+=(unsigned long long)a[2]+b[2];
                r[2]=(unsigned long)ll&(0xffffffffL);
                ll>>=32;
                if (--n <= 0) break;

                ll+=(unsigned long long)a[3]+b[3];
                r[3]=(unsigned long)ll&(0xffffffffL);
                ll>>=32;
                if (--n <= 0) break;

                a+=4;
                b+=4;
                r+=4;
                }
        return((unsigned long)ll);
        }

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