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]

[PATCH 1/3] Perform fold when propagating.


This patch performs more aggressive folding in order for the
match.pd changes to kick in later.

Some test cases rely on VRP doing something which now already
happens during CCP so adjust them accordingly.

Also, the loop versioning pass was missing one case when
deconstructing addresses that would only be triggered after
this patch for me:
It could handle addition and subsequent convert/nop but not
a convert/nop directly.  This would cause the hash to be
calculated differently and, in turn, cause the pass to miss
a versioning opportunity.  Fixed this by adding the missing
case.
---
 gcc/fortran/trans-intrinsic.c                  | 5 +++--
 gcc/gimple-loop-versioning.cc                  | 6 ++++++
 gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C      | 4 +++-
 gcc/testsuite/gcc.dg/pr35691-1.c               | 4 ++--
 gcc/testsuite/gcc.dg/pr35691-2.c               | 4 ++--
 gcc/testsuite/gcc.dg/pr35691-3.c               | 4 ++--
 gcc/testsuite/gcc.dg/pr35691-4.c               | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c     | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c      | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c    | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/loop-15.c        | 2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr23744.c        | 4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/pr52631.c        | 4 ++--
 gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c | 2 +-
 gcc/tree-ssa-propagate.c                       | 6 ++++--
 15 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index a6e33833680..99ec5f34319 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -5428,8 +5428,9 @@ gfc_conv_intrinsic_findloc (gfc_se *se, gfc_expr *expr)
   tree type;
   tree tmp;
   tree found;
-  tree forward_branch;
-  tree back_branch;
+  /* Initialize here to avoid 'maybe used uninitialized'.  */
+  tree forward_branch = NULL_TREE;
+  tree back_branch = NULL_TREE;
   gfc_loopinfo loop;
   gfc_ss *arrayss;
   gfc_ss *maskss;
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index 8fa19488490..36c70543402 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -1266,6 +1266,12 @@ loop_versioning::record_address_fragment (gimple *stmt,
 		  continue;
 		}
 	    }
+	  if (code == NOP_EXPR)
+	    {
+	      tree op1 = gimple_assign_rhs1 (assign);
+	      address->terms[i].expr = strip_casts (op1);
+	      continue;
+	    }
 	}
       i += 1;
     }
diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C
index ca7e18f66a9..83a8f0668df 100644
--- a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C
+++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-dse2-details -Wno-return-type" } */
+/* { dg-options "-O2 -fdump-tree-dse2-details -fdump-tree-vrp1-details -Wno-return-type" } */
 
 typedef __SIZE_TYPE__ size_t;
 extern "C"
@@ -55,3 +55,5 @@ fill_vec_av_set (av_set_t av)
 
 /* { dg-final { scan-tree-dump-not "Trimming statement .head = -" "dse2" } } */
 /* { dg-final { scan-tree-dump-not "mem\[^\r\n\]*, 0\\);" "dse2" } } */
+/* { dg-final { scan-tree-dump "Folded into: GIMPLE_NOP" "vrp1" } } */
+/* { dg-final { scan-tree-dump-not "memmove" "dse2" } } */  }
diff --git a/gcc/testsuite/gcc.dg/pr35691-1.c b/gcc/testsuite/gcc.dg/pr35691-1.c
index 34dc02ab560..2e1d8bd0f43 100644
--- a/gcc/testsuite/gcc.dg/pr35691-1.c
+++ b/gcc/testsuite/gcc.dg/pr35691-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+/* { dg-options "-O2 -fdump-tree-ccp1-details" } */
 
 int foo(int z0, unsigned z1)
 {
@@ -9,4 +9,4 @@ int foo(int z0, unsigned z1)
   return t2;
 }
 
-/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */
diff --git a/gcc/testsuite/gcc.dg/pr35691-2.c b/gcc/testsuite/gcc.dg/pr35691-2.c
index b89ce481c6c..d5e335bb72a 100644
--- a/gcc/testsuite/gcc.dg/pr35691-2.c
+++ b/gcc/testsuite/gcc.dg/pr35691-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+/* { dg-options "-O2 -fdump-tree-ccp1-details" } */
 
 int foo(int z0, unsigned z1)
 {
@@ -9,4 +9,4 @@ int foo(int z0, unsigned z1)
   return t2;
 }
 
-/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */
diff --git a/gcc/testsuite/gcc.dg/pr35691-3.c b/gcc/testsuite/gcc.dg/pr35691-3.c
index 75b49a6e2ca..a1896e47b59 100644
--- a/gcc/testsuite/gcc.dg/pr35691-3.c
+++ b/gcc/testsuite/gcc.dg/pr35691-3.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+/* { dg-options "-O2 -fdump-tree-ccp1-details" } */
 
 int foo(int z0, unsigned z1)
 {
@@ -9,4 +9,4 @@ int foo(int z0, unsigned z1)
   return t2;
 }
 
-/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */
diff --git a/gcc/testsuite/gcc.dg/pr35691-4.c b/gcc/testsuite/gcc.dg/pr35691-4.c
index 2d9456bd16f..58f28aebe69 100644
--- a/gcc/testsuite/gcc.dg/pr35691-4.c
+++ b/gcc/testsuite/gcc.dg/pr35691-4.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */
+/* { dg-options "-O2 -fdump-tree-ccp1-details" } */
 
 int foo(int z0, unsigned z1)
 {
@@ -9,4 +9,4 @@ int foo(int z0, unsigned z1)
   return t2;
 }
 
-/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c
index 10935293476..17c2a7e2d3e 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-dce2 -fdump-tree-forwprop1-details" } */
+/* { dg-options "-O2 -fdump-tree-dce2 -fdump-tree-ccp1-details" } */
   
 int abarney[2];
 int afred[1];
@@ -23,7 +23,7 @@ void foo(int edx, int eax)
  
 
 /* Verify that we did a forward propagation.  */
-/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "forwprop1"} } */
+/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "ccp1"} } */
 
 /* After dce we should have two IF statements remaining as the other
    two tests can be threaded.  */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c b/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c
index b563f5e404c..6890d0067b6 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-forwprop1-details -fdump-tree-ccp1-details" } */
+/* { dg-options "-O -fdump-tree-ccp1-details" } */
 
 int f1(int a, int b){
   int c = a & b;
@@ -26,4 +26,4 @@ int g3(int a, int b, int c){
 }
 
 /* { dg-final { scan-tree-dump-times "Match-and-simplified" 2 "ccp1" } } */
-/* { dg-final { scan-tree-dump-times "gimple_simplified" 3 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "gimple_simplified" 3 "ccp1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c
index 1bef7e7a31f..bef76e597dd 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-forwprop1" } */
+/* { dg-options "-O -fdump-tree-forwprop2" } */
 
 int foo (double xx, double xy)
 {
@@ -10,4 +10,4 @@ int foo (double xx, double xy)
   return 2;
 }
 
-/* { dg-final { scan-tree-dump "if \\\(x" "forwprop1" } } */
+/* { dg-final { scan-tree-dump "if \\\(x" "forwprop2" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c
index b437518487d..dce6ad57a04 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c
@@ -19,7 +19,7 @@ int bla(void)
 }
 
 /* Since the loop is removed, there should be no addition.  */
-/* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" } } */
 /* { dg-final { scan-tree-dump-times " \\* " 1 "optimized" } } */
 
 /* The if from the loop header copying remains in the code.  */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c b/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c
index 3385aa1e424..ba3fda352ca 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
 
 void h (void);
 
@@ -17,4 +17,4 @@ int g (int i, int j)
     return 1;
 }
 
-/* { dg-final { scan-tree-dump-times "Folding predicate.*to 1" 1 "vrp1" } } */
+/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "vrp1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c
index c18a5d570b4..2e99d112057 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-fre1-details" } */
+/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-ccp1-details" } */
 
 unsigned f(unsigned a)
 {
@@ -12,6 +12,6 @@ unsigned f(unsigned a)
 }
 
 /* We want to verify that we replace the b & 1 with b.  */
-/* { dg-final { scan-tree-dump-times "Replaced b_\[0-9\]+ & 1 with b_\[0-9\]+ in" 1 "fre1"} } */
+/* { dg-final { scan-tree-dump-times "Match-and-simplified b_\[0-9\]+ & 1 to b_\[0-9\]+" 1 "ccp1"} } */
  
 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c b/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c
index 34ce512f372..e2e0d6cb8bc 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-additional-options "-fno-tree-forwprop -fno-tree-vrp" }
+/* { dg-additional-options "-fno-tree-forwprop -fno-tree-vrp -fno-tree-ccp -fno-tree-copy-prop" } */
 /* { dg-require-effective-target vect_int } */
 
 #include "tree-vect.h"
diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c
index 0862f83e9a1..7a8f1e037b0 100644
--- a/gcc/tree-ssa-propagate.c
+++ b/gcc/tree-ssa-propagate.c
@@ -1064,10 +1064,12 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
       /* Replace real uses in the statement.  */
       did_replace |= substitute_and_fold_engine->replace_uses_in (stmt);
 
-      /* If we made a replacement, fold the statement.  */
       if (did_replace)
+	  gimple_set_modified (stmt, true);
+
+      if (fold_stmt (&i, follow_single_use_edges))
 	{
-	  fold_stmt (&i, follow_single_use_edges);
+	  did_replace = true;
 	  stmt = gsi_stmt (i);
 	  gimple_set_modified (stmt, true);
 	}
-- 
2.17.0


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