public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: More fp bug in egcs
@ 1998-05-03  0:55 H.J. Lu
  1998-05-03 12:03 ` H.J. Lu
  1998-05-03 20:10 ` Jim Wilson
  0 siblings, 2 replies; 19+ messages in thread
From: H.J. Lu @ 1998-05-03  0:55 UTC (permalink / raw)
  To: wilson, law, scox, p3; +Cc: egcs

> 
> > 
> > I believe this is another bug in the same i386 code as my last patch.
> > 
> > The problem is that the only FP->DImode converstion instruction pops the
> > FP stack.  Normally we have both popping and non-popping versions of
> > instructions.  The x86 code handles this by aborting if we need to emit
> > the non-existent non-popping instruction.  However, this can't work all
> > of the time, because it assumes the optimizer always generates optimal
> > code.  That isn't safe.  And it is obviously not safe if we are compiling
> > without optimization.
> > 
> > In order to fix this, we need to emulate the missing instruction if gcc
> > needs to emit it.  The following patch does this.   If there is a better way
> > to do this, then let me know.
> > 
> > Thu Apr 30 19:28:16 1998  Jim Wilson  <wilson@cygnus.com>
> > 
> > 	* i386.c (output_fix_trunc): Add code to emulate non-popping DImode
> > 	case.
> > 
> > *** i386.c	Sun Feb 15 11:54:11 1998
> > --- /home/wilson/tmp/i386.c	Thu Apr 30 19:26:54 1998
> > *************** output_fix_trunc (insn, operands)
> > *** 3731,3738 ****
> >     int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
> >     rtx xops[2];
> >   
> > !   if (! STACK_TOP_P (operands[1]) ||
> > !       (GET_MODE (operands[0]) == DImode && ! stack_top_dies))
> >       abort ();
> >   
> >     xops[0] = GEN_INT (12);
> > --- 3731,3737 ----
> >     int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
> >     rtx xops[2];
> >   
> > !   if (! STACK_TOP_P (operands[1]))
> >       abort ();
> >   
> >     xops[0] = GEN_INT (12);
> > *************** output_fix_trunc (insn, operands)
> > *** 3750,3755 ****
> > --- 3749,3765 ----
> >       {
> >         if (stack_top_dies)
> >   	output_asm_insn (AS1 (fistp%z0,%0), operands);
> > +       else if (GET_MODE (operands[0]) == DImode && ! stack_top_dies)
> > + 	{
> > + 	  /* There is no DImode version of this without a stack pop, so
> > + 	     we must emulate it.  It doesn't matter much what the second
> > + 	     instruction is, because the value being pushed on the FP stack
> > + 	     is not used except for the following stack popping store.
> > + 	     This case can only happen without optimization, so it doesn't
> > + 	     matter that it is inefficient.  */
> > + 	  output_asm_insn (AS1 (fistp%z0,%0), operands);
> > + 	  output_asm_insn (AS1 (fild%z0,%0), operands);
> > + 	}
> >         else
> >   	output_asm_insn (AS1 (fist%z0,%0), operands);
> >       }
> > 
> 
> Here is the trimmed down test case. I am not sure if your patch is
> correct. If you take look at the stack RTL dump, you will see SF 1 in
> 
> (define_insn ""
>   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
>         (fix:DI (fix:SF (match_operand:SF 1 "register_operand" "+f")))) 
>    (clobber (match_dup 1))
>    (clobber (match_operand:SI 2 "memory_operand" "m"))        
>    (clobber (match_operand:DI 3 "memory_operand" "m"))
>    (clobber (match_scratch:SI 4 "=&q"))]
>   "TARGET_80387"
>   "* return output_fix_trunc (insn, operands);")                 
> 
> is used as the input for the next insn:
> 
> ;; Insn is not within a basic block
> (insn:QI 104 269 272 (parallel[ 
>             (set (mem:DI (plus:SI (reg:SI 6 %ebp)
>                         (const_int -144)))
>                 (fix:DI (fix:SF (reg:SF 8 %st(0)))))
>             (clobber (reg:SF 8 %st(0)))
>             (clobber (mem:SI (plus:SI (reg:SI 6 %ebp)
>                         (const_int -4))))
>             (clobber (mem:DI (plus:SI (reg:SI 6 %ebp)
>                         (const_int -12))))
>             (clobber (reg:SI 1 %edx))
>         ] ) 117 {fix_truncxfsi2-1} (nil)
>     (nil))
> 
> ;; Insn is not within a basic block
> (insn:QI 272 104 275 (set (mem:SF (plus:SI (reg:SI 6 %ebp)
>                 (const_int -148)))
>         (reg:SF 8 %st(0))) -1 (nil)
>     (expr_list:REG_DEAD (reg:DF 8 %st(0))
>         (nil)))
> 
> I don't know if it is correct. Did gcc know %st(0) was not the same
> %st(0) before?
> 

How does this patch look? It works for my test case.

I think it is a reload bug. I don't know what the purpose to output the
last reload for a dead register. I don't what the best solution is and
I am not sure if my patch covers all cases.

Thanks.


---
Sun May  3 00:35:41 1998  H.J. Lu  (hjl@gnu.org)

	* reload1.c (emit_reload_insns): Don't output the last reload
	insn if OLD is dead at the end of INSN.

--- ../../../import/egcs/gcc/reload1.c	Mon Apr 20 08:23:47 1998
+++ reload1.c	Sun May  3 00:49:52 1998
@@ -6729,7 +6729,8 @@ emit_reload_insns (insn)
 #endif
 
 	  /* Output the last reload insn.  */
-	  if (! special)
+	  if (! special && (GET_CODE (old) != REG
+			    || !dead_or_set_p (insn, old)))
 	    gen_reload (old, reloadreg, reload_opnum[j],
 			reload_when_needed[j]);
 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-03  0:55 More fp bug in egcs H.J. Lu
@ 1998-05-03 12:03 ` H.J. Lu
  1998-05-03 17:14   ` Jim Wilson
  1998-05-03 20:10 ` Jim Wilson
  1 sibling, 1 reply; 19+ messages in thread
From: H.J. Lu @ 1998-05-03 12:03 UTC (permalink / raw)
  To: H.J. Lu; +Cc: wilson, law, scox, p3, 

> 
> How does this patch look? It works for my test case.
> 
> I think it is a reload bug. I don't know what the purpose to output the
> last reload for a dead register. I don't what the best solution is and
> I am not sure if my patch covers all cases.
> 

Here is a revised patch. I hope this bug can be fixed in 1.0.3.

Thanks.


H.J.
----
Sun May  3 10:48:40 1998  H.J. Lu  (hjl@gnu.org)

	* reload1.c (emit_reload_insns): Don't output the last reload
	insn if OLD is not the dest of INSN and is dead at the end of
	INSN.

--- ../../../import/egcs/gcc/reload1.c	Mon Apr 20 08:23:47 1998
+++ ./reload1.c	Sun May  3 11:26:28 1998
@@ -6730,8 +6730,17 @@ emit_reload_insns (insn)
 
 	  /* Output the last reload insn.  */
 	  if (! special)
-	    gen_reload (old, reloadreg, reload_opnum[j],
-			reload_when_needed[j]);
+	    {
+	      rtx set;
+
+	      /* Don't output the last reload if OLD is not the dest
+		 of INSN and is dead at the end of INSN. */
+	      if (GET_CODE (old) != REG || !(set = single_set (insn))
+		  || old == SET_DEST (set)
+		  || !dead_or_set_p (insn, old))
+		gen_reload (old, reloadreg, reload_opnum[j],
+			    reload_when_needed[j]);
+	    }
 
 #ifdef PRESERVE_DEATH_INFO_REGNO_P
 	  /* If final will look at death notes for this reg,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-03 12:03 ` H.J. Lu
@ 1998-05-03 17:14   ` Jim Wilson
  1998-05-04 11:17     ` H.J. Lu
  0 siblings, 1 reply; 19+ messages in thread
From: Jim Wilson @ 1998-05-03 17:14 UTC (permalink / raw)
  To: H.J. Lu; +Cc: law, scox, crux, egcs

One reason for keeping output reloads, even though the register is dead, is
for debugging purposes.  With your patch, it looks like debugging of 
unoptimized code would not work right.  It would be OK to do this
when optimizing, but that would not fix the x86 bug.

Jim


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-03  0:55 More fp bug in egcs H.J. Lu
  1998-05-03 12:03 ` H.J. Lu
@ 1998-05-03 20:10 ` Jim Wilson
  1998-05-05  5:46   ` Jeffrey A Law
  1 sibling, 1 reply; 19+ messages in thread
From: Jim Wilson @ 1998-05-03 20:10 UTC (permalink / raw)
  To: H.J. Lu; +Cc: law, scox, crux, egcs

	How does this patch look? It works for my test case.

A reload patch is not a safe way to fix this problem.  Your reload patch
affects all programs for all targets.  My patch affects only x86 programs
that currently fail.  Since my patch has much more limited scope, it is a
much better solution for a egcs-1.0.3 bug fix release.

	I think it is a reload bug. I don't know what the purpose to output the
	last reload for a dead register. I don't what the best solution is and
	I am not sure if my patch covers all cases.

I think it is more accurate to call it a `missed optimization' than a `bug',
as the output is correct.  The only reason it fails on the x86 is because of
a i386.md bug which my patch fixes.

While it may be useful to add this optimization, I don't think that egcs-1.0.3
is the proper place to try it.  Especially considering how hard it is to get
reload patches right.

Jim

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-03 17:14   ` Jim Wilson
@ 1998-05-04 11:17     ` H.J. Lu
  1998-05-04 18:07       ` Jeffrey A Law
  0 siblings, 1 reply; 19+ messages in thread
From: H.J. Lu @ 1998-05-04 11:17 UTC (permalink / raw)
  To: Jim Wilson; +Cc: hjl, law, scox, crux, egcs

> 
> One reason for keeping output reloads, even though the register is dead, is
> for debugging purposes.  With your patch, it looks like debugging of 
> unoptimized code would not work right.  It would be OK to do this
> when optimizing, but that would not fix the x86 bug.
> 

If the register is clobbered, isn't the value in it random? If it is
tru, how can it help debugging? I changed my patch to omit the output
reload if it is in the source and is clobbered. Does it look safe?


-- 
H.J. Lu (hjl@gnu.org)
----
Sun May  3 18:44:40 1998  H.J. Lu  (hjl@gnu.org)

	* reload1.c (emit_reload_insns): Don't output the last reload
	insn if OLD is the src of INSN and is clobbered by INSN.

--- ../../../import/egcs/gcc/reload1.c	Mon Apr 20 08:23:47 1998
+++ ./reload1.c	Sun May  3 18:57:26 1998
@@ -6730,8 +6730,17 @@ emit_reload_insns (insn)
 
 	  /* Output the last reload insn.  */
 	  if (! special)
-	    gen_reload (old, reloadreg, reload_opnum[j],
-			reload_when_needed[j]);
+	    {
+	      rtx set;
+
+	      /* Don't output the last reload if OLD is the src of INSN
+		 and is clobbered by INSN. */
+	      if (GET_CODE (old) != REG || !(set = single_set (insn))
+		  || !reg_mentioned_p (old, SET_SRC (set))
+		  || !regno_clobbered_p (REGNO (old), insn))
+		gen_reload (old, reloadreg, reload_opnum[j],
+			    reload_when_needed[j]);
+	    }
 
 #ifdef PRESERVE_DEATH_INFO_REGNO_P
 	  /* If final will look at death notes for this reg,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-04 18:07       ` Jeffrey A Law
@ 1998-05-04 18:07         ` H.J. Lu
  1998-05-04 22:00           ` Jeffrey A Law
  1998-05-08 16:04           ` Jeffrey A Law
  0 siblings, 2 replies; 19+ messages in thread
From: H.J. Lu @ 1998-05-04 18:07 UTC (permalink / raw)
  To: law; +Cc: hjl, wilson, scox, crux, egcs

> 
> 
>   In message < m0yWMtF-000268C@ocean.lucon.org >you write:
>   > > 
>   > > One reason for keeping output reloads, even though the register is dead, 
>   > is
>   > > for debugging purposes.  With your patch, it looks like debugging of 
>   > > unoptimized code would not work right.  It would be OK to do this
>   > > when optimizing, but that would not fix the x86 bug.
>   > > 
>   > 
>   > If the register is clobbered, isn't the value in it random? If it is
>   > tru, how can it help debugging? I changed my patch to omit the output
>   > reload if it is in the source and is clobbered. Does it look safe?
> >From the compiler's standpoint it is clobbered.
> 
> However, the value in the clobbered register might have meaning to
> the user that is debugging code.
> 

Since the value in the clobbered register is controlled by the
compiler, may depend on the user source code, may change from
release to release and the clobbered register itself may disappear
from release to release, how will the user know what the value in
the clobbered register should be? It seems to me that as far as
the user is concerned, any value in the clobbered register is
be ok as long as the destination of the instruction is valid.

I am enclosing a modified patch. It is very conservative. Does
it look safe?

-- 
Mon May  4 07:43:05 1998  H.J. Lu  (hjl@gnu.org)

	* reload1.c (emit_reload_insns): Don't output the last reload
	insn if OLD is not the dest of NSN and is in the src and is
	clobbered by INSN.

--- ../../../import/egcs/gcc/reload1.c	Mon Apr 20 08:23:47 1998
+++ ./reload1.c	Mon May  4 13:41:46 1998
@@ -6730,8 +6730,18 @@ emit_reload_insns (insn)
 
 	  /* Output the last reload insn.  */
 	  if (! special)
-	    gen_reload (old, reloadreg, reload_opnum[j],
-			reload_when_needed[j]);
+	    {
+	      rtx set;
+
+	      /* Don't output the last reload if OLD is not the dest of
+		 INSN and is in the src and is clobbered by INSN. */
+	      if (GET_CODE (old) != REG || !(set = single_set (insn))
+		  || rtx_equal_p (old, SET_DEST (set))
+		  || !reg_mentioned_p (old, SET_SRC (set))
+		  || !regno_clobbered_p (REGNO (old), insn))
+		gen_reload (old, reloadreg, reload_opnum[j],
+			    reload_when_needed[j]);
+	    }
 
 #ifdef PRESERVE_DEATH_INFO_REGNO_P
 	  /* If final will look at death notes for this reg,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-04 11:17     ` H.J. Lu
@ 1998-05-04 18:07       ` Jeffrey A Law
  1998-05-04 18:07         ` H.J. Lu
  0 siblings, 1 reply; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-04 18:07 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jim Wilson, scox, crux, egcs

  In message < m0yWMtF-000268C@ocean.lucon.org >you write:
  > > 
  > > One reason for keeping output reloads, even though the register is dead, 
  > is
  > > for debugging purposes.  With your patch, it looks like debugging of 
  > > unoptimized code would not work right.  It would be OK to do this
  > > when optimizing, but that would not fix the x86 bug.
  > > 
  > 
  > If the register is clobbered, isn't the value in it random? If it is
  > tru, how can it help debugging? I changed my patch to omit the output
  > reload if it is in the source and is clobbered. Does it look safe?
From the compiler's standpoint it is clobbered.

However, the value in the clobbered register might have meaning to
the user that is debugging code.

jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-04 18:07         ` H.J. Lu
@ 1998-05-04 22:00           ` Jeffrey A Law
  1998-05-08 16:04           ` Jeffrey A Law
  1 sibling, 0 replies; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-04 22:00 UTC (permalink / raw)
  To: H.J. Lu; +Cc: wilson, scox, crux, egcs

  In message < m0yWSyp-000268C@ocean.lucon.org >you write:
  > Since the value in the clobbered register is controlled by the
  > compiler, may depend on the user source code, may change from
  > release to release and the clobbered register itself may disappear
  > from release to release, how will the user know what the value in
  > the clobbered register should be? It seems to me that as far as
  > the user is concerned, any value in the clobbered register is
  > be ok as long as the destination of the instruction is valid.
HJ, we are not fixing this bug with a patch to reload.  Period.

If you want to argue that this code is an optimization and it actually
helps with -O, then we'll consider adding it as an optimization.  But
it is not the right way to fix the bug.

jef

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-03 20:10 ` Jim Wilson
@ 1998-05-05  5:46   ` Jeffrey A Law
  0 siblings, 0 replies; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-05  5:46 UTC (permalink / raw)
  To: Jim Wilson; +Cc: H.J. Lu, scox, crux, egcs

  In message < 199805032254.PAA08319@rtl.cygnus.com >you write:
  > 	How does this patch look? It works for my test case.
  > 
  > A reload patch is not a safe way to fix this problem.  Your reload patch
  > affects all programs for all targets.  My patch affects only x86 programs
  > that currently fail.  Since my patch has much more limited scope, it is a
  > much better solution for a egcs-1.0.3 bug fix release.
Agreed!

  > 	I think it is a reload bug. I don't know what the purpose to output the
  > 	last reload for a dead register. I don't what the best solution is and
  > 	I am not sure if my patch covers all cases.
  > 
  > I think it is more accurate to call it a `missed optimization' than a `bug',
  > as the output is correct.  The only reason it fails on the x86 is because of
  > a i386.md bug which my patch fixes.
Agreed again.

HJ -- you're making the same fundamental mistake as you did with the
"disable regmove" bug which really turned out to be a bug in i386.md.

Jim's patch is more correct to fix the bug and several orders of
magnitude safer.

And I think both Jim and I agree that you can make a case for your
patch as an optimization -- in which case it would belong in the
development branch, not the release branch.

jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-04 18:07         ` H.J. Lu
  1998-05-04 22:00           ` Jeffrey A Law
@ 1998-05-08 16:04           ` Jeffrey A Law
  1 sibling, 0 replies; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-08 16:04 UTC (permalink / raw)
  To: H.J. Lu; +Cc: wilson, scox, crux, egcs

  In message < m0yWSyp-000268C@ocean.lucon.org >you write:
  > 	* reload1.c (emit_reload_insns): Don't output the last reload
  > 	insn if OLD is not the dest of NSN and is in the src and is
  > 	clobbered by INSN.
I played with this a little the other day on the assumption that
we could consider it as an optimization patch.

I did bootstraps with an instrumented compiler to detect when this
optimization could be applied.

For an x86 -O2 bootstrap it triggered only about 15 times; I analyzed
at some (but not all) of the cases where this change was able to
optimize code better.

They all looked like safe optimizations (which isn't a suprise given
the purpose of the patch).  Sometimes we deleted a store into memory
other times it was just a reg-reg copy.

The optimization never triggered during a PA bootstrap.  Which, isn't
a big suprise.

I went ahead and installed a modified version of the patch which
only triggers when -fexpensive-optimizations is enabled.


jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-05 19:14       ` H.J. Lu
@ 1998-05-06 11:49         ` Jim Wilson
  0 siblings, 0 replies; 19+ messages in thread
From: Jim Wilson @ 1998-05-06 11:49 UTC (permalink / raw)
  To: H.J. Lu; +Cc: law, scox, crux, egcs

	Here is the stack RTL dump again. As you can see
            (clobber (reg:SF 14 %st(6)))
	should be
            (clobber (reg:SF 8 %st(0)))
	Should I worry about it? I think the bug is in move_for_stack_reg () in
	reg-stack.c:

There is no need to worry about it for the egcs-1.0.3 release or the egcs-1.1.x
release.  It would be nice to get this fixed in the development sources in
the long term, but for now it is perfectly harmless.

There is a general problem that reg-stack does not perform register
substitutions in clobbers.  The fix will probably be involved, and would
not be safe for any pending release.

Jim

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-05  0:35     ` Jeffrey A Law
@ 1998-05-05 19:14       ` H.J. Lu
  1998-05-06 11:49         ` Jim Wilson
  0 siblings, 1 reply; 19+ messages in thread
From: H.J. Lu @ 1998-05-05 19:14 UTC (permalink / raw)
  To: law; +Cc: hjl, wilson, scox, crux, egcs

> 
> 
>   In message < m0yVnEy-000268C@ocean.lucon.org >you write:
>   > Here is the trimmed down test case. I am not sure if your patch is
>   > correct. If you take look at the stack RTL dump, you will see SF 1 in
> [ ... ]
> BTW, I added the testcase to the testsuite.
> 
> jeff
> 

Here is the stack RTL dump again. As you can see

            (clobber (reg:SF 14 %st(6)))

should be

            (clobber (reg:SF 8 %st(0)))

Should I worry about it? I think the bug is in move_for_stack_reg () in
reg-stack.c:

  else if (STACK_REG_P (src))
    {
      /* Save from a stack reg to MEM, or possibly integer reg.  Since
	 only top of stack may be saved, emit an exchange first if
	 needs be.  */

      emit_swap_insn (insn, regstack, src);

      note = find_regno_note (insn, REG_DEAD, REGNO (src));
      if (note)
	{
	  replace_reg (&XEXP (note, 0), FIRST_STACK_REG);
	  regstack->top--;
	  CLEAR_HARD_REG_BIT (regstack->reg_set, REGNO (src));
	}
      else if (GET_MODE (src) == XFmode && regstack->top < REG_STACK_SIZE - 1)
	{
	  /* A 387 cannot write an XFmode value to a MEM without
	     clobbering the source reg.  The output code can handle
	     this by reading back the value from the MEM.
	     But it is more efficient to use a temp register if one is
	     available.  Push the source value here if the register
	     stack is not full, and then write the value to memory via
	     a pop.  */
	  rtx push_rtx, push_insn;
	  rtx top_stack_reg = FP_MODE_REG (FIRST_STACK_REG, XFmode);

	  push_rtx = gen_movxf (top_stack_reg, top_stack_reg);
	  push_insn = emit_insn_before (push_rtx, insn);
	  PUT_MODE (push_insn, QImode);
	  REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_DEAD, top_stack_reg,
				      REG_NOTES (insn));
	}

      replace_reg (psrc, FIRST_STACK_REG);
    }

The problem is not all notes are updated.

-- 
H.J. Lu (hjl@gnu.org)
----
;; Insn is not within a basic block
(insn:QI 67 163 166 (parallel[ 
            (set (reg:DI 2 %ecx)
                (fix:DI (fix:SF (reg:SF 8 %st(0)))))
            (clobber (reg:SF 14 %st(6)))
            (clobber (mem:SI (plus:SI (reg:SI 6 %ebp)
                        (const_int -20))))
            (clobber (mem:DI (plus:SI (reg:SI 6 %ebp)
                        (const_int -28))))
            (clobber (reg:SI 1 %edx))
        ] ) 120 {fix_truncxfsi2-1} (nil)
    (nil))

;; Insn is not within a basic block
(insn:QI 166 67 68 (set (mem:SF (plus:SI (reg:SI 6 %ebp)
                (const_int -76)))
        (reg:SF 8 %st(0))) -1 (nil)
    (expr_list:REG_DEAD (reg:DF 8 %st(0))
        (nil)))

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-04-30 20:03 ` Jim Wilson
  1998-05-02 18:56   ` H.J. Lu
@ 1998-05-05  5:03   ` Jeffrey A Law
  1 sibling, 0 replies; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-05  5:03 UTC (permalink / raw)
  To: Jim Wilson; +Cc: H.J. Lu, scox, crux, egcs

  In message <199805010234.TAA02560@ada.cygnus.com.cygnus.com>you write:
  > I believe this is another bug in the same i386 code as my last patch.
  > 
  > The problem is that the only FP->DImode converstion instruction pops the
  > FP stack.  Normally we have both popping and non-popping versions of
  > instructions.  The x86 code handles this by aborting if we need to emit
  > the non-existent non-popping instruction.  However, this can't work all
  > of the time, because it assumes the optimizer always generates optimal
  > code.  That isn't safe.  And it is obviously not safe if we are compiling
  > without optimization.
  > 
  > In order to fix this, we need to emulate the missing instruction if gcc
  > needs to emit it.  The following patch does this.   If there is a better wa
  > y
  > to do this, then let me know.
  > 
  > Thu Apr 30 19:28:16 1998  Jim Wilson  <wilson@cygnus.com>
  > 
  > 	* i386.c (output_fix_trunc): Add code to emulate non-popping DImode
  > 	case.
I went ahead and checked this into the release branch and the mainline
sources.
jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-02 18:56   ` H.J. Lu
  1998-05-03 20:10     ` Jim Wilson
@ 1998-05-05  0:35     ` Jeffrey A Law
  1998-05-05 19:14       ` H.J. Lu
  1 sibling, 1 reply; 19+ messages in thread
From: Jeffrey A Law @ 1998-05-05  0:35 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jim Wilson, scox, crux, egcs

  In message < m0yVnEy-000268C@ocean.lucon.org >you write:
  > Here is the trimmed down test case. I am not sure if your patch is
  > correct. If you take look at the stack RTL dump, you will see SF 1 in
[ ... ]
BTW, I added the testcase to the testsuite.

jeff

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-05-02 18:56   ` H.J. Lu
@ 1998-05-03 20:10     ` Jim Wilson
  1998-05-05  0:35     ` Jeffrey A Law
  1 sibling, 0 replies; 19+ messages in thread
From: Jim Wilson @ 1998-05-03 20:10 UTC (permalink / raw)
  To: H.J. Lu; +Cc: law, scox, crux, egcs

	Here is the trimmed down test case. I am not sure if your patch is
	correct. If you take look at the stack RTL dump, you will see SF 1 in
	is used as the input for the next insn:

It is supposed to be used by the next instruction.  This is the output reload
that copies the input/output value to the stack slot where it lives.  However,
since this value is dead, it will never be read from the stack slot, and hence
it doesn't matter what this value is.

The only problem here is that the code is inefficient, but since this case
can only happen when not optimized, this is not a problem.

	I don't know if it is correct. Did gcc know %st(0) was not the same
	%st(0) before?

Yes, gcc knows that %st(0) was clobbered.  This is why the following
instruction is storing the clobbered value back to the stack slot where it
lives.

When considering how to fix this bug, it is important to separate what the
RTL means from what the actual x86 FP instructions are.  My patch fixes the
problem by synthesizing a missing instruction.  This is a perfectly valid thing
to do.  This is no different than using two 4-byte loads to make a 8-byte load.
It is just a bit harder to understand because the FP stack is involved.

Jim


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-04-30 20:03 ` Jim Wilson
@ 1998-05-02 18:56   ` H.J. Lu
  1998-05-03 20:10     ` Jim Wilson
  1998-05-05  0:35     ` Jeffrey A Law
  1998-05-05  5:03   ` Jeffrey A Law
  1 sibling, 2 replies; 19+ messages in thread
From: H.J. Lu @ 1998-05-02 18:56 UTC (permalink / raw)
  To: Jim Wilson; +Cc: hjl, wilson, law, scox, crux, egcs

> 
> I believe this is another bug in the same i386 code as my last patch.
> 
> The problem is that the only FP->DImode converstion instruction pops the
> FP stack.  Normally we have both popping and non-popping versions of
> instructions.  The x86 code handles this by aborting if we need to emit
> the non-existent non-popping instruction.  However, this can't work all
> of the time, because it assumes the optimizer always generates optimal
> code.  That isn't safe.  And it is obviously not safe if we are compiling
> without optimization.
> 
> In order to fix this, we need to emulate the missing instruction if gcc
> needs to emit it.  The following patch does this.   If there is a better way
> to do this, then let me know.
> 
> Thu Apr 30 19:28:16 1998  Jim Wilson  <wilson@cygnus.com>
> 
> 	* i386.c (output_fix_trunc): Add code to emulate non-popping DImode
> 	case.
> 
> *** i386.c	Sun Feb 15 11:54:11 1998
> --- /home/wilson/tmp/i386.c	Thu Apr 30 19:26:54 1998
> *************** output_fix_trunc (insn, operands)
> *** 3731,3738 ****
>     int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
>     rtx xops[2];
>   
> !   if (! STACK_TOP_P (operands[1]) ||
> !       (GET_MODE (operands[0]) == DImode && ! stack_top_dies))
>       abort ();
>   
>     xops[0] = GEN_INT (12);
> --- 3731,3737 ----
>     int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
>     rtx xops[2];
>   
> !   if (! STACK_TOP_P (operands[1]))
>       abort ();
>   
>     xops[0] = GEN_INT (12);
> *************** output_fix_trunc (insn, operands)
> *** 3750,3755 ****
> --- 3749,3765 ----
>       {
>         if (stack_top_dies)
>   	output_asm_insn (AS1 (fistp%z0,%0), operands);
> +       else if (GET_MODE (operands[0]) == DImode && ! stack_top_dies)
> + 	{
> + 	  /* There is no DImode version of this without a stack pop, so
> + 	     we must emulate it.  It doesn't matter much what the second
> + 	     instruction is, because the value being pushed on the FP stack
> + 	     is not used except for the following stack popping store.
> + 	     This case can only happen without optimization, so it doesn't
> + 	     matter that it is inefficient.  */
> + 	  output_asm_insn (AS1 (fistp%z0,%0), operands);
> + 	  output_asm_insn (AS1 (fild%z0,%0), operands);
> + 	}
>         else
>   	output_asm_insn (AS1 (fist%z0,%0), operands);
>       }
> 

Here is the trimmed down test case. I am not sure if your patch is
correct. If you take look at the stack RTL dump, you will see SF 1 in

(define_insn ""
  [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
        (fix:DI (fix:SF (match_operand:SF 1 "register_operand" "+f")))) 
   (clobber (match_dup 1))
   (clobber (match_operand:SI 2 "memory_operand" "m"))        
   (clobber (match_operand:DI 3 "memory_operand" "m"))
   (clobber (match_scratch:SI 4 "=&q"))]
  "TARGET_80387"
  "* return output_fix_trunc (insn, operands);")                 

is used as the input for the next insn:

;; Insn is not within a basic block
(insn:QI 104 269 272 (parallel[ 
            (set (mem:DI (plus:SI (reg:SI 6 %ebp)
                        (const_int -144)))
                (fix:DI (fix:SF (reg:SF 8 %st(0)))))
            (clobber (reg:SF 8 %st(0)))
            (clobber (mem:SI (plus:SI (reg:SI 6 %ebp)
                        (const_int -4))))
            (clobber (mem:DI (plus:SI (reg:SI 6 %ebp)
                        (const_int -12))))
            (clobber (reg:SI 1 %edx))
        ] ) 117 {fix_truncxfsi2-1} (nil)
    (nil))

;; Insn is not within a basic block
(insn:QI 272 104 275 (set (mem:SF (plus:SI (reg:SI 6 %ebp)
                (const_int -148)))
        (reg:SF 8 %st(0))) -1 (nil)
    (expr_list:REG_DEAD (reg:DF 8 %st(0))
        (nil)))

I don't know if it is correct. Did gcc know %st(0) was not the same
%st(0) before?


Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---
typedef struct _geom_elem {
  double        coeffs[6];
} pGeomDefRec, *pGeomDefPtr;
typedef struct _mpgeombanddef {
	int	yOut;		 
	int	in_width;	 
} mpGeometryBandRec, *mpGeometryBandPtr;
typedef void *pointer;
typedef unsigned char  CARD8;
typedef CARD8 BytePixel;
void  BiGL_B  (OUTP,srcimg,width,sline,pedpvt,pvtband)	pointer OUTP;
pointer *srcimg;
register int width;
int sline;
pGeomDefPtr pedpvt; mpGeometryBandPtr pvtband;
{
  register float s, t, st;
  register int 	isrcline,isrcpix;
  register int 	srcwidth = pvtband->in_width - 1;
  register   BytePixel  val;
  register   BytePixel  *ptrIn, *ptrJn;
  register double a  = pedpvt->coeffs[0];
  register double c  = pedpvt->coeffs[2];
  register double srcpix  = a * ((double)(0.0000))  +	pedpvt->coeffs[1] * (pvtband->yOut + ((double)(0.0000)) ) +	pedpvt->coeffs[4];
  register double srcline = c * ((double)(0.0000))  +	pedpvt->coeffs[3] * (pvtband->yOut + ((double)(0.0000)) ) +	pedpvt->coeffs[5];
  if ( (isrcpix >= 0) && (isrcpix < srcwidth) )
    val =	ptrIn[isrcpix]   * ((float)1. - s - t + st) + ptrIn[isrcpix+1] * (s - st) +	ptrJn[isrcpix]   * (t - st) +	ptrJn[isrcpix+1] * (st) +   (float)0.5 ;
} 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-04-25 18:25 H.J. Lu
  1998-04-27 21:29 ` Jim Wilson
@ 1998-04-30 20:03 ` Jim Wilson
  1998-05-02 18:56   ` H.J. Lu
  1998-05-05  5:03   ` Jeffrey A Law
  1 sibling, 2 replies; 19+ messages in thread
From: Jim Wilson @ 1998-04-30 20:03 UTC (permalink / raw)
  To: H.J. Lu; +Cc: wilson, law, scox, crux, egcs

I believe this is another bug in the same i386 code as my last patch.

The problem is that the only FP->DImode converstion instruction pops the
FP stack.  Normally we have both popping and non-popping versions of
instructions.  The x86 code handles this by aborting if we need to emit
the non-existent non-popping instruction.  However, this can't work all
of the time, because it assumes the optimizer always generates optimal
code.  That isn't safe.  And it is obviously not safe if we are compiling
without optimization.

In order to fix this, we need to emulate the missing instruction if gcc
needs to emit it.  The following patch does this.   If there is a better way
to do this, then let me know.

Thu Apr 30 19:28:16 1998  Jim Wilson  <wilson@cygnus.com>

	* i386.c (output_fix_trunc): Add code to emulate non-popping DImode
	case.

*** i386.c	Sun Feb 15 11:54:11 1998
--- /home/wilson/tmp/i386.c	Thu Apr 30 19:26:54 1998
*************** output_fix_trunc (insn, operands)
*** 3731,3738 ****
    int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
    rtx xops[2];
  
!   if (! STACK_TOP_P (operands[1]) ||
!       (GET_MODE (operands[0]) == DImode && ! stack_top_dies))
      abort ();
  
    xops[0] = GEN_INT (12);
--- 3731,3737 ----
    int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
    rtx xops[2];
  
!   if (! STACK_TOP_P (operands[1]))
      abort ();
  
    xops[0] = GEN_INT (12);
*************** output_fix_trunc (insn, operands)
*** 3750,3755 ****
--- 3749,3765 ----
      {
        if (stack_top_dies)
  	output_asm_insn (AS1 (fistp%z0,%0), operands);
+       else if (GET_MODE (operands[0]) == DImode && ! stack_top_dies)
+ 	{
+ 	  /* There is no DImode version of this without a stack pop, so
+ 	     we must emulate it.  It doesn't matter much what the second
+ 	     instruction is, because the value being pushed on the FP stack
+ 	     is not used except for the following stack popping store.
+ 	     This case can only happen without optimization, so it doesn't
+ 	     matter that it is inefficient.  */
+ 	  output_asm_insn (AS1 (fistp%z0,%0), operands);
+ 	  output_asm_insn (AS1 (fild%z0,%0), operands);
+ 	}
        else
  	output_asm_insn (AS1 (fist%z0,%0), operands);
      }

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: More fp bug in egcs
  1998-04-25 18:25 H.J. Lu
@ 1998-04-27 21:29 ` Jim Wilson
  1998-04-30 20:03 ` Jim Wilson
  1 sibling, 0 replies; 19+ messages in thread
From: Jim Wilson @ 1998-04-27 21:29 UTC (permalink / raw)
  To: H.J. Lu; +Cc: law, scox, crux, egcs

Yes, this is a problem with my patch.  My patch that makes the SF/DF->DI
conversions work with -O makes them fail without -O.  I missed that.
Grr.  I am going to have to take another look at this problem.  I believe
this patch was added to the pre-release 1.0.3, and hence we may have a serious
problem here.  There is only a problem if people compile without optimization
though.

Jim

^ permalink raw reply	[flat|nested] 19+ messages in thread

* More fp bug in egcs
@ 1998-04-25 18:25 H.J. Lu
  1998-04-27 21:29 ` Jim Wilson
  1998-04-30 20:03 ` Jim Wilson
  0 siblings, 2 replies; 19+ messages in thread
From: H.J. Lu @ 1998-04-25 18:25 UTC (permalink / raw)
  To: wilson, law, scox, crux; +Cc: egcs

Hi,

I discovered this x86 fp bug by accident.

# gcc -B/home/work/gnu/bin/egcs/gcc/ -S  mpgeomnn.c
gcc: Internal compiler error: program cc1 got fatal signal 6

It is very similar to the one fixed by Jim. It will compile if -O is
used. I think it may have something to do with Jim's patch. In the
greg rtl dump, the clobbered register is used as input in the next
insn.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---mpgeomnn.c---
typedef struct _geom_elem {
  double        coeffs[6];
  double        constant[3 ];
  int		do_band[3];
} pGeomDefRec, *pGeomDefPtr;
typedef struct _mpgeombanddef {
	double	first_mlow,	 
		first_mhigh;	 
	int	first_ilow,	 
		first_ihigh;	 
	double	*s_locs;	 
	int	*x_locs;	 
	int	x_start;
	int	x_end;
	int	int_constant;	 
	int	yOut;		 
	int	out_width;	 
	int	out_height;	 
	int	in_width;	 
	int	in_height;
	int	lo_src_available;  
	int	hi_src_available;
	void	(*linefunc) ();
	void	(*fillfunc) ();
} mpGeometryBandRec, *mpGeometryBandPtr;
typedef void *pointer;
typedef unsigned char  CARD8;
typedef CARD8 BytePixel;
static void  BiGL_B  (OUTP,srcimg,width,sline,pedpvt,pvtband)	pointer OUTP;	pointer *srcimg;	register int width;	int sline;	pGeomDefPtr pedpvt; mpGeometryBandPtr pvtband;	{	register float s, t, st;	register double a  = pedpvt->coeffs[0];	register double c  = pedpvt->coeffs[2];	register double srcpix  = a * ((double)(0.0000))  +	pedpvt->coeffs[1] * (pvtband->yOut + ((double)(0.0000)) ) +	pedpvt->coeffs[4];	register double srcline = c * ((double)(0.0000))  +	pedpvt->coeffs[3] * (pvtband->yOut + ((double)(0.0000)) ) +	pedpvt->coeffs[5];	register int 	isrcline,isrcpix;	register   BytePixel  constant = (  BytePixel ) pvtband->  int_constant ;	register   BytePixel  *outp	= (  BytePixel  *) OUTP;	register   BytePixel  *ptrIn, *ptrJn;	register   BytePixel  val;	register int 	srcwidth = pvtband->in_width - 1;	register int 	minline  = pvtband->lo_src_available;	register int 	maxline  = pvtband->hi_src_available;	while ( width > 0 ) { isrcline = srcline; isrcpix  = srcpix; val = constant; if ( (isrcline >= minline) && (isrcline < maxline) ) {	s = srcpix - isrcpix;	ptrIn = (  BytePixel  *) srcimg[isrcline]; t = srcline - isrcline;	ptrJn = (  BytePixel  *) srcimg[isrcline+1]; st = s * t;	if ( (isrcpix >= 0) && (isrcpix < srcwidth) )	val =	ptrIn[isrcpix]   * ((float)1. - s - t + st) + ptrIn[isrcpix+1] * (s - st) +	ptrJn[isrcpix]   * (t - st) +	ptrJn[isrcpix+1] * (st) +   (float)0.5 ;	}	width--; srcline += c; srcpix  += a; *outp++ = val; }	} 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~1998-05-08 16:04 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-03  0:55 More fp bug in egcs H.J. Lu
1998-05-03 12:03 ` H.J. Lu
1998-05-03 17:14   ` Jim Wilson
1998-05-04 11:17     ` H.J. Lu
1998-05-04 18:07       ` Jeffrey A Law
1998-05-04 18:07         ` H.J. Lu
1998-05-04 22:00           ` Jeffrey A Law
1998-05-08 16:04           ` Jeffrey A Law
1998-05-03 20:10 ` Jim Wilson
1998-05-05  5:46   ` Jeffrey A Law
  -- strict thread matches above, loose matches on Subject: below --
1998-04-25 18:25 H.J. Lu
1998-04-27 21:29 ` Jim Wilson
1998-04-30 20:03 ` Jim Wilson
1998-05-02 18:56   ` H.J. Lu
1998-05-03 20:10     ` Jim Wilson
1998-05-05  0:35     ` Jeffrey A Law
1998-05-05 19:14       ` H.J. Lu
1998-05-06 11:49         ` Jim Wilson
1998-05-05  5:03   ` Jeffrey A Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).