public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@linaro.org>
To: gcc-patches@gcc.gnu.org
Subject: [19/nn] Don't treat zero-sized ranges as overlapping
Date: Mon, 23 Oct 2017 11:29:00 -0000	[thread overview]
Message-ID: <87mv4iumpq.fsf@linaro.org> (raw)
In-Reply-To: <87wp3mxgir.fsf@linaro.org> (Richard Sandiford's message of "Mon,	23 Oct 2017 12:14:36 +0100")

Most GCC ranges seem to be represented as an offset and a size (rather
than a start and inclusive end or start and exclusive end).  The usual
test for whether X is in a range is of course:

  x >= start && x < start + size
or:
  x >= start && x - start < size

which means that an empty range of size 0 contains nothing.  But other
range tests aren't as obvious.

The usual test for whether one range is contained within another
range is:

  start1 >= start2 && start1 + size1 <= start2 + size2

while the test for whether two ranges overlap (from ranges_overlap_p) is:

     (start1 >= start2 && start1 < start2 + size2)
  || (start2 >= start1 && start2 < start1 + size1)

i.e. the ranges overlap if one range contains the start of the other
range.  This leads to strange results like:

  (start X, size 0) is a subrange of (start X, size 0) but
  (start X, size 0) does not overlap (start X, size 0)

Similarly:

  (start 4, size 0) is a subrange of (start 2, size 2) but
  (start 4, size 0) does not overlap (start 2, size 2)

It seems like "X is a subrange of Y" should imply "X overlaps Y".

This becomes harder to ignore with the runtime sizes and offsets
added for SVE.  The most obvious fix seemed to be to say that
an empty range does not overlap anything, and is therefore not
a subrange of anything.

Using the new definition of subranges didn't seem to cause any
codegen differences in the testsuite.  But there was one change
with the new definition of overlapping ranges.  strncpy-chk.c has:

  memset (dst, 0, sizeof (dst));
  if (strncpy (dst, src, 0) != dst || strcmp (dst, ""))
    abort();

The strncpy is detected as a zero-size write, and so with the new
definition of overlapping ranges, we treat the strncpy as having
no effect on the strcmp (which is true).  The reaching definition
is the memset instead.

This patch makes ranges_overlap_p return false for zero-sized
ranges, even if the other range has an unknown size.


2017-10-23  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* tree-ssa-alias.h (ranges_overlap_p): Return false if either
	range is known to be empty.

Index: gcc/tree-ssa-alias.h
===================================================================
--- gcc/tree-ssa-alias.h	2017-03-28 16:19:22.000000000 +0100
+++ gcc/tree-ssa-alias.h	2017-10-23 11:47:38.181155696 +0100
@@ -171,6 +171,8 @@ ranges_overlap_p (HOST_WIDE_INT pos1,
 		  HOST_WIDE_INT pos2,
 		  unsigned HOST_WIDE_INT size2)
 {
+  if (size1 == 0 || size2 == 0)
+    return false;
   if (pos1 >= pos2
       && (size2 == (unsigned HOST_WIDE_INT)-1
 	  || pos1 < (pos2 + (HOST_WIDE_INT) size2)))

  parent reply	other threads:[~2017-10-23 11:29 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 11:16 [00/nn] Patches preparing for runtime offsets and sizes Richard Sandiford
2017-10-23 11:17 ` [01/nn] Add gen_(const_)vec_duplicate helpers Richard Sandiford
2017-10-25 16:29   ` Jeff Law
2017-10-27 16:12     ` Richard Sandiford
2017-10-23 11:19 ` [03/nn] Allow vector CONSTs Richard Sandiford
2017-10-25 16:59   ` Jeff Law
2017-10-27 16:19     ` Richard Sandiford
2017-10-23 11:19 ` [02/nn] Add more vec_duplicate simplifications Richard Sandiford
2017-10-25 16:35   ` Jeff Law
2017-11-10  9:42     ` Christophe Lyon
2017-10-23 11:20 ` [04/nn] Add a VEC_SERIES rtl code Richard Sandiford
2017-10-26 11:49   ` Richard Biener
2017-10-23 11:21 ` [05/nn] Add VEC_DUPLICATE_{CST,EXPR} and associated optab Richard Sandiford
2017-10-26 11:53   ` Richard Biener
2017-11-06 15:09     ` Richard Sandiford
2017-11-07 10:37       ` Richard Biener
2017-12-15  0:29   ` Richard Sandiford
2017-12-15  8:58     ` Richard Biener
2017-12-15 12:52       ` Richard Sandiford
2017-12-15 13:20         ` Richard Biener
2017-10-23 11:22 ` [06/nn] Add VEC_SERIES_{CST,EXPR} " Richard Sandiford
2017-10-26 12:26   ` Richard Biener
2017-10-26 12:43     ` Richard Biener
2017-11-06 15:21       ` Richard Sandiford
2017-11-07 10:38         ` Richard Biener
2017-12-15  0:34   ` Richard Sandiford
2017-12-15  9:03     ` Richard Biener
2017-10-23 11:22 ` [07/nn] Add unique CONSTs Richard Sandiford
2017-10-27 15:51   ` Jeff Law
2017-10-27 15:58     ` Richard Sandiford
2017-10-30 14:49       ` Jeff Law
2017-10-23 11:22 ` [08/nn] Add a fixed_size_mode class Richard Sandiford
2017-10-26 11:57   ` Richard Biener
2017-10-23 11:23 ` [09/nn] Add a fixed_size_mode_pod class Richard Sandiford
2017-10-26 11:59   ` Richard Biener
2017-10-26 12:18     ` Richard Sandiford
2017-10-26 12:46       ` Richard Biener
2017-10-26 19:42         ` Eric Botcazou
2017-10-27  8:34           ` Richard Biener
2017-10-27  9:28             ` Eric Botcazou
2017-10-30  3:14           ` Trevor Saunders
2017-10-30  8:52             ` Richard Sandiford
2017-10-30 10:13             ` Eric Botcazou
2017-10-31 10:39               ` Trevor Saunders
2017-10-31 17:29                 ` Eric Botcazou
2017-10-31 17:57                   ` Jeff Law
2017-11-01  2:50                     ` Trevor Saunders
2017-11-01 16:30                       ` Jeff Law
2017-11-02  4:28                         ` Trevor Saunders
2017-10-26 19:44         ` Richard Sandiford
2017-10-26 19:45         ` Jakub Jelinek
2017-10-27  8:43           ` Richard Biener
2017-10-27  8:45             ` Jakub Jelinek
2017-10-27 10:19             ` Pedro Alves
2017-10-27 15:23             ` Jeff Law
2017-10-23 11:24 ` [10/nn] Widening optab cleanup Richard Sandiford
2017-10-30 18:32   ` Jeff Law
2017-10-23 11:24 ` [11/nn] Add narrower_subreg_mode helper function Richard Sandiford
2017-10-30 15:06   ` Jeff Law
2017-10-23 11:25 ` [13/nn] More is_a <scalar_int_mode> Richard Sandiford
2017-10-26 12:03   ` Richard Biener
2017-10-23 11:25 ` [12/nn] Add an is_narrower_int_mode helper function Richard Sandiford
2017-10-26 11:59   ` Richard Biener
2017-10-23 11:26 ` [14/nn] Add helpers for shift count modes Richard Sandiford
2017-10-26 12:07   ` Richard Biener
2017-10-26 12:07     ` Richard Biener
2017-11-20 21:04       ` Richard Sandiford
2017-11-21 15:00         ` Richard Biener
2017-12-15  0:48           ` Richard Sandiford
2017-12-15  9:06             ` Richard Biener
2017-12-15 15:17               ` Richard Sandiford
2017-12-19 19:13                 ` Richard Sandiford
2017-12-20  0:27                   ` Jeff Law
2017-10-30 15:03     ` Jeff Law
2017-10-23 11:27 ` [16/nn] Factor out the mode handling in lower-subreg.c Richard Sandiford
2017-10-26 12:09   ` Richard Biener
2017-10-23 11:27 ` [15/nn] Use more specific hash functions in rtlhash.c Richard Sandiford
2017-10-26 12:08   ` Richard Biener
2017-10-23 11:28 ` [17/nn] Turn var-tracking.c:INT_MEM_OFFSET into a function Richard Sandiford
2017-10-26 12:10   ` Richard Biener
2017-10-23 11:29 ` [18/nn] Use (CONST_VECTOR|GET_MODE)_NUNITS in simplify-rtx.c Richard Sandiford
2017-10-26 12:13   ` Richard Biener
2017-10-23 11:29 ` Richard Sandiford [this message]
2017-10-26 12:14   ` [19/nn] Don't treat zero-sized ranges as overlapping Richard Biener
2017-10-23 11:30 ` [20/nn] Make tree-ssa-dse.c:normalize_ref return a bool Richard Sandiford
2017-10-30 17:49   ` Jeff Law
2017-10-23 11:31 ` [21/nn] Minor vn_reference_lookup_3 tweak Richard Sandiford
2017-10-26 12:18   ` Richard Biener
2017-10-23 11:45 ` [22/nn] Make dse.c use offset/width instead of start/end Richard Sandiford
2017-10-26 12:18   ` Richard Biener

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=87mv4iumpq.fsf@linaro.org \
    --to=richard.sandiford@linaro.org \
    --cc=gcc-patches@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).