public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used
@ 2012-01-30 19:28 jhaberman at gmail dot com
  2012-01-31 11:44 ` [Bug target/52055] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jhaberman at gmail dot com @ 2012-01-30 19:28 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52055
           Summary: load of 64-bit pointer reads 64 bits even when only 32
                    are used
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jhaberman@gmail.com


The following test program:

#include <stdint.h>
uint32_t rd32(uint64_t *i) { return *i; }

Compiles to this (-O3 -fomit-frame-pointer):

0000000000000000 <rd32>:
   0:    48 8b 07                 mov    rax,QWORD PTR [rdi]
   3:    c3                       ret    

But Clang compiles to this, which seems correct, is one byte shorter and
touches less memory:

0000000000000000 <rd32>:
   0:    8b 07                    mov    eax,DWORD PTR [rdi]
   2:    c3                       ret


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
@ 2012-01-31 11:44 ` rguenth at gcc dot gnu.org
  2012-01-31 18:29 ` jhaberman at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-31 11:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-31
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-31 10:56:23 UTC ---
Confirmed.  It's valid to shorten the load for aligned i, it would not be
valid if it were a read from a possibly unaligned memory (it might trap
with 64bit size but not with 32bit).


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
  2012-01-31 11:44 ` [Bug target/52055] " rguenth at gcc dot gnu.org
@ 2012-01-31 18:29 ` jhaberman at gmail dot com
  2012-01-31 19:02 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jhaberman at gmail dot com @ 2012-01-31 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Josh Haberman <jhaberman at gmail dot com> 2012-01-31 17:23:51 UTC ---
Is there any requirement that you trap if the 64-bit read would have trapped?  
Aren't unaligned reads undefined behavior that only happen to work on x86-64?


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
  2012-01-31 11:44 ` [Bug target/52055] " rguenth at gcc dot gnu.org
  2012-01-31 18:29 ` jhaberman at gmail dot com
@ 2012-01-31 19:02 ` jakub at gcc dot gnu.org
  2012-02-01 16:14 ` ebotcazou at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-01-31 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-01-31 18:29:33 UTC ---
Combine can already do this kind of change, as can be seen e.g. on
void foo (unsigned long long *p) { asm volatile ("" : : "rm" ((unsigned) *p));
}
where combine shortens the load into SImode load, but on this testcase we don't
attempt to combine it, because cant_combine_insn_p on the insn with subreg says
we shouldn't combine it (the src is a subreg:SI of the reg:DI initialized by
the DImode memory load, but dest is hard register %eax, which has likely
spilled
register class).
So, shell we do this kind of shortening in fwprop instead?  If a MEM load has
all uses subregged to a narrower mode, try to subreg it and adjust the callers?


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
                   ` (2 preceding siblings ...)
  2012-01-31 19:02 ` jakub at gcc dot gnu.org
@ 2012-02-01 16:14 ` ebotcazou at gcc dot gnu.org
  2012-02-01 16:36 ` jakub at gcc dot gnu.org
  2012-02-14  5:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-02-01 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-02-01 16:13:43 UTC ---
> So, shell we do this kind of shortening in fwprop instead?  If a MEM load has
> all uses subregged to a narrower mode, try to subreg it and adjust the callers?

This would be backward combining (a la REE) though, not forward propagating.


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
                   ` (3 preceding siblings ...)
  2012-02-01 16:14 ` ebotcazou at gcc dot gnu.org
@ 2012-02-01 16:36 ` jakub at gcc dot gnu.org
  2012-02-14  5:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-02-01 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-02-01 16:35:13 UTC ---
That's true, but currently REE is after reload, this combining would be better
done before reload.  Perhaps a separate post-combine pre-ira pass could handle
that and also perhaps PR50176 (if it is somehow possible to insert CC clobbers
to insns that don't have it safely).  The UD/DU links computation REE does is
very expensive I think.


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

* [Bug target/52055] load of 64-bit pointer reads 64 bits even when only 32 are used
  2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
                   ` (4 preceding siblings ...)
  2012-02-01 16:36 ` jakub at gcc dot gnu.org
@ 2012-02-14  5:22 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-14  5:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |enhancement


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

end of thread, other threads:[~2012-02-14  5:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-30 19:28 [Bug target/52055] New: load of 64-bit pointer reads 64 bits even when only 32 are used jhaberman at gmail dot com
2012-01-31 11:44 ` [Bug target/52055] " rguenth at gcc dot gnu.org
2012-01-31 18:29 ` jhaberman at gmail dot com
2012-01-31 19:02 ` jakub at gcc dot gnu.org
2012-02-01 16:14 ` ebotcazou at gcc dot gnu.org
2012-02-01 16:36 ` jakub at gcc dot gnu.org
2012-02-14  5:22 ` pinskia 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).