public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/40153]  New: Long long comparison optimized away incorrectly in Thumb code.
@ 2009-05-14 22:00 dougkwan at google dot com
  2009-05-15  7:09 ` [Bug rtl-optimization/40153] " dougkwan at google dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: dougkwan at google dot com @ 2009-05-14 22:00 UTC (permalink / raw)
  To: gcc-bugs

Several versions of gcc (trunk, 4.4.0, 4.3.1 and 4.3.3) mis-compiled this test
case.

----bug.c----
/* compile with -Os -mthumb */
extern void abort (void);

static int llcmp(long long a, long long b);

struct info {
  long unsigned ll;
};

int __attribute__((noinline))
cmp(const void *a, const void *b)
{
  struct info *pa = *((struct info **)a);
  struct info *pb = *((struct info **)b);
  return llcmp(pa->ll, pb->ll);
}

static int
llcmp(long long a, long long b)
{
  if (a < b)
    return -1;
  if (a > b)
    return 1;
  return 0;
}

int
main ()
{
  struct info pa, pb;
  struct info *unsorted[2];

  unsorted[0] = &pa;
  unsorted[1] = &pb;

  pa.ll = 1;
  pb.ll = 2;
  if (cmp (&unsorted[0], &unsorted[1]) != -1)
    abort();

  pa.ll = 2;
  pb.ll = 1;
  if (cmp (&unsorted[0], &unsorted[1]) != 1)
    abort();

  pa.ll = 1;
  pb.ll = 1;
  if (cmp (&unsorted[0], &unsorted[1]) != 0)
    abort();

  return 0;
}
------

sh-3.2$ arm-unknown-linux-gnueabi-gcc -Os -mthumb bug.c
sh-3.2$ /disk2/dougkwan/qemu/install/bin/qemu-arm -L
~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sys-root a.out
qemu: uncaught target signal 6 (Aborted) - exiting
sh-3.2$ arm-unknown-linux-gnueabi-gcc  -mthumb bug.csh-3.2$
/disk2/dougkwan/qemu/install/bin/qemu-arm -L
~/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sys-root a.out
sh-3.2$ 

Below is code generate for the function cmp:
----
        .align  1
        .global cmp
        .code   16
        .thumb_func
        .type   cmp, %function
cmp:
        push    {lr}
        ldr     r3, [r0]
        ldr     r2, [r1]
        ldr     r3, [r3]
        ldr     r2, [r2]
        cmp     r2, r3
        bhi     .L6
        mov     r0, #0
        b       .L2
.L6:
        mov     r0, #1
        neg     r0, r0
.L2:
        @ sp needed for prologue
        pop     {pc}
        .size   cmp, .-cmp
        .align  1

Note that the compiled function only returns 0 and 1 where as the same function
in the source code return values -1, 0 and 1.


-- 
           Summary: Long long comparison optimized away incorrectly in Thumb
                    code.
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dougkwan at google dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: arm-unknown-linux-gnueabi


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


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

* [Bug rtl-optimization/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
@ 2009-05-15  7:09 ` dougkwan at google dot com
  2009-05-15  8:26 ` [Bug target/40153] " ramana at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dougkwan at google dot com @ 2009-05-15  7:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from dougkwan at google dot com  2009-05-15 07:08 -------
This is caused by a typo in arm.md.

(define_insn "cstoresi_nltu_thumb1"
  [(set (match_operand:SI 0 "s_register_operand" "=l,l")
        (neg:SI (gtu:SI (match_operand:SI 1 "s_register_operand" "l,*h")
                        (match_operand:SI 2 "thumb1_cmp_operand" "lI*h,*r"))))]
  "TARGET_THUMB1"
  "cmp\\t%1, %2\;sbc\\t%0, %0, %0"
  [(set_attr "length" "4")]
)

The instruction cstoresi_nltu_thumb1 is used to compute the expression -(x < y)
where x and y are unsigned SI-type values.  The operand of the NEG RTX should
be a LTU RTX instead of a GTU RTX.  The incorrected RTX code caused a later CSE
pass to substitute this pattern:

(set x
    (neg (gtu a b)))   <=== cstoresi_nltu_thumb1
(set y (neg x))        

with

(set y (gtu a b))

I tried fixing the RTX code and the test case passed.


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
  2009-05-15  7:09 ` [Bug rtl-optimization/40153] " dougkwan at google dot com
@ 2009-05-15  8:26 ` ramana at gcc dot gnu dot org
  2009-05-15  8:29 ` dougkwan at google dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-05-15  8:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ramana at gcc dot gnu dot org  2009-05-15 08:26 -------
(In reply to comment #1)
> This is caused by a typo in arm.md.
> 
> (define_insn "cstoresi_nltu_thumb1"
>   [(set (match_operand:SI 0 "s_register_operand" "=l,l")
>         (neg:SI (gtu:SI (match_operand:SI 1 "s_register_operand" "l,*h")
>                         (match_operand:SI 2 "thumb1_cmp_operand" "lI*h,*r"))))]
>   "TARGET_THUMB1"
>   "cmp\\t%1, %2\;sbc\\t%0, %0, %0"
>   [(set_attr "length" "4")]
> )
> 
> The instruction cstoresi_nltu_thumb1 is used to compute the expression -(x < y)
> where x and y are unsigned SI-type values.  The operand of the NEG RTX should
> be a LTU RTX instead of a GTU RTX.  The incorrected RTX code caused a later CSE
> pass to substitute this pattern:
> 
> (set x
>     (neg (gtu a b)))   <=== cstoresi_nltu_thumb1
> (set y (neg x))        
> 
> with
> 
> (set y (gtu a b))
> 
> I tried fixing the RTX code and the test case passed.
> 

This looks correct. Please submit a patch to gcc-patches@.


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-15 08:26:09
               date|                            |


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
  2009-05-15  7:09 ` [Bug rtl-optimization/40153] " dougkwan at google dot com
  2009-05-15  8:26 ` [Bug target/40153] " ramana at gcc dot gnu dot org
@ 2009-05-15  8:29 ` dougkwan at google dot com
  2009-05-16 12:53 ` rearnsha at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dougkwan at google dot com @ 2009-05-15  8:29 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2106 bytes --]



------- Comment #3 from dougkwan at google dot com  2009-05-15 08:28 -------
Subject: Re:  Long long comparison optimized away 
        incorrectly in Thumb code.

I am running regression tests and will submit a patch tomorrow morning
after that.

-Doug

2009/5/15 ramana at gcc dot gnu dot org <gcc-bugzilla@gcc.gnu.org>:
>
>
> ------- Comment #2 from ramana at gcc dot gnu dot org  2009-05-15 08:26 -------
> (In reply to comment #1)
>> This is caused by a typo in arm.md.
>>
>> (define_insn "cstoresi_nltu_thumb1"
>>   [(set (match_operand:SI 0 "s_register_operand" "=l,l")
>>         (neg:SI (gtu:SI (match_operand:SI 1 "s_register_operand" "l,*h")
>>                         (match_operand:SI 2 "thumb1_cmp_operand" "lI*h,*r"))))]
>>   "TARGET_THUMB1"
>>   "cmp\\t%1, %2\;sbc\\t%0, %0, %0"
>>   [(set_attr "length" "4")]
>> )
>>
>> The instruction cstoresi_nltu_thumb1 is used to compute the expression -(x < y)
>> where x and y are unsigned SI-type values.  The operand of the NEG RTX should
>> be a LTU RTX instead of a GTU RTX.  The incorrected RTX code caused a later CSE
>> pass to substitute this pattern:
>>
>> (set x
>>     (neg (gtu a b)))   <=== cstoresi_nltu_thumb1
>> (set y (neg x))
>>
>> with
>>
>> (set y (gtu a b))
>>
>> I tried fixing the RTX code and the test case passed.
>>
>
> This looks correct. Please submit a patch to gcc-patches@.
>
>
> --
>
> ramana at gcc dot gnu dot org changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>             Status|UNCONFIRMED                 |NEW
>     Ever Confirmed|0                           |1
>   Last reconfirmed|0000-00-00 00:00:00         |2009-05-15 08:26:09
>               date|                            |
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40153
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
>


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (2 preceding siblings ...)
  2009-05-15  8:29 ` dougkwan at google dot com
@ 2009-05-16 12:53 ` rearnsha at gcc dot gnu dot org
  2009-05-16 13:28 ` rearnsha at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-16 12:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rearnsha at gcc dot gnu dot org  2009-05-16 12:53 -------
Subject: Bug 40153

Author: rearnsha
Date: Sat May 16 12:53:22 2009
New Revision: 147613

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147613
Log:
        PR target/40153
        * arm.md (cstoresi_nltu_thumb1): Use a neg of ltu as the pattern name
        implies.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.md


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (3 preceding siblings ...)
  2009-05-16 12:53 ` rearnsha at gcc dot gnu dot org
@ 2009-05-16 13:28 ` rearnsha at gcc dot gnu dot org
  2009-05-16 13:49 ` rearnsha at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-16 13:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rearnsha at gcc dot gnu dot org  2009-05-16 13:28 -------
Subject: Bug 40153

Author: rearnsha
Date: Sat May 16 13:28:27 2009
New Revision: 147614

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147614
Log:
        PR target/40153
        * arm.md (cstoresi_nltu_thumb1): Use a neg of ltu as the pattern name
        implies.

Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/config/arm/arm.md


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (4 preceding siblings ...)
  2009-05-16 13:28 ` rearnsha at gcc dot gnu dot org
@ 2009-05-16 13:49 ` rearnsha at gcc dot gnu dot org
  2009-05-16 17:47 ` dougkwan at google dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-16 13:49 UTC (permalink / raw)
  To: gcc-bugs



-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rearnsha at gcc dot gnu dot
                   |                            |org
         AssignedTo|unassigned at gcc dot gnu   |rearnsha at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
           Keywords|                            |wrong-code
   Last reconfirmed|2009-05-15 08:26:09         |2009-05-16 13:49:20
               date|                            |


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (5 preceding siblings ...)
  2009-05-16 13:49 ` rearnsha at gcc dot gnu dot org
@ 2009-05-16 17:47 ` dougkwan at google dot com
  2009-05-16 23:04 ` rearnsha at gcc dot gnu dot org
  2009-05-16 23:06 ` rearnsha at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: dougkwan at google dot com @ 2009-05-16 17:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dougkwan at google dot com  2009-05-16 17:46 -------
Thanks for fixing this.  I also submitted a patch yesterday with the same fix
and a test case also.  The bug is fixed but I think we still want the test
case, right?

(In reply to comment #4)
> Subject: Bug 40153
> 
> Author: rearnsha
> Date: Sat May 16 12:53:22 2009
> New Revision: 147613
> 
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147613
> Log:
>         PR target/40153
>         * arm.md (cstoresi_nltu_thumb1): Use a neg of ltu as the pattern name
>         implies.
> 
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/config/arm/arm.md
> 


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (6 preceding siblings ...)
  2009-05-16 17:47 ` dougkwan at google dot com
@ 2009-05-16 23:04 ` rearnsha at gcc dot gnu dot org
  2009-05-16 23:06 ` rearnsha at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-16 23:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rearnsha at gcc dot gnu dot org  2009-05-16 23:04 -------
Subject: Bug 40153

Author: rearnsha
Date: Sat May 16 23:04:06 2009
New Revision: 147626

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147626
Log:
        PR target/40153
        * arm.md (cstoresi_nltu_thumb1): Use a neg of ltu as the pattern name
        implies.

Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/arm/arm.md


-- 


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


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

* [Bug target/40153] Long long comparison optimized away incorrectly in Thumb code.
  2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
                   ` (7 preceding siblings ...)
  2009-05-16 23:04 ` rearnsha at gcc dot gnu dot org
@ 2009-05-16 23:06 ` rearnsha at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-16 23:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rearnsha at gcc dot gnu dot org  2009-05-16 23:06 -------
(In reply to comment #6)
> Thanks for fixing this.  I also submitted a patch yesterday with the same fix
> and a test case also.  The bug is fixed but I think we still want the test
> case, right?

Sorry, didn't see your patch.  I don't think another test is really necessary,
this fixes so many failures on trunk that I don't see the need for an
additional test.


-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.4


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


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

end of thread, other threads:[~2009-05-16 23:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-14 22:00 [Bug rtl-optimization/40153] New: Long long comparison optimized away incorrectly in Thumb code dougkwan at google dot com
2009-05-15  7:09 ` [Bug rtl-optimization/40153] " dougkwan at google dot com
2009-05-15  8:26 ` [Bug target/40153] " ramana at gcc dot gnu dot org
2009-05-15  8:29 ` dougkwan at google dot com
2009-05-16 12:53 ` rearnsha at gcc dot gnu dot org
2009-05-16 13:28 ` rearnsha at gcc dot gnu dot org
2009-05-16 13:49 ` rearnsha at gcc dot gnu dot org
2009-05-16 17:47 ` dougkwan at google dot com
2009-05-16 23:04 ` rearnsha at gcc dot gnu dot org
2009-05-16 23:06 ` rearnsha at gcc dot gnu dot 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).