public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6854] middle-end/98773 - always sign extend CHREC_RIGHT
@ 2021-01-22 11:50 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-01-22 11:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8bad25eb56bd16f3482f856a75b1c1ae5cfe1c4f

commit r11-6854-g8bad25eb56bd16f3482f856a75b1c1ae5cfe1c4f
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 22 11:29:17 2021 +0100

    middle-end/98773 - always sign extend CHREC_RIGHT
    
    The previous change exposed a miscompile when trying to interpret
    CHREC_RIGHT correctly which in fact it already was to the extent
    it is used.  The following reverts this part of the change, only
    retaining the singling out of HOST_WIDE_INT_MIN.
    
    2021-01-22  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/98773
            * tree-data-ref.c (initalize_matrix_A): Revert previous
            change, retaining failing on HOST_WIDE_INT_MIN CHREC_RIGHT.
    
            * gcc.dg/torture/pr98773.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr98773.c | 19 +++++++++++++++++++
 gcc/tree-data-ref.c                    | 17 +++--------------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr98773.c b/gcc/testsuite/gcc.dg/torture/pr98773.c
new file mode 100644
index 00000000000..026e8efba5c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr98773.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+char a[128];
+
+void __attribute__((noipa))
+foo ()
+{
+  for (unsigned i = 27; i >= 5; --i)
+    a[i] = a[i-5];
+}
+
+int main()
+{
+  __builtin_memcpy (a, "Hello World", sizeof ("Hello World"));
+  foo ();
+  if (__builtin_memcmp (a + 5, "Hello World", sizeof ("Hello World")) != 0)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index d19c5eb51e4..124a7bea6a9 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -3924,21 +3924,10 @@ initialize_matrix_A (lambda_matrix A, tree chrec, unsigned index, int mult)
   switch (TREE_CODE (chrec))
     {
     case POLYNOMIAL_CHREC:
-      /* CHREC_RIGHT and its negated value should fit in a lambda_int.
-	 Pointer typed chrecs right are to be interpreted signed.  */
       HOST_WIDE_INT chrec_right;
-      if (POINTER_TYPE_P (chrec_type (chrec)))
-	{
-	  if (!cst_and_fits_in_hwi (CHREC_RIGHT (chrec)))
-	    return chrec_dont_know;
-	  chrec_right = int_cst_value (CHREC_RIGHT (chrec));
-	}
-      else
-	{
-	  if (!tree_fits_shwi_p (CHREC_RIGHT (chrec)))
-	    return chrec_dont_know;
-	  chrec_right = tree_to_shwi (CHREC_RIGHT (chrec));
-	}
+      if (!cst_and_fits_in_hwi (CHREC_RIGHT (chrec)))
+	return chrec_dont_know;
+      chrec_right = int_cst_value (CHREC_RIGHT (chrec));
       /* We want to be able to negate without overflow.  */
       if (chrec_right == HOST_WIDE_INT_MIN)
 	return chrec_dont_know;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-22 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 11:50 [gcc r11-6854] middle-end/98773 - always sign extend CHREC_RIGHT Richard Biener

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).