From 3facc4b61545614e75b4fb852a72bbc80554705b Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Wed, 2 Jun 2004 18:56:54 +0000 Subject: [PATCH] re PR tree-optimization/14736 ([tree-ssa] code quality regression) 2004-06-02 Andrew Pinski PR tree-optimization/14736 * g++.dg/tree-ssa/ssa-cast-1.C: New Test. PR tree-optimization/14042 * g++.dg/tree-ssa/ssa-sra-1.C: New Test. PR tree-optimization/14729 * g++.dg/tree-ssa/ssa-sra-2.C: New Test. 2004-06-02 Andrew Pinski PR tree-optimization/14042 PR tree-optimization/14729 PR tree-optimization/14736 * tree-ssa.c: Check the type which the pointer points to instead of the pointer types. From-SVN: r82573 --- gcc/ChangeLog | 8 +++ gcc/testsuite/ChangeLog | 11 ++++ gcc/testsuite/g++.dg/tree-ssa/ssa-cast-1.C | 12 +++++ gcc/testsuite/g++.dg/tree-ssa/ssa-sra-1.C | 60 ++++++++++++++++++++++ gcc/testsuite/g++.dg/tree-ssa/ssa-sra-2.C | 51 ++++++++++++++++++ gcc/tree-ssa.c | 3 +- 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/ssa-cast-1.C create mode 100644 gcc/testsuite/g++.dg/tree-ssa/ssa-sra-1.C create mode 100644 gcc/testsuite/g++.dg/tree-ssa/ssa-sra-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d22422d993..7290effa578 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2004-06-02 Andrew Pinski + + PR tree-optimization/14042 + PR tree-optimization/14729 + PR tree-optimization/14736 + * tree-ssa.c: Check the type which the pointer points to + instead of the pointer types. + 2004-06-02 Kazu Hirata PR tree-optimization/15738. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2a8bc4a6c94..4f4dd345151 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2004-06-02 Andrew Pinski + + PR tree-optimization/14736 + * g++.dg/tree-ssa/ssa-cast-1.C: New Test. + + PR tree-optimization/14042 + * g++.dg/tree-ssa/ssa-sra-1.C: New Test. + + PR tree-optimization/14729 + * g++.dg/tree-ssa/ssa-sra-2.C: New Test. + 2004-06-02 Tobias Schlueter PR fortran/15557 diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-cast-1.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-cast-1.C new file mode 100644 index 00000000000..b8015870a22 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-cast-1.C @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-vars" } */ + +int &f(int *a) +{ + return *a; +} + +/* There should be no cast as pointer and references are + considered the same type. */ +/* { dg-final { scan-tree-dump-times "\\(int &\\)" 0 "vars"} } */ + diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-1.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-1.C new file mode 100644 index 00000000000..cf6c520ce21 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-1.C @@ -0,0 +1,60 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-vars-details" } */ + +void link_error(); + + +struct State { + int p0, p1, p2; + inline State(){p0=0;p1=0;p2=0;} + inline State(const State &s) { + p0 = s.p0; + p1 = s.p1; + p2 = s.p2; + } + + inline void operator =(const State &s) { + p0 = s.p0; + p1 = s.p1; + p2 = s.p2; + } + + inline void step(void) { + p0 = p1+p2; + p1 = p0*p1+p2; + p2 = p0-p2; + } +}; + + +inline void iterate_ok(State &inS1, State &inS2, unsigned int n) +{ + State s1 = inS1; + for (unsigned int i = 0; i < n; i++) { + s1.step(); + } + inS1 = s1; +} + +void temp() +{ + State s1; + s1.p0 = 0; + s1.p1 = 0; + s1.p2 = 0; + State s2; + s2.p0 = 0; + s2.p1 = 0; + s2.p2 = 0; + iterate_ok (s1, s2, 1); + if (s1.p0) + link_error(); + if (s1.p0) + link_error(); + if (s1.p0) + link_error(); +} + +/* We should removed the casts from pointers to references and caused SRA to happen. */ + +/* { dg-final { scan-tree-dump-times "link_error" 0 "vars"} } */ diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-2.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-2.C new file mode 100644 index 00000000000..0d637520969 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-sra-2.C @@ -0,0 +1,51 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-vars-details" } */ + +void link_error(); + +struct OOf { + int value; + OOf() {value = 0;} +}; +inline OOf operator+(OOf op1, OOf op2) +{ + OOf f; + f.value = op1.value + op2.value; + return f; +} +inline OOf operator*(OOf op1, OOf op2) +{ + OOf f; + f.value = op1.value * op2.value; + return f; +} +inline OOf operator-(OOf op1, OOf op2) +{ + OOf f; + f.value = op1.value - op2.value; + return f; +} +inline OOf test_func( + OOf a, + OOf b, + OOf c +) +{ + OOf d, e; + OOf result; + d = a * b + b * c; + e = a * c - b * d; + result = d * e; + return result; +} + +void test() +{ + OOf a, b, c; + OOf d = test_func (a,b,c); + if (d.value) + link_error(); +} + +/* We should removed the casts from pointers to references and caused SRA to happen. */ +/* { dg-final { scan-tree-dump-times "link_error" 0 "vars"} } */ diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 8ecce07e4f4..99e2cb64dfd 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -555,7 +555,8 @@ tree_ssa_useless_type_conversion_1 (tree outer_type, tree inner_type) so strip conversions that just switch between them. */ else if (POINTER_TYPE_P (inner_type) && POINTER_TYPE_P (outer_type) - && lang_hooks.types_compatible_p (inner_type, outer_type)) + && lang_hooks.types_compatible_p (TREE_TYPE (inner_type), + TREE_TYPE (outer_type))) return true; /* If both the inner and outer types are integral types, then the -- 2.30.2