aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c54
1 files changed, 10 insertions, 44 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index fb59049..32de681 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -3741,7 +3741,7 @@ fold_truth_not_expr (tree arg)
case NON_LVALUE_EXPR:
return invert_truthvalue (TREE_OPERAND (arg, 0));
- case NOP_EXPR:
+ CASE_CONVERT:
if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
{
t = build1 (TRUTH_NOT_EXPR, type, arg);
@@ -3750,7 +3750,6 @@ fold_truth_not_expr (tree arg)
/* ... fall through ... */
- case CONVERT_EXPR:
case FLOAT_EXPR:
t = build1 (TREE_CODE (arg), type,
invert_truthvalue (TREE_OPERAND (arg, 0)));
@@ -4694,7 +4693,6 @@ static tree
build_range_check (tree type, tree exp, int in_p, tree low, tree high)
{
tree etype = TREE_TYPE (exp), value;
- enum tree_code code;
#ifdef HAVE_canonicalize_funcptr_for_compare
/* Disable this optimization for function pointer expressions
@@ -4777,35 +4775,14 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high)
}
/* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low).
- This requires wrap-around arithmetics for the type of the expression. */
- code = TREE_CODE (etype);
- switch (code)
- {
- case INTEGER_TYPE:
- case ENUMERAL_TYPE:
- case BOOLEAN_TYPE:
- /* There is no requirement that LOW be within the range of ETYPE
- if the latter is a subtype. It must, however, be within the base
- type of ETYPE. So be sure we do the subtraction in that type. */
- if (code == INTEGER_TYPE && TREE_TYPE (etype))
- {
- etype = TREE_TYPE (etype);
- /* But not in an enumeral or boolean type though. */
- code = TREE_CODE (etype);
- }
+ This requires wrap-around arithmetics for the type of the expression.
+ First make sure that arithmetics in this type is valid, then make sure
+ that it wraps around. */
+ if (TREE_CODE (etype) == ENUMERAL_TYPE || TREE_CODE (etype) == BOOLEAN_TYPE)
+ etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype),
+ TYPE_UNSIGNED (etype));
- if (code != INTEGER_TYPE)
- etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype),
- TYPE_UNSIGNED (etype));
- break;
-
- default:
- break;
- }
-
- /* If we don't have wrap-around arithmetics upfront, try to force it. */
- if (TREE_CODE (etype) == INTEGER_TYPE
- && !TYPE_OVERFLOW_WRAPS (etype))
+ if (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_OVERFLOW_WRAPS (etype))
{
tree utype, minv, maxv;
@@ -7229,11 +7206,6 @@ fold_sign_changed_comparison (enum tree_code code, tree type,
if (TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
return NULL_TREE;
- /* If the conversion is from an integral subtype to its basetype
- leave it alone. */
- if (TREE_TYPE (inner_type) == outer_type)
- return NULL_TREE;
-
if (TREE_CODE (arg1) != INTEGER_CST
&& !(CONVERT_EXPR_P (arg1)
&& TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type))
@@ -8291,9 +8263,7 @@ fold_unary (enum tree_code code, tree type, tree op0)
transformation effectively doesn't preserve non-maximal ranges. */
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (op0) == BIT_AND_EXPR
- && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST
- /* Not if the conversion is to the sub-type. */
- && TREE_TYPE (type) != TREE_TYPE (op0))
+ && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST)
{
tree and = op0;
tree and0 = TREE_OPERAND (and, 0), and1 = TREE_OPERAND (and, 1);
@@ -8410,11 +8380,7 @@ fold_unary (enum tree_code code, tree type, tree op0)
|| POINTER_TYPE_P (type))
&& (INTEGRAL_TYPE_P (TREE_TYPE (op0))
|| POINTER_TYPE_P (TREE_TYPE (op0)))
- && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0))
- /* Do not muck with VIEW_CONVERT_EXPRs that convert from
- a sub-type to its base type as generated by the Ada FE. */
- && !(INTEGRAL_TYPE_P (TREE_TYPE (op0))
- && TREE_TYPE (TREE_TYPE (op0))))
+ && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0)))
return fold_convert (type, op0);
/* Strip inner integral conversions that do not change the precision. */