[PATCH][18/n] Merge from match-and-simplify, complex stuff

Richard Biener rguenther@suse.de
Wed Nov 12 13:45:00 GMT 2014


This merges simple REALPART_EXPR/IMAGPART_EXPR/COMPLEX_EXPR cancellations.

I've adjusted the FRE testcase to disable forwprop (which now does
the transform as well) to test that FRE still would do it.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2014-11-12  Richard Biener  <rguenther@suse.de>

	* match.pd: Implement simple complex operations cancelling.
	* fold-const.c (fold_unary_loc): Remove them here.

	* gcc.dg/tree-ssa/ssa-fre-32.c: Disable forwprop.

Index: trunk/gcc/fold-const.c
===================================================================
*** trunk.orig/gcc/fold-const.c	2014-11-11 14:39:10.060078023 +0100
--- trunk/gcc/fold-const.c	2014-11-12 10:17:35.362983937 +0100
*************** fold_unary_loc (location_t loc, enum tre
*** 7996,8004 ****
      case REALPART_EXPR:
        if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
  	return fold_convert_loc (loc, type, arg0);
-       if (TREE_CODE (arg0) == COMPLEX_EXPR)
- 	return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0),
- 				 TREE_OPERAND (arg0, 1));
        if (TREE_CODE (arg0) == COMPLEX_CST)
  	return fold_convert_loc (loc, type, TREE_REALPART (arg0));
        if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
--- 7996,8001 ----
*************** fold_unary_loc (location_t loc, enum tre
*** 8039,8047 ****
      case IMAGPART_EXPR:
        if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
  	return build_zero_cst (type);
-       if (TREE_CODE (arg0) == COMPLEX_EXPR)
- 	return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 1),
- 				 TREE_OPERAND (arg0, 0));
        if (TREE_CODE (arg0) == COMPLEX_CST)
  	return fold_convert_loc (loc, type, TREE_IMAGPART (arg0));
        if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
--- 8036,8041 ----
*************** fold_binary_loc (location_t loc,
*** 13358,13370 ****
  	  || (TREE_CODE (arg0) == INTEGER_CST
  	      && TREE_CODE (arg1) == INTEGER_CST))
  	return build_complex (type, arg0, arg1);
-       if (TREE_CODE (arg0) == REALPART_EXPR
- 	  && TREE_CODE (arg1) == IMAGPART_EXPR
- 	  && TREE_TYPE (TREE_OPERAND (arg0, 0)) == type
- 	  && operand_equal_p (TREE_OPERAND (arg0, 0),
- 			      TREE_OPERAND (arg1, 0), 0))
- 	return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0),
- 				     TREE_OPERAND (arg1, 0));
        return NULL_TREE;
  
      case ASSERT_EXPR:
--- 13352,13357 ----
Index: trunk/gcc/match.pd
===================================================================
*** trunk.orig/gcc/match.pd	2014-11-12 10:12:38.770996916 +0100
--- trunk/gcc/match.pd	2014-11-12 10:15:43.890988815 +0100
*************** along with GCC; see the file COPYING3.
*** 580,582 ****
--- 580,594 ----
  (simplify
   (cond (logical_inverted_value truth_valued_p@0) @1 @2)
   (cond @0 @2 @1))
+ 
+ 
+ /* COMPLEX_EXPR and REALPART/IMAGPART_EXPR cancellations.  */
+ (simplify
+   (complex (realpart @0) (imagpart @0))
+   @0)
+ (simplify
+   (realpart (complex @0 @1))
+   @0)
+ (simplify
+   (imagpart (complex @0 @1))
+   @1)
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-32.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-32.c	(revision 217407)
+++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-32.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-fre1-details" } */
+/* { dg-options "-O -fno-tree-forwprop -fdump-tree-fre1-details" } */
 
 _Complex float m;
 



More information about the Gcc-patches mailing list