public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned.
@ 2023-08-21 10:09 charly.poyac at gmail dot com
  2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: charly.poyac at gmail dot com @ 2023-08-21 10:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111088
           Summary: useless 'xor eax,eax' inserted when a value is not
                    returned.
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: charly.poyac at gmail dot com
  Target Milestone: ---

I compile this simple C code with GCC 13.2:

int foo(int *a)
{
    *a += 1;
}

int foo2(int *a)
{
    *a += 1;
} 

and it produces the following assembly code with '-O3':

foo:
        add     DWORD PTR [rdi], 1
        ret
foo2:
        add     DWORD PTR [rdi], 1
        xor     eax, eax
        ret

see godbolt: https://godbolt.org/z/eeT63ePcr

We can see the inconsistency between the two functions with the 'xor eax,eax'
added in foo2. This does not happen if I compile with -O1.

Yes, these functions should return an integer, but they don't. However, this is
allowed by the C standard (2018 6.9.1 11/12).

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

* [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
@ 2023-08-21 13:59 ` pinskia at gcc dot gnu.org
  2023-08-21 16:23 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is ICF coming into play and then inlining.

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

* [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
  2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
@ 2023-08-21 16:23 ` pinskia at gcc dot gnu.org
  2023-08-21 16:27   ` Jan Hubicka
  2023-08-21 16:27 ` [Bug ipa/111088] " hubicka at ucw dot cz
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-08-21
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So ICF figures out foo and foo2 are the same and has foo2 tail calls foo:

  <bb 2> [local count: 1073741824]:
  retval.2_4 = foo (a_2(D)); [tail call]
  return retval.2_4;

But adds a return with a value. And then the inliner inlines foo into foo2 but
we still have the return with a value around ...

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

* Re: [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 16:23 ` pinskia at gcc dot gnu.org
@ 2023-08-21 16:27   ` Jan Hubicka
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Hubicka @ 2023-08-21 16:27 UTC (permalink / raw)
  To: pinskia at gcc dot gnu.org, mjambor; +Cc: gcc-bugs

> But adds a return with a value. And then the inliner inlines foo into foo2 but
> we still have the return with a value around ...
I guess ICF can special case unused return value, but why this is not
taken care of by ipa-sra?

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

* [Bug ipa/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
  2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
  2023-08-21 16:23 ` pinskia at gcc dot gnu.org
@ 2023-08-21 16:27 ` hubicka at ucw dot cz
  2023-08-22  6:49 ` rguenth at gcc dot gnu.org
  2023-08-23 12:29 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: hubicka at ucw dot cz @ 2023-08-21 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jan Hubicka <hubicka at ucw dot cz> ---
> But adds a return with a value. And then the inliner inlines foo into foo2 but
> we still have the return with a value around ...
I guess ICF can special case unused return value, but why this is not
taken care of by ipa-sra?

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

* [Bug ipa/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
                   ` (2 preceding siblings ...)
  2023-08-21 16:27 ` [Bug ipa/111088] " hubicka at ucw dot cz
@ 2023-08-22  6:49 ` rguenth at gcc dot gnu.org
  2023-08-23 12:29 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-22  6:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
In C++ this would have been undefined - I don't think this particular testcase
is worth "optimizing".

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

* [Bug ipa/111088] useless 'xor eax,eax' inserted when a value is not returned and icf
  2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
                   ` (3 preceding siblings ...)
  2023-08-22  6:49 ` rguenth at gcc dot gnu.org
@ 2023-08-23 12:29 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: jamborm at gcc dot gnu.org @ 2023-08-23 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

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

--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #3)
> > But adds a return with a value. And then the inliner inlines foo into foo2 but
> > we still have the return with a value around ...
> I guess ICF can special case unused return value, but why this is not
> taken care of by ipa-sra?

Probably because none of the functions is static.

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

end of thread, other threads:[~2023-08-23 12:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
2023-08-21 16:23 ` pinskia at gcc dot gnu.org
2023-08-21 16:27   ` Jan Hubicka
2023-08-21 16:27 ` [Bug ipa/111088] " hubicka at ucw dot cz
2023-08-22  6:49 ` rguenth at gcc dot gnu.org
2023-08-23 12:29 ` jamborm 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).