This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question about simplify_cond_and_lookup_avail_expr
On Nov 24, 2004, at 4:14 PM, Jeffrey A Law wrote:
On Wed, 2004-11-24 at 11:57 -0800, Devang Patel wrote:
Related question, Why do find_equivalent_equality_comparison() only
for
EQ and NE ?
I can't think of a good reason offhand. I might have been
overly paranoid about whether or not we can apply that
tranformation with relational tests.
OK. I am playing with following patch. It allows me to remove few
unnecessary casts that prevents me to auto vectorize SPEC gzip loop.
With this patch, plus couple of other patches not yet in mainline, I am
able to vectorize candidate gzip loop.
I have not polished it to be a real patch and full testing is not yet
complete, but am I on the right track?
Thanks,
-
Devang
* tree-ssa-dom.c (eliminate_unnecessary_casts): New function.
(optimize_stmt): Eliminate unnecessary casts.
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.65
diff -Idpatel.pbxuser -c -3 -p -r2.65 tree-ssa-dom.c
*** tree-ssa-dom.c 30 Oct 2004 12:15:09 -0000 2.65
--- tree-ssa-dom.c 25 Nov 2004 01:43:49 -0000
*************** cprop_into_stmt (tree stmt)
*** 2914,2919 ****
--- 2917,2995 ----
return may_have_exposed_new_symbols;
}
+ /* Remove unnecessary cast.
+ For example,
+ int a;
+ short int s1, s2;
+
+ a = (int) s1;
+ s2 = (short) a;
+ */
+
+ static void
+ eliminate_unnecessary_casts (tree stmt)
+ {
+ tree lhs, rhs;
+ #ifdef ENABLE_CHECKING
+ gcc_assert (stmt);
+ #endif
+
+ if (TREE_CODE (stmt) == COND_EXPR
+ && COMPARISON_CLASS_P (COND_EXPR_COND (stmt)))
+ {
+ tree new_cond = NULL_TREE;
+ tree op0 = TREE_OPERAND (COND_EXPR_COND (stmt), 0);
+ if (op0 && TREE_CODE (op0) == SSA_NAME)
+ new_cond = find_equivalent_equality_comparison (COND_EXPR_COND
(stmt));
+ if (new_cond)
+ {
+ COND_EXPR_COND (stmt) = new_cond;
+ modify_stmt (stmt);
+ return;
+ }
+ }
+
+ if (TREE_CODE (stmt) != MODIFY_EXPR)
+ return;
+
+ lhs = TREE_OPERAND (stmt, 0);
+ rhs = TREE_OPERAND (stmt, 1);
+
+ if ((TREE_CODE (rhs) == NOP_EXPR
+ || TREE_CODE (rhs) == CONVERT_EXPR)
+ && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME)
+ {
+ tree def_stmt, def_rhs, def_lhs;
+
+ def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
+
+ if (TREE_CODE (def_stmt) == MODIFY_EXPR)
+ {
+ def_lhs = TREE_OPERAND (def_stmt, 0);
+ def_rhs = TREE_OPERAND (def_stmt, 1);
+
+ if ((TREE_CODE (def_rhs) == NOP_EXPR
+ || TREE_CODE (def_rhs) == CONVERT_EXPR)
+ && TREE_CODE (TREE_OPERAND (def_rhs, 0)) == SSA_NAME)
+ {
+ tree rhs_inner_type = TREE_TYPE (TREE_OPERAND (def_rhs,
0));
+ tree lhs_type = TREE_TYPE (lhs);
+
+ if (TYPE_PRECISION (rhs_inner_type) == TYPE_PRECISION
(lhs_type)
+ && TYPE_MAIN_VARIANT (rhs_inner_type) ==
TYPE_MAIN_VARIANT (lhs_type))
+ {
+ tree expr = VARRAY_TOP_TREE (avail_exprs_stack);
+
+ TREE_OPERAND (stmt, 1) = TREE_OPERAND (def_rhs, 0);
+ modify_stmt (stmt);
+
+ VARRAY_POP (avail_exprs_stack);
+
+ }
+ }
+ }
+ }
+ }
/* Optimize the statement pointed by iterator SI.
*************** optimize_stmt (struct dom_walk_data *wal
*** 2998,3003 ****
--- 3074,3081 ----
may_have_exposed_new_symbols
|= eliminate_redundant_computations (walk_data, stmt, ann);
+ eliminate_unnecessary_casts (stmt);
+
/* Record any additional equivalences created by this statement. */
if (TREE_CODE (stmt) == MODIFY_EXPR)
record_equivalences_from_stmt (stmt,