On 1/9/19 9:43 AM, Richard Biener wrote:
> On Tue, 8 Jan 2019, Jakub Jelinek wrote:
> 
>> Hi!
>>
>> As mentioned in the PR, if a VECTOR_CST is not VECTOR_CST_STEPPED_P,
>> it is sufficient to recurse just on all the encoded elt, because if
>> the vector has more elts than encoded, all the remaining ones are equal to
>> the last one.
>> But, if it is stepped, there is the possibility that while the penultimate
>> and last encoded elt could be zero or one, the first non-encoded one could
>> be two or minus one.
>>
>> The patch as committed is doing:
>>         unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
>>         if (VECTOR_CST_STEPPED_P (expr)
>>             && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
>>           return false;
>> so if it is stepped, it updates nelts to the subparts count and thus
>> attempts to verify all elts rather than just the encoded ones.  But that
>> fails because VECTOR_CST_ENCODED_ELT can't really access the non-encoded
>> ones.  The following patch fixes it by using vector_cst_elt there instead,
>> for the encoded elt it just returns VECTOR_CST_ENCODED_ELT immediately and
>> for the next value it will likely fail the predicate.
>>
>> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> OK.
> 
> Richard.
> 
>> 2019-01-08  Jelinek  <ja...@redhat.com>
>>
>>      PR middle-end/88758
>>      * tree.c (initializer_each_zero_or_onep) <case VECTOR_CST>: Use
>>      vector_cst_elt instead of VECTOR_CST_ENCODED_ELT.
>>
>> --- gcc/tree.c.jj    2019-01-07 17:59:22.883951743 +0100
>> +++ gcc/tree.c       2019-01-08 18:15:01.956087119 +0100
>> @@ -11255,7 +11255,7 @@ initializer_each_zero_or_onep (const_tre
>>  
>>      for (unsigned int i = 0; i < nelts; ++i)
>>        {
>> -        tree elt = VECTOR_CST_ENCODED_ELT (expr, i);
>> +        tree elt = vector_cst_elt (expr, i);
>>          if (!initializer_each_zero_or_onep (elt))
>>            return false;
>>        }
>>
>>      Jakub
>>
>>
> 

I'm adding a test-case for that, tested on x86_64-linux-gnu.
Verified that ICEs when the fix is removed. I'm going to install the patch.

Martin
>From 4c7b3356fff88dc443777f53ebb9e15e451a5d51 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Fri, 11 Jan 2019 14:17:46 +0100
Subject: [PATCH] Add a testcase (PR middle-end/88758).

gcc/testsuite/ChangeLog:

2019-01-11  Martin Liska  <mli...@suse.cz>

	PR middle-end/88758
	* g++.dg/lto/pr88758_0.C: New test.
	* g++.dg/lto/pr88758_1.C: New test.
---
 gcc/testsuite/g++.dg/lto/pr88758_0.C | 7 +++++++
 gcc/testsuite/g++.dg/lto/pr88758_1.C | 9 +++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/lto/pr88758_0.C
 create mode 100644 gcc/testsuite/g++.dg/lto/pr88758_1.C

diff --git a/gcc/testsuite/g++.dg/lto/pr88758_0.C b/gcc/testsuite/g++.dg/lto/pr88758_0.C
new file mode 100644
index 00000000000..eccbf63c358
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr88758_0.C
@@ -0,0 +1,7 @@
+// { dg-lto-do link }
+// { dg-require-effective-target fpic }
+// { dg-require-effective-target shared }
+// { dg-lto-options { { -O3 -fPIC -flto -shared } } }
+
+void PreEvaluate(void);
+int main() { PreEvaluate(); return 0; }
diff --git a/gcc/testsuite/g++.dg/lto/pr88758_1.C b/gcc/testsuite/g++.dg/lto/pr88758_1.C
new file mode 100644
index 00000000000..64ff57aeeb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr88758_1.C
@@ -0,0 +1,9 @@
+extern int a[];
+int b;
+int c;
+
+void PreEvaluate(void) {
+  b = 0;
+  for (; b < 8; b++)
+    a[b] = c * (b > 0 ? b - 1 : 0);
+}
-- 
2.20.1

Reply via email to