toolchain: gcc: backport fixes for gcc bug 54295
[openwrt/openwrt.git] / toolchain / gcc / patches / 4.7-linaro / 020-gcc_bug_54295.patch
1 diff -urN a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
2 --- a/gcc/tree-ssa-math-opts.c 2013-03-11 22:01:34.000000000 +0100
3 +++ b/gcc/tree-ssa-math-opts.c 2013-04-29 15:55:34.906809377 +0200
4 @@ -2007,6 +2007,47 @@
5 }
6 };
7
8 +/* Return true if stmt is a type conversion operation that can be stripped
9 + when used in a widening multiply operation. */
10 +static bool
11 +widening_mult_conversion_strippable_p (tree result_type, gimple stmt)
12 +{
13 + enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
14 +
15 + if (TREE_CODE (result_type) == INTEGER_TYPE)
16 + {
17 + tree op_type;
18 + tree inner_op_type;
19 +
20 + if (!CONVERT_EXPR_CODE_P (rhs_code))
21 + return false;
22 +
23 + op_type = TREE_TYPE (gimple_assign_lhs (stmt));
24 +
25 + /* If the type of OP has the same precision as the result, then
26 + we can strip this conversion. The multiply operation will be
27 + selected to create the correct extension as a by-product. */
28 + if (TYPE_PRECISION (result_type) == TYPE_PRECISION (op_type))
29 + return true;
30 +
31 + /* We can also strip a conversion if it preserves the signed-ness of
32 + the operation and doesn't narrow the range. */
33 + inner_op_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
34 +
35 + /* If the inner-most type is unsigned, then we can strip any
36 + intermediate widening operation. If it's signed, then the
37 + intermediate widening operation must also be signed. */
38 + if ((TYPE_UNSIGNED (inner_op_type)
39 + || TYPE_UNSIGNED (op_type) == TYPE_UNSIGNED (inner_op_type))
40 + && TYPE_PRECISION (op_type) > TYPE_PRECISION (inner_op_type))
41 + return true;
42 +
43 + return false;
44 + }
45 +
46 + return rhs_code == FIXED_CONVERT_EXPR;
47 +}
48 +
49 /* Return true if RHS is a suitable operand for a widening multiplication,
50 assuming a target type of TYPE.
51 There are two cases:
52 @@ -2023,17 +2064,13 @@
53 {
54 gimple stmt;
55 tree type1, rhs1;
56 - enum tree_code rhs_code;
57
58 if (TREE_CODE (rhs) == SSA_NAME)
59 {
60 stmt = SSA_NAME_DEF_STMT (rhs);
61 if (is_gimple_assign (stmt))
62 {
63 - rhs_code = gimple_assign_rhs_code (stmt);
64 - if (TREE_CODE (type) == INTEGER_TYPE
65 - ? !CONVERT_EXPR_CODE_P (rhs_code)
66 - : rhs_code != FIXED_CONVERT_EXPR)
67 + if (! widening_mult_conversion_strippable_p (type, stmt))
68 rhs1 = rhs;
69 else
70 {