diff options
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 114 |
1 files changed, 59 insertions, 55 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9be1ceae023..78fb2789d87 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -224,7 +224,7 @@ force_fit_type (tree t, int overflow) /* Unsigned types do not suffer sign extension or overflow unless they are a sizetype. */ - if (TREE_UNSIGNED (TREE_TYPE (t)) + if (TYPE_UNSIGNED (TREE_TYPE (t)) && ! (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE && TYPE_IS_SIZETYPE (TREE_TYPE (t)))) return overflow; @@ -853,7 +853,7 @@ negate_expr_p (tree t) switch (TREE_CODE (t)) { case INTEGER_CST: - if (TREE_UNSIGNED (type) || ! flag_trapv) + if (TYPE_UNSIGNED (type) || ! flag_trapv) return true; /* Check that -CST will not overflow type. */ @@ -897,7 +897,7 @@ negate_expr_p (tree t) TREE_OPERAND (t, 1)); case MULT_EXPR: - if (TREE_UNSIGNED (TREE_TYPE (t))) + if (TYPE_UNSIGNED (TREE_TYPE (t))) break; /* Fall through. */ @@ -962,7 +962,7 @@ negate_expr (tree t) case INTEGER_CST: tem = fold_negate_const (t, type); if (! TREE_OVERFLOW (tem) - || TREE_UNSIGNED (type) + || TYPE_UNSIGNED (type) || ! flag_trapv) return tem; break; @@ -1021,7 +1021,7 @@ negate_expr (tree t) break; case MULT_EXPR: - if (TREE_UNSIGNED (TREE_TYPE (t))) + if (TYPE_UNSIGNED (TREE_TYPE (t))) break; /* Fall through. */ @@ -1077,7 +1077,7 @@ negate_expr (tree t) && (unsigned HOST_WIDE_INT) (TYPE_PRECISION (type) - 1) == TREE_INT_CST_LOW (op1)) { - tree ntype = TREE_UNSIGNED (type) + tree ntype = TYPE_UNSIGNED (type) ? lang_hooks.types.signed_type (type) : lang_hooks.types.unsigned_type (type); tree temp = fold_convert (ntype, TREE_OPERAND (t, 0)); @@ -1241,7 +1241,7 @@ int_const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc) HOST_WIDE_INT garbageh; tree t; tree type = TREE_TYPE (arg1); - int uns = TREE_UNSIGNED (type); + int uns = TYPE_UNSIGNED (type); int is_sizetype = (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type)); int overflow = 0; @@ -1682,7 +1682,7 @@ size_diffop (tree arg0, tree arg1) abort (); /* If the type is already signed, just do the simple thing. */ - if (! TREE_UNSIGNED (type)) + if (!TYPE_UNSIGNED (type)) return size_binop (MINUS_EXPR, arg0, arg1); ctype = (type == bitsizetype || type == ubitsizetype @@ -1751,8 +1751,8 @@ fold_convert_const (enum tree_code code, tree type, tree arg1) TREE_OVERFLOW (t) = ((force_fit_type (t, (TREE_INT_CST_HIGH (arg1) < 0 - && (TREE_UNSIGNED (type) - < TREE_UNSIGNED (TREE_TYPE (arg1))))) + && (TYPE_UNSIGNED (type) + < TYPE_UNSIGNED (TREE_TYPE (arg1))))) && ! POINTER_TYPE_P (TREE_TYPE (arg1))) || TREE_OVERFLOW (arg1)); TREE_CONSTANT_OVERFLOW (t) @@ -2159,10 +2159,14 @@ operand_equal_p (tree arg0, tree arg1, int only_const) { tree fndecl; + /* If either is ERROR_MARK, they aren't equal. */ + if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK) + return 0; + /* If both types don't have the same signedness, then we can't consider them equal. We must check this before the STRIP_NOPS calls because they may change the signedness of the arguments. */ - if (TREE_UNSIGNED (TREE_TYPE (arg0)) != TREE_UNSIGNED (TREE_TYPE (arg1))) + if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1))) return 0; STRIP_NOPS (arg0); @@ -2253,8 +2257,8 @@ operand_equal_p (tree arg0, tree arg1, int only_const) case '1': /* Two conversions are equal only if signedness and modes match. */ if ((TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == CONVERT_EXPR) - && (TREE_UNSIGNED (TREE_TYPE (arg0)) - != TREE_UNSIGNED (TREE_TYPE (arg1)))) + && (TYPE_UNSIGNED (TREE_TYPE (arg0)) + != TYPE_UNSIGNED (TREE_TYPE (arg1)))) return 0; return operand_equal_p (TREE_OPERAND (arg0, 0), @@ -3057,7 +3061,7 @@ decode_field_reference (tree exp, HOST_WIDE_INT *pbitsize, the outer type, then the outer type gives the signedness. Otherwise (in case of a small bitfield) the signedness is unchanged. */ if (outer_type && *pbitsize == tree_low_cst (TYPE_SIZE (outer_type), 1)) - *punsignedp = TREE_UNSIGNED (outer_type); + *punsignedp = TYPE_UNSIGNED (outer_type); /* Compute the mask to access the bitfield. */ unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1); @@ -3377,7 +3381,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh) greater than or equal to zero. We base the range tests we make on that fact, so we record it here so we can parse existing range tests. */ - if (TREE_UNSIGNED (type) && (low == 0 || high == 0)) + if (TYPE_UNSIGNED (type) && (low == 0 || high == 0)) { if (! merge_ranges (&n_in_p, &n_low, &n_high, in_p, low, high, 1, fold_convert (type, integer_zero_node), @@ -3481,7 +3485,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh) So we have to make sure that the original unsigned value will be interpreted as positive. */ - if (TREE_UNSIGNED (type) && ! TREE_UNSIGNED (TREE_TYPE (exp))) + if (TYPE_UNSIGNED (type) && ! TYPE_UNSIGNED (TREE_TYPE (exp))) { tree equiv_type = lang_hooks.types.type_for_mode (TYPE_MODE (type), 1); @@ -3582,7 +3586,7 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) if (integer_zerop (low)) { - if (! TREE_UNSIGNED (etype)) + if (! TYPE_UNSIGNED (etype)) { etype = lang_hooks.types.unsigned_type (etype); high = fold_convert (etype, high); @@ -3612,7 +3616,7 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high) if (TREE_INT_CST_HIGH (high) == hi && TREE_INT_CST_LOW (high) == lo) { - if (TREE_UNSIGNED (etype)) + if (TYPE_UNSIGNED (etype)) { etype = lang_hooks.types.signed_type (etype); exp = fold_convert (etype, exp); @@ -3866,7 +3870,7 @@ unextend (tree c, int p, int unsignedp, tree mask) do the type conversion here. At this point, the constant is either zero or one, and the conversion to a signed type can never overflow. We could get an overflow if this conversion is done anywhere else. */ - if (TREE_UNSIGNED (type)) + if (TYPE_UNSIGNED (type)) temp = fold_convert (lang_hooks.types.signed_type (type), temp); temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1), 0); @@ -3875,7 +3879,7 @@ unextend (tree c, int p, int unsignedp, tree mask) temp = const_binop (BIT_AND_EXPR, temp, fold_convert (TREE_TYPE (c), mask), 0); /* If necessary, convert the type back to match the type of C. */ - if (TREE_UNSIGNED (type)) + if (TYPE_UNSIGNED (type)) temp = fold_convert (type, temp); return fold_convert (type, const_binop (BIT_XOR_EXPR, c, temp, 0)); @@ -4504,7 +4508,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) || TREE_CODE_CLASS (TREE_CODE (op0)) == 'e') /* ... and is unsigned, and its type is smaller than ctype, then we cannot pass through as widening. */ - && ((TREE_UNSIGNED (TREE_TYPE (op0)) + && ((TYPE_UNSIGNED (TREE_TYPE (op0)) && ! (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE && TYPE_IS_SIZETYPE (TREE_TYPE (op0))) && (GET_MODE_SIZE (TYPE_MODE (ctype)) @@ -4516,8 +4520,8 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) /* ... or signedness changes for division or modulus, then we cannot pass through this conversion. */ || (code != MULT_EXPR - && (TREE_UNSIGNED (ctype) - != TREE_UNSIGNED (TREE_TYPE (op0)))))) + && (TYPE_UNSIGNED (ctype) + != TYPE_UNSIGNED (TREE_TYPE (op0)))))) break; /* Pass the constant down and see if we can make a simplification. If @@ -4540,7 +4544,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) case MIN_EXPR: case MAX_EXPR: /* If widening the type changes the signedness, then we can't perform this optimization as that changes the result. */ - if (TREE_UNSIGNED (ctype) != TREE_UNSIGNED (type)) + if (TYPE_UNSIGNED (ctype) != TYPE_UNSIGNED (type)) break; /* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */ @@ -4631,7 +4635,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) /* If we have an unsigned type is not a sizetype, we cannot widen the operation since it will change the result if the original computation overflowed. */ - if (TREE_UNSIGNED (ctype) + if (TYPE_UNSIGNED (ctype) && ! (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype)) && ctype != type) break; @@ -4696,7 +4700,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) If we have an unsigned type that is not a sizetype, we cannot do this since it will change the result if the original computation overflowed. */ - if ((! TREE_UNSIGNED (ctype) + if ((! TYPE_UNSIGNED (ctype) || (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype))) && ! flag_wrapv && ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR) @@ -5631,17 +5635,17 @@ fold (tree expr) int inside_ptr = POINTER_TYPE_P (inside_type); int inside_float = FLOAT_TYPE_P (inside_type); unsigned int inside_prec = TYPE_PRECISION (inside_type); - int inside_unsignedp = TREE_UNSIGNED (inside_type); + int inside_unsignedp = TYPE_UNSIGNED (inside_type); int inter_int = INTEGRAL_TYPE_P (inter_type); int inter_ptr = POINTER_TYPE_P (inter_type); int inter_float = FLOAT_TYPE_P (inter_type); unsigned int inter_prec = TYPE_PRECISION (inter_type); - int inter_unsignedp = TREE_UNSIGNED (inter_type); + int inter_unsignedp = TYPE_UNSIGNED (inter_type); int final_int = INTEGRAL_TYPE_P (type); int final_ptr = POINTER_TYPE_P (type); int final_float = FLOAT_TYPE_P (type); unsigned int final_prec = TYPE_PRECISION (type); - int final_unsignedp = TREE_UNSIGNED (type); + int final_unsignedp = TYPE_UNSIGNED (type); /* In addition to the cases of two conversions in a row handled below, if we are converting something to its own @@ -5733,7 +5737,7 @@ fold (tree expr) tree and0 = TREE_OPERAND (and, 0), and1 = TREE_OPERAND (and, 1); int change = 0; - if (TREE_UNSIGNED (TREE_TYPE (and)) + if (TYPE_UNSIGNED (TREE_TYPE (and)) || (TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (and)))) change = 1; @@ -6087,7 +6091,7 @@ fold (tree expr) || (code1 == RSHIFT_EXPR && code0 == LSHIFT_EXPR)) && operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0) - && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) + && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) { tree tree01, tree11; enum tree_code code01, code11; @@ -6668,7 +6672,7 @@ fold (tree expr) return t1; /* Simplify ((int)c & 0377) into (int)c, if c is unsigned char. */ if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR - && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) + && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0)))) { unsigned int prec = TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0))); @@ -6938,7 +6942,7 @@ fold (tree expr) case RSHIFT_EXPR: /* Optimize -1 >> x for arithmetic right shifts. */ - if (integer_all_onesp (arg0) && ! TREE_UNSIGNED (type)) + if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type)) return omit_one_operand (type, arg0, arg1); /* ... fall through ... */ @@ -7413,7 +7417,7 @@ fold (tree expr) signed_max = ((unsigned HOST_WIDE_INT) 1 << (width - 1)) - 1; - if (TREE_UNSIGNED (TREE_TYPE (arg1))) + if (TYPE_UNSIGNED (TREE_TYPE (arg1))) { max = ((unsigned HOST_WIDE_INT) 2 << (width - 1)) - 1; min = 0; @@ -7502,7 +7506,7 @@ fold (tree expr) else if (TREE_INT_CST_HIGH (arg1) == 0 && TREE_INT_CST_LOW (arg1) == signed_max - && TREE_UNSIGNED (TREE_TYPE (arg1)) + && TYPE_UNSIGNED (TREE_TYPE (arg1)) /* signed_type does not work on pointer types. */ && INTEGRAL_TYPE_P (TREE_TYPE (arg1))) { @@ -7559,8 +7563,8 @@ fold (tree expr) && TREE_CODE (arg0) == NOP_EXPR && (tem = get_unwidened (arg0, NULL_TREE)) != arg0 && (code == EQ_EXPR || code == NE_EXPR - || TREE_UNSIGNED (TREE_TYPE (arg0)) - == TREE_UNSIGNED (TREE_TYPE (tem))) + || TYPE_UNSIGNED (TREE_TYPE (arg0)) + == TYPE_UNSIGNED (TREE_TYPE (tem))) && (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0 && (TREE_TYPE (t1) == TREE_TYPE (tem) || (TREE_CODE (t1) == INTEGER_CST @@ -7631,7 +7635,7 @@ fold (tree expr) the MOD operation unsigned since it is simpler and equivalent. */ if ((code == NE_EXPR || code == EQ_EXPR) && integer_zerop (arg1) - && ! TREE_UNSIGNED (TREE_TYPE (arg0)) + && !TYPE_UNSIGNED (TREE_TYPE (arg0)) && (TREE_CODE (arg0) == TRUNC_MOD_EXPR || TREE_CODE (arg0) == CEIL_MOD_EXPR || TREE_CODE (arg0) == FLOOR_MOD_EXPR @@ -7706,7 +7710,7 @@ fold (tree expr) /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0 and similarly for >= into !=. */ if ((code == LT_EXPR || code == GE_EXPR) - && TREE_UNSIGNED (TREE_TYPE (arg0)) + && TYPE_UNSIGNED (TREE_TYPE (arg0)) && TREE_CODE (arg1) == LSHIFT_EXPR && integer_onep (TREE_OPERAND (arg1, 0))) return build (code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, @@ -7715,7 +7719,7 @@ fold (tree expr) fold_convert (TREE_TYPE (arg0), integer_zero_node)); else if ((code == LT_EXPR || code == GE_EXPR) - && TREE_UNSIGNED (TREE_TYPE (arg0)) + && TYPE_UNSIGNED (TREE_TYPE (arg0)) && (TREE_CODE (arg1) == NOP_EXPR || TREE_CODE (arg1) == CONVERT_EXPR) && TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR @@ -8001,14 +8005,14 @@ fold (tree expr) return pedantic_non_lvalue (fold_convert (type, arg1)); case GE_EXPR: case GT_EXPR: - if (TREE_UNSIGNED (TREE_TYPE (arg1))) + if (TYPE_UNSIGNED (TREE_TYPE (arg1))) arg1 = fold_convert (lang_hooks.types.signed_type (TREE_TYPE (arg1)), arg1); arg1 = fold (build1 (ABS_EXPR, TREE_TYPE (arg1), arg1)); return pedantic_non_lvalue (fold_convert (type, arg1)); case LE_EXPR: case LT_EXPR: - if (TREE_UNSIGNED (TREE_TYPE (arg1))) + if (TYPE_UNSIGNED (TREE_TYPE (arg1))) arg1 = fold_convert (lang_hooks.types.signed_type (TREE_TYPE (arg1)), arg1); arg1 = fold (build1 (ABS_EXPR, TREE_TYPE (arg1), arg1)); @@ -8655,7 +8659,7 @@ multiple_of_p (tree type, tree top, tree bottom) case INTEGER_CST: if (TREE_CODE (bottom) != INTEGER_CST - || (TREE_UNSIGNED (type) + || (TYPE_UNSIGNED (type) && (tree_int_cst_sgn (top) < 0 || tree_int_cst_sgn (bottom) < 0))) return 0; @@ -8696,8 +8700,8 @@ tree_expr_nonnegative_p (tree t) { tree inner1 = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)); tree inner2 = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)); - if (TREE_CODE (inner1) == INTEGER_TYPE && TREE_UNSIGNED (inner1) - && TREE_CODE (inner2) == INTEGER_TYPE && TREE_UNSIGNED (inner2)) + if (TREE_CODE (inner1) == INTEGER_TYPE && TYPE_UNSIGNED (inner1) + && TREE_CODE (inner2) == INTEGER_TYPE && TYPE_UNSIGNED (inner2)) { unsigned int prec = MAX (TYPE_PRECISION (inner1), TYPE_PRECISION (inner2)) + 1; @@ -8724,8 +8728,8 @@ tree_expr_nonnegative_p (tree t) { tree inner1 = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)); tree inner2 = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (t, 1), 0)); - if (TREE_CODE (inner1) == INTEGER_TYPE && TREE_UNSIGNED (inner1) - && TREE_CODE (inner2) == INTEGER_TYPE && TREE_UNSIGNED (inner2)) + if (TREE_CODE (inner1) == INTEGER_TYPE && TYPE_UNSIGNED (inner1) + && TREE_CODE (inner2) == INTEGER_TYPE && TYPE_UNSIGNED (inner2)) return TYPE_PRECISION (inner1) + TYPE_PRECISION (inner2) < TYPE_PRECISION (TREE_TYPE (t)); } @@ -8767,7 +8771,7 @@ tree_expr_nonnegative_p (tree t) return tree_expr_nonnegative_p (TREE_OPERAND (t, 0)); if (TREE_CODE (inner_type) == INTEGER_TYPE) { - if (TREE_UNSIGNED (inner_type)) + if (TYPE_UNSIGNED (inner_type)) return 1; return tree_expr_nonnegative_p (TREE_OPERAND (t, 0)); } @@ -8778,7 +8782,7 @@ tree_expr_nonnegative_p (tree t) return tree_expr_nonnegative_p (TREE_OPERAND (t,0)); if (TREE_CODE (inner_type) == INTEGER_TYPE) return TYPE_PRECISION (inner_type) < TYPE_PRECISION (outer_type) - && TREE_UNSIGNED (inner_type); + && TYPE_UNSIGNED (inner_type); } } break; @@ -8916,14 +8920,14 @@ tree_expr_nonzero_p (tree t) switch (TREE_CODE (t)) { case ABS_EXPR: - if (!TREE_UNSIGNED (type) && !flag_wrapv) + if (!TYPE_UNSIGNED (type) && !flag_wrapv) return tree_expr_nonzero_p (TREE_OPERAND (t, 0)); case INTEGER_CST: return !integer_zerop (t); case PLUS_EXPR: - if (!TREE_UNSIGNED (type) && !flag_wrapv) + if (!TYPE_UNSIGNED (type) && !flag_wrapv) { /* With the presence of negative values it is hard to say something. */ @@ -8937,7 +8941,7 @@ tree_expr_nonzero_p (tree t) break; case MULT_EXPR: - if (!TREE_UNSIGNED (type) && !flag_wrapv) + if (!TYPE_UNSIGNED (type) && !flag_wrapv) { return (tree_expr_nonzero_p (TREE_OPERAND (t, 0)) && tree_expr_nonzero_p (TREE_OPERAND (t, 1))); @@ -9068,7 +9072,7 @@ fold_negate_const (tree arg0, tree type) TREE_TYPE (t) = type; TREE_OVERFLOW (t) = (TREE_OVERFLOW (arg0) - | force_fit_type (t, overflow && !TREE_UNSIGNED (type))); + | force_fit_type (t, overflow && !TYPE_UNSIGNED (type))); TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0); } @@ -9096,7 +9100,7 @@ fold_abs_const (tree arg0, tree type) { /* If the value is unsigned, then the absolute value is the same as the ordinary value. */ - if (TREE_UNSIGNED (type)) + if (TYPE_UNSIGNED (type)) return arg0; /* Similarly, if the value is non-negative. */ else if (INT_CST_LT (integer_minus_one_node, arg0)) @@ -9180,7 +9184,7 @@ fold_relational_const (enum tree_code code, tree type, tree op0, tree op1) if (code == EQ_EXPR) tem = build_int_2 (tree_int_cst_equal (op0, op1), 0); else - tem = build_int_2 ((TREE_UNSIGNED (TREE_TYPE (op0)) + tem = build_int_2 ((TYPE_UNSIGNED (TREE_TYPE (op0)) ? INT_CST_LT_UNSIGNED (op0, op1) : INT_CST_LT (op0, op1)), 0); |