The following reverts a bogus fix done for PR101009 and instead makes sure we get into the same_access_functions () case when computing the distance vector for g[1] and g[1] where the constants ended up having different types. The generic code doesn't seem to handle loop invariant dependences. The special case gets us both ( 0 ) and ( 1 ) as distance vectors while formerly we got ( 1 ), which the PR101009 fix changed to ( 0 ) with bad effects on other cases as shown in this PR.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk sofar. Richard. PR tree-optimization/116768 * tree-data-ref.cc (build_classic_dist_vector_1): Revert PR101009 change. * tree-chrec.cc (eq_evolutions_p): Make sure (sizetype)1 and (int)1 compare equal. * gcc.dg/torture/pr116768.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr116768.c | 32 +++++++++++++++++++++++++ gcc/tree-chrec.cc | 4 ++-- gcc/tree-data-ref.cc | 2 -- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr116768.c diff --git a/gcc/testsuite/gcc.dg/torture/pr116768.c b/gcc/testsuite/gcc.dg/torture/pr116768.c new file mode 100644 index 00000000000..57b5d00e7b7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116768.c @@ -0,0 +1,32 @@ +/* { dg-do run } */ + +#define numwords 2 + +typedef struct { + unsigned words[numwords]; +} Child; + +typedef struct { + Child child; +} Parent; + +Parent my_or(Parent x, const Parent *y) { + const Child *y_child = &y->child; + for (int i = 0; i < numwords; i++) { + x.child.words[i] |= y_child->words[i]; + } + return x; +} + +int main() { + Parent bs[4]; + __builtin_memset(bs, 0, sizeof(bs)); + + bs[0].child.words[0] = 1; + for (int i = 1; i <= 3; i++) { + bs[i] = my_or(bs[i], &bs[i - 1]); + } + if (bs[2].child.words[0] != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-chrec.cc b/gcc/tree-chrec.cc index 8b7982a2dbe..9b272074a2e 100644 --- a/gcc/tree-chrec.cc +++ b/gcc/tree-chrec.cc @@ -1716,7 +1716,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1) || TREE_CODE (chrec0) != TREE_CODE (chrec1)) return false; - if (chrec0 == chrec1) + if (operand_equal_p (chrec0, chrec1, 0)) return true; if (! types_compatible_p (TREE_TYPE (chrec0), TREE_TYPE (chrec1))) @@ -1743,7 +1743,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1) TREE_OPERAND (chrec1, 0)); default: - return operand_equal_p (chrec0, chrec1, 0); + return false; } } diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc index 0f173e8803a..de234c65e94 100644 --- a/gcc/tree-data-ref.cc +++ b/gcc/tree-data-ref.cc @@ -5223,8 +5223,6 @@ build_classic_dist_vector_1 (struct data_dependence_relation *ddr, non_affine_dependence_relation (ddr); return false; } - else - *init_b = true; } return true; -- 2.43.0