This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] improve C++ code by changing fold-const.c



On Jun 2, 2004, at 12:42, Jeffrey A Law wrote:


	* tree-ssa.c: Check the type which the pointer points to
	instead of the pointer types.

And here is the testcases which I added to make sure that this does not break again.

Thanks,
Andrew Pinski

2004-06-02 Andrew Pinski <pinskia@physics.uc.edu>

        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.


Index: ssa-cast-1.C
===================================================================
RCS file: ssa-cast-1.C
diff -N ssa-cast-1.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ssa-cast-1.C 2 Jun 2004 18:53:34 -0000
@@ -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"} } */
+
Index: ssa-sra-1.C
===================================================================
RCS file: ssa-sra-1.C
diff -N ssa-sra-1.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ssa-sra-1.C 2 Jun 2004 18:53:34 -0000
@@ -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"} } */
Index: ssa-sra-2.C
===================================================================
RCS file: ssa-sra-2.C
diff -N ssa-sra-2.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ssa-sra-2.C 2 Jun 2004 18:53:34 -0000
@@ -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"} } */



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]