public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aldot at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/110052] useless local variable not optimized away
Date: Wed, 31 May 2023 18:24:27 +0000	[thread overview]
Message-ID: <bug-110052-4-6rWpIyRFN6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110052-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Bernhard Reutner-Fischer <aldot at gcc dot gnu.org> ---
(In reply to Bernhard Reutner-Fischer from comment #3)
> Note that in this particular case myrealloc() is static, maybe i should have
> omitted the noipa attribute for it was only meant to simplify analysis and
> there is no such attribute in the original code.
> Furthermore, i would have hoped that given the placement of the definition
> of myrealloc() before the typedef foo_t, it should be unlikely that the
> usage of *foo would invalidate such an optimisation _in this particular
> case_. While the original code unfortunately does not mark *foo as restrict,
> adding restrict would hopefully make it clear that myrealloc() has no
> business in comparing foo's struct members, i'd hope?
> 
> When i drop the noipa attribute in the v1 testcase to make it similar to the
> motivating case, i get:

Correction: When i replace noipa with noinline,noclone (and drop
-ffunction-sections -fdata-sections to improve readability), i get:
    10: 0000000000000030    52 FUNC    GLOBAL DEFAULT    1 bloat
    10: 0000000000000030    21 FUNC    GLOBAL DEFAULT    1 ok

0000000000000030 <bloat>:
  30:   53                      push   %rbx
  31:   48 89 fb                mov    %rdi,%rbx
  34:   48 83 ec 10             sub    $0x10,%rsp
  38:   8b 47 14                mov    0x14(%rdi),%eax
  3b:   48 83 7f 08 00          cmpq   $0x0,0x8(%rdi)
  40:   89 44 24 0c             mov    %eax,0xc(%rsp)
  44:   75 11                   jne    57 <bloat+0x27>
  46:   48 8d 54 24 0c          lea    0xc(%rsp),%rdx
  4b:   be 00 01 00 00          mov    $0x100,%esi
  50:   31 ff                   xor    %edi,%edi
  52:   e8 a9 ff ff ff          callq  0 <myrealloc>
  57:   8b 44 24 0c             mov    0xc(%rsp),%eax
  5b:   89 43 14                mov    %eax,0x14(%rbx)
  5e:   48 83 c4 10             add    $0x10,%rsp
  62:   5b                      pop    %rbx
  63:   c3                      retq   

0000000000000030 <ok>:
  30:   48 83 7f 08 00          cmpq   $0x0,0x8(%rdi)
  35:   75 0d                   jne    44 <ok+0x14>
  37:   48 8d 57 14             lea    0x14(%rdi),%rdx
  3b:   be 00 01 00 00          mov    $0x100,%esi
  40:   31 ff                   xor    %edi,%edi
  42:   eb bc                   jmp    0 <myrealloc>
  44:   c3                      retq

  parent reply	other threads:[~2023-05-31 18:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  8:06 [Bug middle-end/110052] New: " aldot at gcc dot gnu.org
2023-05-31  8:31 ` [Bug middle-end/110052] " amonakov at gcc dot gnu.org
2023-05-31  8:51 ` rguenth at gcc dot gnu.org
2023-05-31 18:12 ` aldot at gcc dot gnu.org
2023-05-31 18:24 ` aldot at gcc dot gnu.org [this message]
2023-06-01 12:48 ` amonakov at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110052-4-6rWpIyRFN6@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).