summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-math-opts.c
diff options
context:
space:
mode:
authorrearnsha <rearnsha@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-20 12:49:47 +0000
committerrearnsha <rearnsha@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-20 12:49:47 +0000
commit71dbd910de1f77f47f662517e2afddaa77b5c275 (patch)
tree974542ce1cddb8b6e57104203aaa61a2f96f6fcb /gcc/tree-ssa-math-opts.c
parente1ab5f1318dedf3f4caa87617c2e77eac7b6c58b (diff)
downloadgcc-71dbd910de1f77f47f662517e2afddaa77b5c275.tar.gz
PR tree-ssa/54295
* tree-ssa-math-opts.c (widening_mult_conversion_strippable_p): New function. (is_widening_mult_rhs_p): Use it. * gcc.c-torture/execute/20120817-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@190533 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-math-opts.c')
-rw-r--r--gcc/tree-ssa-math-opts.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 0d6eeb69055..748bf2f1e49 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1958,6 +1958,43 @@ struct gimple_opt_pass pass_optimize_bswap =
}
};
+/* Return true if stmt is a type conversion operation that can be stripped
+ when used in a widening multiply operation. */
+static bool
+widening_mult_conversion_strippable_p (tree result_type, gimple stmt)
+{
+ enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
+
+ if (TREE_CODE (result_type) == INTEGER_TYPE)
+ {
+ tree op_type;
+ tree inner_op_type;
+
+ if (!CONVERT_EXPR_CODE_P (rhs_code))
+ return false;
+
+ op_type = TREE_TYPE (gimple_assign_lhs (stmt));
+
+ /* If the type of OP has the same precision as the result, then
+ we can strip this conversion. The multiply operation will be
+ selected to create the correct extension as a by-product. */
+ if (TYPE_PRECISION (result_type) == TYPE_PRECISION (op_type))
+ return true;
+
+ /* We can also strip a conversion if it preserves the signed-ness of
+ the operation and doesn't narrow the range. */
+ inner_op_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
+
+ if (TYPE_UNSIGNED (op_type) == TYPE_UNSIGNED (inner_op_type)
+ && TYPE_PRECISION (op_type) > TYPE_PRECISION (inner_op_type))
+ return true;
+
+ return false;
+ }
+
+ return rhs_code == FIXED_CONVERT_EXPR;
+}
+
/* Return true if RHS is a suitable operand for a widening multiplication,
assuming a target type of TYPE.
There are two cases:
@@ -1982,9 +2019,7 @@ is_widening_mult_rhs_p (tree type, tree rhs, tree *type_out,
if (is_gimple_assign (stmt))
{
rhs_code = gimple_assign_rhs_code (stmt);
- if (TREE_CODE (type) == INTEGER_TYPE
- ? !CONVERT_EXPR_CODE_P (rhs_code)
- : rhs_code != FIXED_CONVERT_EXPR)
+ if (! widening_mult_conversion_strippable_p (type, stmt))
rhs1 = rhs;
else
{