2005-03-11 James A. Morrison <phython@gcc.gnu.org>
+ PR tree-optimization/15784
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
+ and -1 - A to ~A.
+
+ * stmt.c (expand_case): Don't change index_type. Convert minval
+ to the proper type.
+
PR tree-optimization/20130
* fold-const.c (fold): Fold x * -1 into -x.
Revert for now:
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/15784
- * fold-const.c (fold): Fold ~A + 1 to -1. Fold -A - 1
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
and -1 - A to ~A.
2005-03-04 Ben Elliston <bje@au.ibm.com>
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/15784
- * fold-const.c (fold): Fold ~A + 1 to -1. Fold -A - 1
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
and -1 - A to ~A.
2005-03-03 David Edelsohn <edelsohn@gnu.org>
if (TREE_CODE (arg0) == NEGATE_EXPR
&& reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
return fold (build2 (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
+ /* Convert ~A + 1 to -A. */
+ if (INTEGRAL_TYPE_P (type)
+ && TREE_CODE (arg0) == BIT_NOT_EXPR
+ && integer_onep (arg1))
+ return fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0)));
if (TREE_CODE (type) == COMPLEX_TYPE)
{
&& reorder_operands_p (arg0, arg1))
return fold (build2 (MINUS_EXPR, type, negate_expr (arg1),
TREE_OPERAND (arg0, 0)));
+ /* Convert -A - 1 to ~A. */
+ if (INTEGRAL_TYPE_P (type)
+ && TREE_CODE (arg0) == NEGATE_EXPR
+ && integer_onep (arg1))
+ return fold (build1 (BIT_NOT_EXPR, type, TREE_OPERAND (arg0, 0)));
+
+ /* Convert -1 - A to ~A. */
+ if (INTEGRAL_TYPE_P (type)
+ && integer_all_onesp (arg0))
+ return fold (build1 (BIT_NOT_EXPR, type, arg1));
if (TREE_CODE (type) == COMPLEX_TYPE)
{
if (compare_tree_int (minval, 0) > 0
&& compare_tree_int (maxval, GET_MODE_BITSIZE (word_mode)) < 0)
{
- minval = integer_zero_node;
+ minval = fold_convert (index_type, integer_zero_node);
range = maxval;
}
emit_case_bit_tests (index_type, index_expr, minval, range,
table_label, default_label))
{
bool ok;
- index_type = integer_type_node;
/* Index jumptables from zero for suitable values of
minval to avoid a subtraction. */
&& compare_tree_int (minval, 0) > 0
&& compare_tree_int (minval, 3) < 0)
{
- minval = integer_zero_node;
+ minval = fold_convert (index_type, integer_zero_node);
range = maxval;
}