public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/50217] New: combine pass generated wrong code for unsigned char comparison on MIPS
@ 2012-03-13  6:51 pinskia at gcc dot gnu.org
  2012-03-13  8:28 ` [Bug rtl-optimization/50217] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-03-13  6:51 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50217
           Summary: combine pass generated wrong code for unsigned char
                    comparison on MIPS
    Classification: Unclassified
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yaocang@gmail.com
            Target: mips


Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Target|                            |mips
          Component|c                           |rtl-optimization

I found gcc3.4.4 generate wrong MIPS instructions for the codes following when
using -O1 and -O2. 

int test(unsigned char a, int *b)
{
    if(b==NULL)
       return -1;
    if(a>=0x01 && a<=0xaf)
    {
       *b++;
       return 0;
    }
    else if(a<=0xfe)
       return 1;
    else
       return 3;

    return 4;
}

In assemble codes, (a>=0x01 && a<=0xaf) correspond to "add $8,$8,-1; sltui
$8,$8,-81 " .
According to MIPS instruction manual, "sltui $8,$8,-81 " means the value in $8
will be compared with the constant 0xFFFFFFAF. So when the variable "a" has a
value larger than 0xaf, but "sltui $8,$8,-81 " make the condition  "(a>=0x01 &&
a<=0xaf)" hold, and the program flow go into if-body, and get wrong result.

It seems to me that when simplify_comparison combining tow rtl insn about the
if condition, zero_extend and ltu, the constant was signed-extended.

This problem doesn't occur in 2.96 and 4.3, other versions not tested.


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

* [Bug rtl-optimization/50217] combine pass generated wrong code for unsigned char comparison on MIPS
  2012-03-13  6:51 [Bug rtl-optimization/50217] New: combine pass generated wrong code for unsigned char comparison on MIPS pinskia at gcc dot gnu.org
@ 2012-03-13  8:28 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-03-13  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2012-03-13
      Known to work|                            |4.3.6
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-03-13 08:28:17 UTC ---
GCC 3.4.x is no longer maintained (nor is 4.3.x which works for you).  The
oldest still maintained GCC version is 4.5.3, so please try that.


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

end of thread, other threads:[~2012-03-13  8:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13  6:51 [Bug rtl-optimization/50217] New: combine pass generated wrong code for unsigned char comparison on MIPS pinskia at gcc dot gnu.org
2012-03-13  8:28 ` [Bug rtl-optimization/50217] " rguenth at gcc dot gnu.org

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).