[gcc(refs/users/aoliva/heads/testme)] verbose fold_truth_andor_1 - extra

Alexandre Oliva aoliva@gcc.gnu.org
Thu Sep 17 08:22:29 GMT 2020


https://gcc.gnu.org/g:88bde4e82281723371fd02cc6fcc425e4c6439c6

commit 88bde4e82281723371fd02cc6fcc425e4c6439c6
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Tue Sep 15 13:32:23 2020 -0300

    verbose fold_truth_andor_1 - extra

Diff:
---
 gcc/fold-const.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c835327dac9..526687c647e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6176,7 +6176,7 @@ merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
 
 static tree
 fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
-		    tree lhs, tree rhs, tree *separatep)
+		    tree lhs, tree rhs, tree *separatep, int recursed = 0)
 {
   /* If this is the "or" of two comparisons, we can do something if
      the comparisons are NE_EXPR.  If this is the "and", we can do something
@@ -6238,6 +6238,7 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
       || TREE_CODE_CLASS (rcode) != tcc_comparison)
     {
       tree separate = NULL;
+      bool report = true;
 
       /* Check for the possibility of merging component references.
 	 If any of our operands is another similar operation, recurse
@@ -6260,8 +6261,11 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 					    TREE_OPERAND (lhs, 1), rhs,
 					    separatep
 					    ? separatep
-					    : NULL)) != 0)
+					    : NULL, recursed + 1)) != 0)
 	    {
+	      report = separatep || recursed > 1
+		|| (TREE_CODE (TREE_OPERAND (lhs, 1)) == code
+		    && TREE_TYPE (TREE_OPERAND (lhs, 1)) == truth_type);
 	      /* We have combined the latter part of LHS with RHS.  If
 		 they were separate, the recursion already placed any
 		 remains of RHS in *SEPARATEP, otherwise they are all
@@ -6269,13 +6273,13 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 		 former part of LHS.  */
 	      result = fold_build2_loc (loc, code, truth_type,
 					TREE_OPERAND (lhs, 0), result);
-	      return result;
 	    }
+	  else
 	  if ((result = fold_truth_andor_1 (loc, code, truth_type,
 					    TREE_OPERAND (lhs, 0), rhs,
 					    separatep
 					    ? separatep
-					    : &separate)) != 0)
+					    : &separate, recursed + 1)) != 0)
 	    {
 	      /* We have combined the former part of LHS with RHS.  If
 		 they were separate, the recursive call will have
@@ -6289,7 +6293,6 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 	      if (separate)
 		result = fold_build2_loc (loc, code, truth_type,
 					  result, separate);
-	      return result;
 	    }
 	}
       else if (TREE_CODE_CLASS (lcode) == tcc_comparison
@@ -6299,7 +6302,7 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 					    lhs, TREE_OPERAND (rhs, 0),
 					    separatep
 					    ? &separate
-					    : NULL)) != 0)
+					    : NULL, recursed + 1)) != 0)
 	    {
 	      /* We have combined LHS with the former part of RHS.  If
 		 they were separate, have any remnants of RHS placed
@@ -6317,11 +6320,11 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 	      else
 		result = fold_build2_loc (loc, code, truth_type,
 					  result, separate);
-	      return result;
 	    }
+	  else
 	  if ((result = fold_truth_andor_1 (loc, code, truth_type,
 					    lhs, TREE_OPERAND (rhs, 1),
-					    &separate)) != 0)
+					    &separate, recursed + 1)) != 0)
 	    {
 	      /* We have combined LHS with the latter part of RHS.
 		 They're definitely not adjacent, so we get the
@@ -6340,11 +6343,22 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 	      else
 		result = fold_build2_loc (loc, code, truth_type,
 					  result, separate);
-	      return result;
 	    }
 	}
+      else
+	result = NULL;
 
-      return 0;
+      if (report && result)
+	{
+	  if (separatep && *separatep)
+	    inform (loc, "extra merged %qE and %qE into %qE and %qE",
+		    lhs, rhs, result, *separatep);
+	  else
+	    inform (loc, "extra merged %qE and %qE into %qE",
+		    lhs, rhs, result);
+	}
+
+      return result;
     }
 
   ll_arg = TREE_OPERAND (lhs, 0);
@@ -6817,6 +6831,13 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 	  result = lll_result;
 	  *separatep = llr_result;
 	}
+
+      if (separatep && *separatep)
+	inform (loc, "merged extra %qE and %qE into %qE and %qE",
+		lhs, rhs, result, *separatep);
+      else
+	inform (loc, "merged extra %qE and %qE into %qE",
+		lhs, rhs, result);
     }
   else
     {
@@ -6835,6 +6856,10 @@ fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
 
       result = build2_loc (loc, wanted_code, truth_type, result,
 			   const_binop (BIT_IOR_EXPR, l_const, r_const));
+
+      if (recursed > 1)
+	inform (loc, "merged extra %qE and %qE into %qE",
+		lhs, rhs, result);
     }
 
   return result;


More information about the Gcc-cvs mailing list