public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/109791] -Wstringop-overflow warning with -O3 and _GLIBCXX_USE_CXX11_ABI=0
Date: Wed, 10 May 2023 07:26:56 +0000	[thread overview]
Message-ID: <bug-109791-4-6aIEpxprwx@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109791-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |amacleod at redhat dot com,
                   |                            |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-05-10

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  This is a missed optimization, we fail to optimize the loop guard

<bb 16> [local count: 329643239]:
_4 = (unsigned long) &MEM <char[3]> [(void *)&str + 2B];
_6 = (unsigned long) __i_14;
_50 = -_6;
_100 = _4 + 18446744073709551615;
_40 = _100 - _6;
_41 = _40 > 13;
if (_41 != 0)

with __i_14 being

<bb 11> [local count: 452186132]:
# __i_14 = PHI <&MEM <char[3]> [(void *)&str + 1B](10), &MEM <char[3]> [(void
*)&str + 2B](9)>

I'll note that the strlen pass runs before VRP (but after DOM), but I'll
also note that likely ranger isn't very good with these kind of
"symbolic" ranges?  How would we handle this?  Using two
relations, __i_14 >= &str + 1 && __i_14 <= &str + 2?

DOM has

Optimizing block #16

1>>> STMT 1 = &MEM <char[3]> [(void *)&str + 2B] ge_expr __i_14
1>>> STMT 1 = &MEM <char[3]> [(void *)&str + 2B] ne_expr __i_14
1>>> STMT 0 = &MEM <char[3]> [(void *)&str + 2B] eq_expr __i_14
1>>> STMT 1 = &MEM <char[3]> [(void *)&str + 2B] gt_expr __i_14
1>>> STMT 0 = &MEM <char[3]> [(void *)&str + 2B] le_expr __i_14
Optimizing statement _4 = (unsigned long) &MEM <char[3]> [(void *)&str + 2B];
LKUP STMT _4 = nop_expr &MEM <char[3]> [(void *)&str + 2B]
2>>> STMT _4 = nop_expr &MEM <char[3]> [(void *)&str + 2B]
Optimizing statement _6 = (unsigned long) __i_14;
LKUP STMT _6 = nop_expr __i_14
2>>> STMT _6 = nop_expr __i_14
Optimizing statement _50 = -_6;
 Registering value_relation (_6 pe64 __i_14) (bb16) at _6 = (unsigned long)
__i_14;
LKUP STMT _50 = negate_expr _6
2>>> STMT _50 = negate_expr _6
Optimizing statement _100 = _4 + 18446744073709551615;
LKUP STMT _100 = _4 plus_expr 18446744073709551615
2>>> STMT _100 = _4 plus_expr 18446744073709551615
Optimizing statement _40 = _100 - _6;
 Registering value_relation (_100 < _4) (bb16) at _100 = _4 +
18446744073709551615;
LKUP STMT _40 = _100 minus_expr _6
2>>> STMT _40 = _100 minus_expr _6
Optimizing statement _41 = _40 > 13;
LKUP STMT _41 = _40 gt_expr 13
2>>> STMT _41 = _40 gt_expr 13
LKUP STMT _40 le_expr 14
Optimizing statement if (_41 != 0)

Visiting conditional with predicate: if (_41 != 0)

With known ranges
        _41: [irange] bool VARYING

  parent reply	other threads:[~2023-05-10  7:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 16:48 [Bug c++/109791] New: " szhong at perforce dot com
2023-05-09 17:28 ` [Bug tree-optimization/109791] " pinskia at gcc dot gnu.org
2023-05-10  7:26 ` rguenth at gcc dot gnu.org [this message]
2023-05-11  8:05 ` aldyh at gcc dot gnu.org
2023-05-11  8:19 ` aldyh at gcc dot gnu.org
2023-05-11  9:39 ` rguenth at gcc dot gnu.org
2023-05-11  9:47 ` aldyh at gcc dot gnu.org
2023-05-11 11:36 ` rguenther at suse dot de
2023-05-11 11:40 ` rguenth at gcc dot gnu.org
2023-05-11 12:22 ` rguenth at gcc dot gnu.org
2023-05-11 12:34 ` rguenth at gcc dot gnu.org
2023-05-11 12:35 ` rguenth at gcc dot gnu.org
2023-05-11 12:36 ` rguenth at gcc dot gnu.org
2023-05-12 11:48 ` cvs-commit at gcc dot gnu.org
2023-05-25 12:14 ` rguenth at gcc dot gnu.org
2023-05-25 12:15 ` rguenth at gcc dot gnu.org
2023-05-25 12:16 ` rguenth at gcc dot gnu.org
2023-05-25 15:35 ` pinskia at gcc dot gnu.org
2023-06-07 22:28 ` pinskia 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-109791-4-6aIEpxprwx@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).