aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.8/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.8/gcc/fold-const.c')
-rw-r--r--gcc-4.8/gcc/fold-const.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/gcc-4.8/gcc/fold-const.c b/gcc-4.8/gcc/fold-const.c
index 6dc8934f3..3a60201e2 100644
--- a/gcc-4.8/gcc/fold-const.c
+++ b/gcc-4.8/gcc/fold-const.c
@@ -461,8 +461,6 @@ negate_expr_p (tree t)
case TRUNC_DIV_EXPR:
case ROUND_DIV_EXPR:
- case FLOOR_DIV_EXPR:
- case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
/* In general we can't negate A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
@@ -644,8 +642,6 @@ fold_negate_expr (location_t loc, tree t)
case TRUNC_DIV_EXPR:
case ROUND_DIV_EXPR:
- case FLOOR_DIV_EXPR:
- case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
/* In general we can't negate A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
@@ -2664,10 +2660,11 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
case COMPONENT_REF:
/* Handle operand 2 the same as for ARRAY_REF. Operand 0
may be NULL when we're called to compare MEM_EXPRs. */
- if (!OP_SAME_WITH_NULL (0))
+ if (!OP_SAME_WITH_NULL (0)
+ || !OP_SAME (1))
return 0;
flags &= ~OEP_CONSTANT_ADDRESS_OF;
- return OP_SAME (1) && OP_SAME_WITH_NULL (2);
+ return OP_SAME_WITH_NULL (2);
case BIT_FIELD_REF:
if (!OP_SAME (0))
@@ -4920,12 +4917,16 @@ fold_range_test (location_t loc, enum tree_code code, tree type,
int in0_p, in1_p, in_p;
tree low0, low1, low, high0, high1, high;
bool strict_overflow_p = false;
- tree lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
- tree rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
- tree tem;
+ tree tem, lhs, rhs;
const char * const warnmsg = G_("assuming signed overflow does not occur "
"when simplifying range test");
+ if (!INTEGRAL_TYPE_P (type))
+ return 0;
+
+ lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
+ rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
+
/* If this is an OR operation, invert both sides; we will invert
again at the end. */
if (or_op)
@@ -10927,6 +10928,13 @@ fold_binary_loc (location_t loc,
fold_build2_loc (loc, MULT_EXPR, type,
build_int_cst (type, 2) , arg1));
+ /* ((T) (X /[ex] C)) * C cancels out if the conversion is
+ sign-changing only. */
+ if (TREE_CODE (arg1) == INTEGER_CST
+ && TREE_CODE (arg0) == EXACT_DIV_EXPR
+ && operand_equal_p (arg1, TREE_OPERAND (arg0, 1), 0))
+ return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,
@@ -16587,7 +16595,7 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
tree index = bitsize_int (indexi);
- if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (op00type))
+ if (offset / part_widthi < TYPE_VECTOR_SUBPARTS (op00type))
return fold_build3_loc (loc,
BIT_FIELD_REF, type, op00,
part_width, index);