public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode
@ 2011-06-22 17:01 hjl.tools at gmail dot com
  2011-06-22 18:12 ` [Bug middle-end/49504] " hjl.tools at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2011-06-22 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Invalid optimization for Pmode != ptr_mode
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hjl.tools@gmail.com


On x32 branch, I got

[hjl@gnu-33 tmp]$ cat x32.c
unsigned long long t(const void* p, unsigned long long q) {
  unsigned long long a = (((unsigned long long) ((unsigned long) p)) + q) >>
32;
  return a;
}
[hjl@gnu-33 tmp]$ /usr/gcc-4.7.0-x32/bin/gcc -O2 -mx32 -S x32.c
[hjl@gnu-33 tmp]$ cat x32.s
    .file    "x32.c"
    .text
    .p2align 4,,15
    .globl    t
    .type    t, @function
t:
.LFB0:
    .cfi_startproc
    xorl    %eax, %eax
    ret
    .cfi_endproc
.LFE0:
    .size    t, .-t
    .ident    "GCC: (GNU) 4.7.0 20110616 (experimental)"
    .section    .note.GNU-stack,"",@progbits
[hjl@gnu-33 tmp]$ 

From

http://code.google.com/p/nativeclient/issues/detail?id=1601

What it does is that when pointers from memory (ptr_mode) are zero extended
when getting into registers (Pmode)(POINTERS_EXTEND_UNSIGNED > 0), and there is
a Pmode PLUS or MINUS of a register that holds a pointer value with some other
register, all bits above ptr_mode are considered zero.

Here is the test that demonstrates the bug clearly (compile with -O2):

  unsigned long long t(const void* p, unsigned long long q) {
    unsigned long long a = (((unsigned long long)p) + q) >> 32;
    return a;
  }

In our z86_64 compiler, p is 32-bit. It gets zero-extended to 64-bit long long
for addition with q, but the fact that it was originally a pointer is
preserved. Thus, nonzero_bits1 thinks the result of addition always has high
32-bits equal to zero, so the result of the right shift is always zero.

The test gets optimized to "return 0;".


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

* [Bug middle-end/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
@ 2011-06-22 18:12 ` hjl.tools at gmail dot com
  2011-06-22 19:44 ` [Bug rtl-optimization/49504] " hjl.tools at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2011-06-22 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 2011-06-22 18:11:33 UTC ---
Another combine bug.


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
  2011-06-22 18:12 ` [Bug middle-end/49504] " hjl.tools at gmail dot com
@ 2011-06-22 19:44 ` hjl.tools at gmail dot com
  2011-06-22 20:00 ` hjl at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2011-06-22 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-p
                   |                            |atches/2011-06/msg01704.htm
                   |                            |l
          Component|middle-end                  |rtl-optimization

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> 2011-06-22 19:44:09 UTC ---
The patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2011-06/msg01704.html


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
  2011-06-22 18:12 ` [Bug middle-end/49504] " hjl.tools at gmail dot com
  2011-06-22 19:44 ` [Bug rtl-optimization/49504] " hjl.tools at gmail dot com
@ 2011-06-22 20:00 ` hjl at gcc dot gnu.org
  2011-06-23 14:53 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl at gcc dot gnu.org @ 2011-06-22 20:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2011-06-22 19:59:59 UTC ---
Author: hjl
Date: Wed Jun 22 19:59:52 2011
New Revision: 175306

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175306
Log:
Properly handle pointer addition/subtraction.

gcc/

2011-06-22  H.J. Lu  <hongjiu.lu@intel.com>

    PR rtl-optimization/49504
    * rtlanal.c (nonzero_bits1): Properly handle addition or
    subtraction a pointer in Pmode if pointers extend unsigned.

gcc/testsuite/

2011-06-22  H.J. Lu  <hongjiu.lu@intel.com>

    PR rtl-optimization/49504
    * gcc.target/i386/pr49504.c: New.

Added:
    branches/x32/gcc/testsuite/gcc.target/i386/pr49504.c
Modified:
    branches/x32/gcc/ChangeLog.x32
    branches/x32/gcc/rtlanal.c
    branches/x32/gcc/testsuite/ChangeLog.x32


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2011-06-22 20:00 ` hjl at gcc dot gnu.org
@ 2011-06-23 14:53 ` hjl.tools at gmail dot com
  2011-06-24 13:42 ` hjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2011-06-23 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> 2011-06-23 14:52:40 UTC ---
*** Bug 49088 has been marked as a duplicate of this bug. ***


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2011-06-23 14:53 ` hjl.tools at gmail dot com
@ 2011-06-24 13:42 ` hjl at gcc dot gnu.org
  2011-06-24 15:40 ` hjl.tools at gmail dot com
  2011-08-06 14:06 ` hjl at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: hjl at gcc dot gnu.org @ 2011-06-24 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2011-06-24 13:41:44 UTC ---
Author: hjl
Date: Fri Jun 24 13:41:40 2011
New Revision: 175377

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175377
Log:
Properly handle pointer addition/subtraction.

2011-06-24  H.J. Lu  <hongjiu.lu@intel.com>

    PR rtl-optimization/49504
    * rtlanal.c (nonzero_bits1): Properly handle addition or
    subtraction a pointer in Pmode if pointers extend unsigned.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/rtlanal.c


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2011-06-24 13:42 ` hjl at gcc dot gnu.org
@ 2011-06-24 15:40 ` hjl.tools at gmail dot com
  2011-08-06 14:06 ` hjl at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: hjl.tools at gmail dot com @ 2011-06-24 15:40 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.7.0

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> 2011-06-24 15:40:08 UTC ---
Fixed.


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

* [Bug rtl-optimization/49504] Invalid optimization for Pmode != ptr_mode
  2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2011-06-24 15:40 ` hjl.tools at gmail dot com
@ 2011-08-06 14:06 ` hjl at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: hjl at gcc dot gnu.org @ 2011-08-06 14:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2011-08-06 14:05:43 UTC ---
Author: hjl
Date: Sat Aug  6 14:05:39 2011
New Revision: 177509

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=177509
Log:
Add testcases for PRs 48084/49504/49860.

2011-08-06  H.J. Lu  <hongjiu.lu@intel.com>

    PR target/48084
    * gcc.target/i386/pr48084-1.c: New.
    * gcc.target/i386/pr48084-2.c: Likewise.
    * gcc.target/i386/pr48084-3.c: Likewise.
    * gcc.target/i386/pr48084-4.c: Likewise.
    * gcc.target/i386/pr48084-5.c: Likewise.

    PR rtl-optimization/49504
    * gcc.target/i386/pr49504.c: New.

    PR target/49860
    * gcc.dg/pr49860.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/pr49860.c
    trunk/gcc/testsuite/gcc.target/i386/pr48084-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr48084-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr48084-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr48084-4.c
    trunk/gcc/testsuite/gcc.target/i386/pr48084-5.c
    trunk/gcc/testsuite/gcc.target/i386/pr49504.c
Modified:
    trunk/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2011-08-06 14:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-22 17:01 [Bug middle-end/49504] New: Invalid optimization for Pmode != ptr_mode hjl.tools at gmail dot com
2011-06-22 18:12 ` [Bug middle-end/49504] " hjl.tools at gmail dot com
2011-06-22 19:44 ` [Bug rtl-optimization/49504] " hjl.tools at gmail dot com
2011-06-22 20:00 ` hjl at gcc dot gnu.org
2011-06-23 14:53 ` hjl.tools at gmail dot com
2011-06-24 13:42 ` hjl at gcc dot gnu.org
2011-06-24 15:40 ` hjl.tools at gmail dot com
2011-08-06 14:06 ` hjl 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).