This is the mail archive of the gcc-bugs@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]

[Bug target/12654] [3.3/3.4 regression] Incorrect comparison code generated for Alpha


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12654



------- Additional Comments From falk dot hueffner at student dot uni-tuebingen dot de  2003-10-18 14:58 -------
Subject: Re:  [3.3/3.4 regression] Incorrect comparison code generated for Alpha

"tg at swox dot com" <gcc-bugzilla@gcc.gnu.org> writes:

> For (a != IMMEDIATE) and (a == IMMEDIATE) when IMMEDIATE doesn't fit
> in a cmpeq but does fit into an lda, we want to generate
> 
>         lda     tmp,-IMMEDIATE(a)
>         bne/beq ...
> 
> instead of
> 
>         lda     tmp, IMMEDIATE(r31)
>         cmpeq   a, tmp
>         beq/bne

Okay, I can see that.

> I don't understand what you mean with "bypass" in this context.

The comment in that passage was refering to the EV5 ICMP/ILOG bypass.
Seems the comment is wrong or misleading, but the optimization is
still useful.

>   Also, your patch skips the "Compare and branch against 0 directly"
>   for unsigned compares; since it doesn't seem to have any effect on
>   the generated code, it should probably be removed altogether.
> 
> I don't understand.
> 
> What do you mean by "Compare and branch against 0 directly"?

Uhm, I meant signed. These code lines:

	  /* Whee.  Compare and branch against 0 directly.  */
	  if (op1 == const0_rtx)
	    cmp_code = NIL, branch_code = code;

Previously, they were executed also with eg. LE. It doesn't change the
generated code, though, because this is optimized away somewhere else.

How about this patch, which does the same as yours but seems clearer:

Index: alpha.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/alpha/alpha.c,v
retrieving revision 1.332
diff -u -p -c -r1.332 alpha.c
*** alpha.c	11 Oct 2003 16:54:16 -0000	1.332
--- alpha.c	18 Oct 2003 14:52:58 -0000
*************** alpha_emit_conditional_branch (enum rtx_
*** 3150,3176 ****
      {
        cmp_mode = DImode;
  
!       /* The following optimizations are only for signed compares.  */
!       if (code != LEU && code != LTU && code != GEU && code != GTU)
  	{
! 	  /* Whee.  Compare and branch against 0 directly.  */
! 	  if (op1 == const0_rtx)
! 	    cmp_code = NIL, branch_code = code;
  
! 	  /* We want to use cmpcc/bcc when we can, since there is a zero delay
! 	     bypass between logicals and br/cmov on EV5.  But we don't want to
! 	     force valid immediate constants into registers needlessly.  */
! 	  else if (GET_CODE (op1) == CONST_INT)
  	    {
! 	      HOST_WIDE_INT v = INTVAL (op1), n = -v;
! 
! 	      if (! CONST_OK_FOR_LETTER_P (v, 'I')
! 		  && (CONST_OK_FOR_LETTER_P (n, 'K')
! 		      || CONST_OK_FOR_LETTER_P (n, 'L')))
! 		{
! 		  cmp_code = PLUS, branch_code = code;
! 		  op1 = GEN_INT (n);
! 		}
  	    }
  	}
  
--- 3150,3168 ----
      {
        cmp_mode = DImode;
  
!       if ((code == EQ || code == NE) && GET_CODE (op1) == CONST_INT)
  	{
! 	  /* If the constants doesn't fit into an immediate, but can be
! 	     generated by lda/ldah, we adjust the argument and compare
! 	     against zero, so we can use beq/bne directly.  */
! 	  HOST_WIDE_INT v = INTVAL (op1), n = -v;
  
! 	  if (! CONST_OK_FOR_LETTER_P (v, 'I')
! 	      && (CONST_OK_FOR_LETTER_P (n, 'K')
! 		  || CONST_OK_FOR_LETTER_P (n, 'L')))
  	    {
! 	      cmp_code = PLUS, branch_code = code;
! 	      op1 = GEN_INT (n);
  	    }
  	}


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