[PATCH] Turn constant vector CONSTRUCTORs to VECTOR_CSTs
Richard Guenther
rguenther@suse.de
Tue May 26 11:40:00 GMT 2009
Not turning constant vector CONSTRUCTORs to VECTOR_CSTs pervents
constant propagation and folding in VIEW_CONVERT_EXPRs. The following
patch teaches CCP and fold_stmt to properly do that which fixes the
cases originating from both inlining and CCP.
This makes the testcase in PR40122 constant fold properly.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2009-05-26 Richard Guenther <rguenther@suse.de>
PR tree-optimization/40122
* tree-ssa-ccp.c (ccp_fold): Fold vector CONSTRUCTORs to
VECTOR_CSTs if possible.
(fold_gimple_assign): Likewise.
Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c (revision 147862)
--- gcc/tree-ssa-ccp.c (working copy)
*************** ccp_fold (gimple stmt)
*** 958,963 ****
--- 958,987 ----
}
}
}
+ else if (TREE_CODE (rhs) == CONSTRUCTOR
+ && TREE_CODE (TREE_TYPE (rhs)) == VECTOR_TYPE
+ && (CONSTRUCTOR_NELTS (rhs)
+ == TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs))))
+ {
+ unsigned i;
+ tree val, list;
+
+ list = NULL_TREE;
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
+ {
+ if (TREE_CODE (val) == SSA_NAME
+ && get_value (val)->lattice_val == CONSTANT)
+ val = get_value (val)->value;
+ if (TREE_CODE (val) == INTEGER_CST
+ || TREE_CODE (val) == REAL_CST
+ || TREE_CODE (val) == FIXED_CST)
+ list = tree_cons (NULL_TREE, val, list);
+ else
+ return NULL_TREE;
+ }
+
+ return build_vector (TREE_TYPE (rhs), nreverse (list));
+ }
if (kind == tcc_reference)
{
*************** fold_gimple_assign (gimple_stmt_iterator
*** 2654,2659 ****
--- 2678,2702 ----
build_fold_addr_expr (tem));
}
+ else if (TREE_CODE (rhs) == CONSTRUCTOR
+ && TREE_CODE (TREE_TYPE (rhs)) == VECTOR_TYPE
+ && (CONSTRUCTOR_NELTS (rhs)
+ == TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs))))
+ {
+ /* Fold a constant vector CONSTRUCTOR to VECTOR_CST. */
+ unsigned i;
+ tree val;
+
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), i, val)
+ if (TREE_CODE (val) != INTEGER_CST
+ && TREE_CODE (val) != REAL_CST
+ && TREE_CODE (val) != FIXED_CST)
+ return NULL_TREE;
+
+ return build_vector_from_ctor (TREE_TYPE (rhs),
+ CONSTRUCTOR_ELTS (rhs));
+ }
+
/* If we couldn't fold the RHS, hand over to the generic
fold routines. */
if (result == NULL_TREE)
More information about the Gcc-patches
mailing list