public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/40057]  New: Incorrect right shift by 31 with long long
@ 2009-05-07 10:49 rahul at icerasemi dot com
  2009-05-07 11:11 ` [Bug tree-optimization/40057] " rahul at icerasemi dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: rahul at icerasemi dot com @ 2009-05-07 10:49 UTC (permalink / raw)
  To: gcc-bugs

The following code compiled with GCC 4.4 and -O1 produces a wrong result for
the SHIFT and AND operation. Bit 31 of the variable 'var' in fucntion shiftTest
computes to '1' instead of a '0'.

Compiling with -O0 however, produces the right result.


#include "stdio.h"

typedef unsigned long long ulonglong;

int shiftTest (const ulonglong var)
{
  ulonglong predicate = (var >> 31ULL) & 1ULL;

  if (predicate == 0ULL)
    {
      return 0;
    }
  return -1;
}


int main (void)
{
  ulonglong var = 0x1682a9aaaULL;

  printf ("Bit 31 of 0x%llx is %llu\n", var, (var >> 31ULL) & 1ULL);

  int result = shiftTest (var);

  if (result == 0)
    {
      printf ("Bit 31 is 0 - Correct!\n");
    }
  else
    {
      printf ("Bit 31 is 1 - Incorrect!\n");
    }
  return 0;
}


-- 
           Summary: Incorrect right shift by 31 with long long
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rahul at icerasemi dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug tree-optimization/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
@ 2009-05-07 11:11 ` rahul at icerasemi dot com
  2009-05-07 11:19 ` rguenth at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rahul at icerasemi dot com @ 2009-05-07 11:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rahul at icerasemi dot com  2009-05-07 11:11 -------
Suspect tree-ter optimisation pass. Compiling with -O1 -fno-tree-ter produces
the right result. Using -fdump-tree-optimized shows SSA-Gimple to change from

shiftTest (const ulonglong var)
{
  int D.1842;

<bb 2>:
  if (var >> 31 & 1 == 0)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 5>:
  D.1842 = -1;
  goto <bb 4>;

<bb 3>:
  D.1842 = 0;

<bb 4>:
  return D.1842;

}

to

shiftTest (const ulonglong var)
{
  ulonglong predicate;
  int D.1842;
  const ulonglong D.1839;

<bb 2>:
  D.1839 = var >> 31;
  predicate = D.1839 & 1;
  if (predicate == 0)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 5>:
  D.1842 = -1;
  goto <bb 4>;

<bb 3>:
  D.1842 = 0;

<bb 4>:
  return D.1842;

}

Does the complex expression "var >> 31 & 1 == 0" cause problems during RTL
expansion phase?
Are the precedences of the SHIFT and AND operations maintained by the
expression replacement phase?


-- 


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


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

* [Bug tree-optimization/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
  2009-05-07 11:11 ` [Bug tree-optimization/40057] " rahul at icerasemi dot com
@ 2009-05-07 11:19 ` rguenth at gcc dot gnu dot org
  2009-05-07 11:30 ` jakub at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-07 11:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-05-07 11:19 -------
Works for me.


-- 


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


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

* [Bug tree-optimization/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
  2009-05-07 11:11 ` [Bug tree-optimization/40057] " rahul at icerasemi dot com
  2009-05-07 11:19 ` rguenth at gcc dot gnu dot org
@ 2009-05-07 11:30 ` jakub at gcc dot gnu dot org
  2009-05-07 11:34 ` jakub at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 11:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2009-05-07 11:29 -------
Can't reproduce with x86_64-linux 4.4.0 with -m32, perhaps a 32-bit HWI issue,
will check...


-- 


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


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

* [Bug tree-optimization/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (2 preceding siblings ...)
  2009-05-07 11:30 ` jakub at gcc dot gnu dot org
@ 2009-05-07 11:34 ` jakub at gcc dot gnu dot org
  2009-05-07 11:36 ` jakub at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 11:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jakub at gcc dot gnu dot org  2009-05-07 11:33 -------
Indeed, I can reproduce with 32-bit HWI 20090414 4.4 branch, building now head
of 4.4 branch with 32-bit HWI.


-- 


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


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

* [Bug tree-optimization/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (3 preceding siblings ...)
  2009-05-07 11:34 ` jakub at gcc dot gnu dot org
@ 2009-05-07 11:36 ` jakub at gcc dot gnu dot org
  2009-05-07 13:02 ` [Bug middle-end/40057] " jakub at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 11:36 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-07 11:36:16
               date|                            |


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (4 preceding siblings ...)
  2009-05-07 11:36 ` jakub at gcc dot gnu dot org
@ 2009-05-07 13:02 ` jakub at gcc dot gnu dot org
  2009-05-07 13:20 ` jakub at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 13:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2009-05-07 13:02 -------
A bug in do_jump and prefer_and_bit_test.  Testing a fix.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (5 preceding siblings ...)
  2009-05-07 13:02 ` [Bug middle-end/40057] " jakub at gcc dot gnu dot org
@ 2009-05-07 13:20 ` jakub at gcc dot gnu dot org
  2009-05-07 15:28 ` jakub at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 13:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2009-05-07 13:19 -------
Created an attachment (id=17818)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17818&action=view)
gcc44-pr40057.patch

Fix I'm going to bootstrap/regtest.


-- 


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (6 preceding siblings ...)
  2009-05-07 13:20 ` jakub at gcc dot gnu dot org
@ 2009-05-07 15:28 ` jakub at gcc dot gnu dot org
  2009-05-07 15:37 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 15:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jakub at gcc dot gnu dot org  2009-05-07 15:28 -------
Subject: Bug 40057

Author: jakub
Date: Thu May  7 15:27:40 2009
New Revision: 147241

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147241
Log:
        PR middle-end/40057
        * dojump.c (prefer_and_bit_test): Use immed_double_const instead of
        GEN_INT for 1 << bitnum.
        (do_jump) <case BIT_AND_EXPR>: Use build_int_cst_wide_type instead of
        build_int_cst_type.

        * gcc.c-torture/execute/pr40057.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr40057.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dojump.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (7 preceding siblings ...)
  2009-05-07 15:28 ` jakub at gcc dot gnu dot org
@ 2009-05-07 15:37 ` jakub at gcc dot gnu dot org
  2009-05-07 15:53 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 15:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jakub at gcc dot gnu dot org  2009-05-07 15:36 -------
Subject: Bug 40057

Author: jakub
Date: Thu May  7 15:36:23 2009
New Revision: 147242

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147242
Log:
        PR middle-end/40057
        * dojump.c (prefer_and_bit_test): Use immed_double_const instead of
        GEN_INT for 1 << bitnum.
        (do_jump) <case BIT_AND_EXPR>: Use build_int_cst_wide_type instead of
        build_int_cst_type.

        * gcc.c-torture/execute/pr40057.c: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr40057.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/dojump.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (8 preceding siblings ...)
  2009-05-07 15:37 ` jakub at gcc dot gnu dot org
@ 2009-05-07 15:53 ` jakub at gcc dot gnu dot org
  2009-05-07 15:55 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 15:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jakub at gcc dot gnu dot org  2009-05-07 15:53 -------
Subject: Bug 40057

Author: jakub
Date: Thu May  7 15:53:11 2009
New Revision: 147245

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147245
Log:
        PR middle-end/40057
        * dojump.c (prefer_and_bit_test): Use immed_double_const instead of
        GEN_INT for 1 << bitnum.
        (do_jump) <case BIT_AND_EXPR>: Use build_int_cst_wide_type instead of
        build_int_cst_type.

        * gcc.c-torture/execute/pr40057.c: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr40057.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/dojump.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (9 preceding siblings ...)
  2009-05-07 15:53 ` jakub at gcc dot gnu dot org
@ 2009-05-07 15:55 ` jakub at gcc dot gnu dot org
  2009-05-07 15:57 ` rahul at icerasemi dot com
  2009-05-28 11:12 ` jakub at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-07 15:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jakub at gcc dot gnu dot org  2009-05-07 15:55 -------
Fixed.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (10 preceding siblings ...)
  2009-05-07 15:55 ` jakub at gcc dot gnu dot org
@ 2009-05-07 15:57 ` rahul at icerasemi dot com
  2009-05-28 11:12 ` jakub at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: rahul at icerasemi dot com @ 2009-05-07 15:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rahul at icerasemi dot com  2009-05-07 15:57 -------
Confirmed issue resolved.


-- 


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


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

* [Bug middle-end/40057] Incorrect right shift by 31 with long long
  2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
                   ` (11 preceding siblings ...)
  2009-05-07 15:57 ` rahul at icerasemi dot com
@ 2009-05-28 11:12 ` jakub at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-28 11:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from jakub at gcc dot gnu dot org  2009-05-28 11:12 -------
*** Bug 40279 has been marked as a duplicate of this bug. ***


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jisooy at gmail dot com


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


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

end of thread, other threads:[~2009-05-28 11:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-07 10:49 [Bug tree-optimization/40057] New: Incorrect right shift by 31 with long long rahul at icerasemi dot com
2009-05-07 11:11 ` [Bug tree-optimization/40057] " rahul at icerasemi dot com
2009-05-07 11:19 ` rguenth at gcc dot gnu dot org
2009-05-07 11:30 ` jakub at gcc dot gnu dot org
2009-05-07 11:34 ` jakub at gcc dot gnu dot org
2009-05-07 11:36 ` jakub at gcc dot gnu dot org
2009-05-07 13:02 ` [Bug middle-end/40057] " jakub at gcc dot gnu dot org
2009-05-07 13:20 ` jakub at gcc dot gnu dot org
2009-05-07 15:28 ` jakub at gcc dot gnu dot org
2009-05-07 15:37 ` jakub at gcc dot gnu dot org
2009-05-07 15:53 ` jakub at gcc dot gnu dot org
2009-05-07 15:55 ` jakub at gcc dot gnu dot org
2009-05-07 15:57 ` rahul at icerasemi dot com
2009-05-28 11:12 ` jakub 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).