public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/52838] New: [x32] missed optimization for pointer return value
@ 2012-04-02 23:33 bartoldeman at users dot sourceforge.net
  2012-04-04 19:07 ` [Bug rtl-optimization/52838] " ubizjak at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bartoldeman at users dot sourceforge.net @ 2012-04-02 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52838
           Summary: [x32] missed optimization for pointer return value
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bartoldeman@users.sourceforge.net


The program test.c:

extern void *foo(void);
extern void bar(void*);

void test(void)
{
  bar(foo());
}

when compiled with
gcc-4.7 -mx32 -Os -S test.c
produces:
    .file    "test.c"
    .text
    .globl    test
    .type    test, @function
test:
.LFB0:
    .cfi_startproc
    pushq    %rax
    .cfi_def_cfa_offset 16
    call    foo
    popq    %rdx
    .cfi_def_cfa_offset 8
    movq    %rax, %rdi
    jmp    bar
    .cfi_endproc
.LFE0:
    .size    test, .-test
    .ident    "GCC: (Debian 4.7.0-1) 4.7.0"
    .section    .note.GNU-stack,"",@progbits

Here "movq %rax, %rdi" could be replaced by "movl %eax, %edi", saving one
prefix byte 0x48.


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

* [Bug rtl-optimization/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
@ 2012-04-04 19:07 ` ubizjak at gmail dot com
  2012-04-04 21:41 ` ebotcazou at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2012-04-04 19:07 UTC (permalink / raw)
  To: gcc-bugs

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

Uros Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-04
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org
          Component|target                      |rtl-optimization
     Ever Confirmed|0                           |1

--- Comment #1 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-04 19:06:57 UTC ---
This looks like a combine problem:

(insn 8 6 9 2 (set (reg/f:SI 59 [ D.1705 ])
        (subreg/s/u:SI (reg:DI 60) 0)) pr52838.c:6 64 {*movsi_internal}
     (expr_list:REG_DEAD (reg:DI 60)
        (nil)))

(insn 9 8 10 2 (set (reg/f:DI 62 [ D.1705 ])
        (zero_extend:DI (reg/f:SI 59 [ D.1705 ]))) pr52838.c:6 112
{*zero_extendsidi2_rex64}
     (expr_list:REG_DEAD (reg/f:SI 59 [ D.1705 ])
        (nil)))

This gets transformed by combine pass:


Trying 8 -> 9:
Successfully matched this instruction:
(set (reg/f:DI 62 [ D.1705 ])
    (reg:DI 60))
deferring deletion of insn with uid = 8.
modifying insn i3     9 r62:DI=r60:DI
      REG_DEAD: r60:DI

into:

(note 8 6 9 2 NOTE_INSN_DELETED)

(insn 9 8 10 2 (set (reg/f:DI 62 [ D.1705 ])
        (reg:DI 60)) pr52838.c:6 62 {*movdi_internal_rex64}
     (expr_list:REG_DEAD (reg:DI 60)
        (nil)))

But, but ... high 32 bits are not cleared anymore!

Confirmed as a rtl optimization issue, adding CCs for their opinion.


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

* [Bug rtl-optimization/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
  2012-04-04 19:07 ` [Bug rtl-optimization/52838] " ubizjak at gmail dot com
@ 2012-04-04 21:41 ` ebotcazou at gcc dot gnu.org
  2012-04-05  0:46 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-04-04 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-04-04 21:41:02 UTC ---
> This looks like a combine problem:
> 
> (insn 8 6 9 2 (set (reg/f:SI 59 [ D.1705 ])
>         (subreg/s/u:SI (reg:DI 60) 0)) pr52838.c:6 64 {*movsi_internal}
>      (expr_list:REG_DEAD (reg:DI 60)
>         (nil)))
> 
> (insn 9 8 10 2 (set (reg/f:DI 62 [ D.1705 ])
>         (zero_extend:DI (reg/f:SI 59 [ D.1705 ]))) pr52838.c:6 112
> {*zero_extendsidi2_rex64}
>      (expr_list:REG_DEAD (reg/f:SI 59 [ D.1705 ])
>         (nil)))
> 
> This gets transformed by combine pass:
> 
> 
> Trying 8 -> 9:
> Successfully matched this instruction:
> (set (reg/f:DI 62 [ D.1705 ])
>     (reg:DI 60))
> deferring deletion of insn with uid = 8.
> modifying insn i3     9 r62:DI=r60:DI
>       REG_DEAD: r60:DI
> 
> into:
> 
> (note 8 6 9 2 NOTE_INSN_DELETED)
> 
> (insn 9 8 10 2 (set (reg/f:DI 62 [ D.1705 ])
>         (reg:DI 60)) pr52838.c:6 62 {*movdi_internal_rex64}
>      (expr_list:REG_DEAD (reg:DI 60)
>         (nil)))
> 
> But, but ... high 32 bits are not cleared anymore!

The existence of (subreg/s/u:SI (reg:DI 60) 0) means that (reg:DI 60) is known
to be a zero-extended 32-bit value, so the optimization is valid (and useful).


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

* [Bug rtl-optimization/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
  2012-04-04 19:07 ` [Bug rtl-optimization/52838] " ubizjak at gmail dot com
  2012-04-04 21:41 ` ebotcazou at gcc dot gnu.org
@ 2012-04-05  0:46 ` hjl.tools at gmail dot com
  2012-04-05 12:37 ` ubizjak at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2012-04-05  0:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl.tools at gmail dot com

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2012-04-05 00:46:13 UTC ---
(In reply to comment #2)
> The existence of (subreg/s/u:SI (reg:DI 60) 0) means that (reg:DI 60) is known
> to be a zero-extended 32-bit value, so the optimization is valid (and useful).

Can we somehow keep the knowledge that it is a zero-extended 32-bit value?
It is useful for encoding purpose.


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

* [Bug rtl-optimization/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2012-04-05  0:46 ` hjl.tools at gmail dot com
@ 2012-04-05 12:37 ` ubizjak at gmail dot com
  2012-04-05 16:17 ` ebotcazou at gcc dot gnu.org
  2021-08-30  2:08 ` [Bug target/52838] " pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2012-04-05 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

Uros Bizjak <ubizjak at gmail dot com> changed:

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

--- Comment #4 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-05 12:36:28 UTC ---
(In reply to comment #2)

> The existence of (subreg/s/u:SI (reg:DI 60) 0) means that (reg:DI 60) is known
> to be a zero-extended 32-bit value, so the optimization is valid (and useful).

Please note similar problem with sign_extend, PR 52876.


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

* [Bug rtl-optimization/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2012-04-05 12:37 ` ubizjak at gmail dot com
@ 2012-04-05 16:17 ` ebotcazou at gcc dot gnu.org
  2021-08-30  2:08 ` [Bug target/52838] " pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-04-05 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-04-05 16:16:41 UTC ---
> Can we somehow keep the knowledge that it is a zero-extended 32-bit value?
> It is useful for encoding purpose.

After combine has run, this seems hard.  So the easiest approach might be to
disable the combination by tweaking the costs at -Os.


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

* [Bug target/52838] [x32] missed optimization for pointer return value
  2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
                   ` (4 preceding siblings ...)
  2012-04-05 16:17 ` ebotcazou at gcc dot gnu.org
@ 2021-08-30  2:08 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-30  2:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52838

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|rtl-optimization            |target
             Target|                            |x86_64
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

end of thread, other threads:[~2021-08-30  2:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-02 23:33 [Bug target/52838] New: [x32] missed optimization for pointer return value bartoldeman at users dot sourceforge.net
2012-04-04 19:07 ` [Bug rtl-optimization/52838] " ubizjak at gmail dot com
2012-04-04 21:41 ` ebotcazou at gcc dot gnu.org
2012-04-05  0:46 ` hjl.tools at gmail dot com
2012-04-05 12:37 ` ubizjak at gmail dot com
2012-04-05 16:17 ` ebotcazou at gcc dot gnu.org
2021-08-30  2:08 ` [Bug target/52838] " 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).