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] h8300.md: Add more test insns.


Hi Kazu,

Yes, the patch fixes the problem. Thanks.

- Dhananjay

> -----Original Message-----
> From: Kazu Hirata [mailto:kazu@cs.umass.edu]
> Sent: Thursday, January 16, 2003 10:00 PM
> To: Dhananjay R. Deshpande
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [patch] h8300.md: Add more test insns.
> 
> 
> Hi Dhananjay,
> 
> > Following code if compiled with h8300-coff-gcc -S -O2 generates
> > incorrect code
> 
> Thanks for reporting this.  Upon investigation, I found that the bit
> extraction also has the problem.  Here is a testcase.
> 
> unsigned short
> test1 (unsigned short w)
> {
>   if ((w & 0xff00) == 0)
>     {
>       if (w == 0)
> 	w = 2;
>     }
>   return w;
> }
> 
> unsigned long
> test2 (unsigned long w)
> {
>   if ((w & 0xffff0000) == 0)
>     {
>       if (w == 0)
> 	w = 2;
>     }
>   return w;
> }
> 
> int
> test3 (unsigned short a)
> {
>   if (a & 1)
>     return 1;
>   else if (a)
>     return 1;
>   else
>     return 0;
> }
> 
> int
> main ()
> {
>   if (test1 (1) != 1)
>     abort ();
> 
>   if (test2 (1) != 1)
>     abort ();
> 
>   if (test3 (2) != 1)
>     abort ();
> 
>   exit (0);
> }
> 
> The problem is that operands[0] is not necessarily what the value of
> cc0 corresponds to.  Does the attached patch fix the problem?
> Meanwhile, I will run the testsuite with the patch and the new
> testcase.
> 
> Kazu Hirata
> 
> Index: h8300.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.c,v
> retrieving revision 1.201
> diff -u -r1.201 h8300.c
> --- h8300.c	8 Jan 2003 14:02:51 -0000	1.201
> +++ h8300.c	16 Jan 2003 16:19:16 -0000
> @@ -1710,6 +1710,8 @@
>       rtx body;
>       rtx insn;
>  {
> +  rtx set;
> +
>    switch (get_attr_cc (insn))
>      {
>      case CC_NONE:
> @@ -1732,7 +1734,10 @@
>  	 that's ok because alter_cond will change tests to use 
> EQ/NE.  */
>        CC_STATUS_INIT;
>        cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
> -      cc_status.value1 = recog_data.operand[0];
> +      set = single_set (insn);
> +      cc_status.value1 = SET_SRC (set);
> +      if (SET_DEST (set) != cc0_rtx)
> +	cc_status.value2 = SET_DEST (set);
>        break;
>  
>      case CC_SET_ZNV:
> @@ -1741,9 +1746,10 @@
>  	 alter_cond will change tests to use EQ/NE.  */
>        CC_STATUS_INIT;
>        cc_status.flags |= CC_NO_CARRY;
> -      cc_status.value1 = recog_data.operand[0];
> -      if (GET_CODE (body) == SET && REG_P (SET_SRC (body)))
> -	cc_status.value2 = SET_SRC (body);
> +      set = single_set (insn);
> +      cc_status.value1 = SET_SRC (set);
> +      if (SET_DEST (set) != cc0_rtx)
> +	cc_status.value2 = SET_DEST (set);
>        break;
>  
>      case CC_COMPARE:
> 


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