public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Martin Sebor <msebor@gmail.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] adjust object size computation for union accesses and PHIs (PR 92765)
Date: Wed, 15 Jan 2020 21:15:00 -0000	[thread overview]
Message-ID: <5b15c50bd2336aa78dd5d01dd3701a6bc8c644f3.camel@redhat.com> (raw)
In-Reply-To: <64a504e5-8e1f-682a-0443-e74e62d3aac1@gmail.com>

On Wed, 2020-01-15 at 13:18 +0000, Martin Sebor wrote:
> The strcmp optimization newly introduced in GCC 10 relies on
> the size of the smallest referenced array object to determine
> whether the function can return zero.  When the size of
> the object is smaller than the length of the other string
> argument the optimization folds the equality to false.
> 
> The bug report has identified a couple of problems here:
> 1) when the access to the array object is via a pointer to
> a (possibly indirect) member of a union, in GIMPLE the pointer
> may actually point to a different member than the one in
> the original source code.  Thus the size of the array may
> appear to be smaller than in the source code which can then
> result in the optimization being invalid.
> 2) when the pointer in the access may point to two or more
> arrays of different size (i.e., it's the result of a PHI),
> assuming it points to the smallest of them can also lead
> to an incorrect result when the optimization is applied.
> 
> The attached patch adjusts the optimization to 1) avoid making
> any assumptions about the sizes of objects accessed via union
> types, and b) use the size of the largest object in PHI nodes.
> 
> Tested on x86_64-linux.
> 
> Martin
> PR tree-optimization/92765 - wrong code for strcmp of a union member
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/92765
> 	* gcc.dg/strlenopt-92.c: New test.
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/92765
> 	* tree-ssa-strlen.c (component_ref_via_union_p): New function.
> 	(determine_min_objsize): Call it.  Use the maximum object size
> 	for PHI arguments.
OK
jeff

  reply	other threads:[~2020-01-15 20:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 13:25 Martin Sebor
2020-01-15 21:15 ` Jeff Law [this message]
2020-01-15 21:49 ` Jakub Jelinek
2020-01-16 13:26   ` Jakub Jelinek
2020-01-31 20:17 ` Martin Sebor
2020-02-03 18:44   ` Jeff Law
2020-02-04 14:35     ` Richard Biener
2020-02-05 23:58       ` Martin Sebor
2020-02-05 23:58     ` Martin Sebor
2020-02-06 13:01       ` Jeff Law

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=5b15c50bd2336aa78dd5d01dd3701a6bc8c644f3.camel@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=msebor@gmail.com \
    /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).