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 tree-optimization]: Normalize compares X ==/!= 1 -> X !=/== 0 for truth valued X


Hello,

this patch fixes that for replaced uses, we call fold_stmt_inplace. Additionally
it adds to fold_gimple_assign the canonical form for X !=/== 1 -> X ==/!= 0 for
X with one-bit precision type.

ChangeLog gcc/

2011-07-13  Kai Tietz  <ktietz@redhat.com>

	* gimple-fold.c (fold_gimple_assign): Add normalization
	for compares of 1-bit integer precision operands.
	* tree-ssa-propagate.c (replace_uses_in): Call
	fold_stmt_inplace on modified statement.

ChangeLog gcc/testsuite

2011-07-13  Kai Tietz  <ktietz@redhat.com>

	* gcc.dg/tree-ssa/fold-1.c: New test.

Bootstrapped and regression tested for x86_64-pc-linux-gnu.  Ok for apply?

Regards,
Kai

Index: gcc/gcc/gimple-fold.c
===================================================================
--- gcc.orig/gcc/gimple-fold.c	2011-07-13 10:37:32.000000000 +0200
+++ gcc/gcc/gimple-fold.c	2011-07-13 10:39:05.100843400 +0200
@@ -815,6 +815,17 @@ fold_gimple_assign (gimple_stmt_iterator
 					     gimple_assign_rhs2 (stmt));
 	}

+      if (!result && (subcode == EQ_EXPR || subcode == NE_EXPR)
+	  && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (stmt)))
+	  && TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt))) == 1
+	  && integer_onep (gimple_assign_rhs2 (stmt)))
+	result = build2_loc (loc, (subcode == EQ_EXPR ? NE_EXPR : EQ_EXPR),
+			     TREE_TYPE (gimple_assign_lhs (stmt)),
+			     gimple_assign_rhs1 (stmt),
+			     fold_convert_loc (loc,
+				TREE_TYPE (gimple_assign_rhs1 (stmt)),
+				integer_zero_node));
+			
       if (!result)
         result = fold_binary_loc (loc, subcode,
                               TREE_TYPE (gimple_assign_lhs (stmt)),
Index: gcc/gcc/testsuite/gcc.dg/tree-ssa/fold-1.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/gcc/testsuite/gcc.dg/tree-ssa/fold-1.c	2011-07-13
10:50:38.294367800 +0200
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int foo (_Bool a, _Bool b)
+{
+  return a != ((b | !b));
+}
+/* { dg-final { scan-tree-dump-not " != 1" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
Index: gcc/gcc/tree-ssa-propagate.c
===================================================================
--- gcc.orig/gcc/tree-ssa-propagate.c	2011-07-13 10:37:42.000000000 +0200
+++ gcc/gcc/tree-ssa-propagate.c	2011-07-13 10:40:25.688576800 +0200
@@ -904,6 +904,8 @@ replace_uses_in (gimple stmt, ssa_prop_g

       propagate_value (use, val);

+      fold_stmt_inplace (stmt);
+
       replaced = true;
     }


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