aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1999-10-31 20:11:22 -0500
committerRichard Kenner <kenner@gcc.gnu.org>1999-10-31 20:11:22 -0500
commit14a774a9d22db91fb6387cb8eb61060b61782f29 (patch)
tree58ab23a2ebe35102f1a66447caaf4626bb2b4641 /gcc/fold-const.c
parent8f65050e4185eaed8aa074387c3db51955ac806b (diff)
downloadgcc-14a774a9d22db91fb6387cb8eb61060b61782f29.zip
gcc-14a774a9d22db91fb6387cb8eb61060b61782f29.tar.gz
gcc-14a774a9d22db91fb6387cb8eb61060b61782f29.tar.bz2
[multiple changes]
Fri Oct 29 15:25:07 1999 Arnaud Charlet <charlet@ACT-Europe.FR> * gcov.c (DIR_SEPARATOR): Provide default. (output_data): Add test for MS-DOS format absolute filename. (fancy_abort): Correct program name. (open_files): Open all files in binary mode. * libgcc2.c (__bb_exit_func): Likewise. * profile.c (init_branch_prob): Specify binary when opening files. * flags.h (flag_unwind_tables): New decl. * toplev.c (flag_unwind_table): New definition. (f_options): Add -funwind-tables. (decode_g_option): Clarify warning when unknown -g option is given. (rest_of_compilation): If inside an inlined external function, pretend we are just being declared. * dwarf2out.c (dwarf2out_do_frame): Check -funwind_tables. (dwarf2out_frame_finish): Likewise. Fri Oct 29 06:32:44 1999 Geoffrey Keating <geoffk@cygnus.com> * flow.c (propagate_block): When the last reference to a label before an ADDR_VEC is deleted because the reference is a dead store, delete the ADDR_VEC. Fri Oct 29 07:44:26 1999 Vasco Pedro <vp@di.fct.unl.pt> * fold-const.c (merge_ranges): In not in0, but in1, handle upper bounds equal like subset case. Thu Oct 28 19:22:24 1999 Douglas Rupp <rupp@gnat.com> * dbxout.c (dbxout_parms): Generate a second stabs line for parameters passed in a register but moved to the stack. Thu Oct 28 19:12:57 1999 Sam Tardieu <tardieu@act-europe.fr> * gcc.c (pass_exit_codes, greatest_status): New variables. (struct option_map): Add entry for "--pass-exit-codes". (execute): Update greatest_status if error. (display_help): Add documentation for -pass-exit-codes. (process_command): Handle -pass-exit-codes. (main): Look at pass_exit_codes and greatest_status on call to exit. Thu Oct 28 18:06:50 1999 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * reload.c (find_reloads): Refine test for no input reload case to not includes reloads emitted after insn. * function.c (find_temp_slots_from_address): Handle sum involving a register that points to a temp slot. (update_temp_slot_address): Make recursive call if both old and new are PLUS with a common operand. * calls.c (expand_call): Mark temp slot for result as having address taken. * rtlanal.c (reg_referenced_p, case IF_THEN_ELSE): New case. * gcc.c (process_command): Add standard_exec_prefix with "GCC" component as well as "BINUTILS". * integrate.h (copy_rtx_and_substitute): New arg, FOR_LHS. * integrate.c (copy_rtx_and_substitute): Likewise. (expand_inline_function, integrate_parm_decls, integrate_decl_tree): All callers changed. * unroll.c (inital_reg_note_copy, copy_loop_body): Likewise. * dbxout.c (dbxout_type, case INTEGER_TYPE_NODE): If can use gdb extensions, write size of type; also be more consistent in using references when this is a subtype. * pa.md (extv, extzv, insv): Use define_expand to reject constant that is out of range. * loop.c (unknown_constant_address_altered): New variable. (prescan_loop): Initialize it. (note_addr_stored): Set it for RTX_UNCHANGING_P MEM. (invariant_p, case MEM): Remove handling for volatile and readony; check new variable if readonly. (check_dbra_loop): Chdeck unknown_constant_address_altered. * cse.c (canon_hash, case MEM): Do not record if BLKmode. (addr_affects_sp_p): Removed from note_mem_written and only define #ifdef AUTO_INC_DEC. * alpha.c (input_operand, case ADDRESSOF): Treat as REG. * regclass.c (record_reg_classes): Properly handle register move directions. * varasm.c (initializer_constant_valid_p, case MINUS_EXPR): Don't think valid if both operands are invalid. (struct constant_descriptor): New field RTL. (mark_const_hash_entry): Mark it. (record_constant{,_rtx}): Initialize it. (output_constant_def): Allocate RTL in permanent obstack and save in table. ({record,compare}_constant_1): Modes must match for CONSTRUCTOR of ARRAY_TYPE. * c-common.h (initializer_constant_valid_p): Delete decl from here. * output.h (initializer_constant_valid_p): Move decl to here. * c-common.c (initializer_constant_valid_p): Delete function from here. * varasm.c (initializer_constant_valid_p): Move function to here. * tree.h (STRIP_SIGN_NOPS): New macro. * fold-const.c (optimize_minmax_comparison): New function. (invert_truthvalue, case WITH_RECORD_EXPR): New case. (fold): Use STRIP_SIGN_NOPS instead of STRIP_TYPE_NOPS. (fold, case EQ_EXPR): Call optimize_minmax_comparison and add cases with ABS_EXPR, NEGATE_EXPR, PLUS_EXPR, MINUS_EXPR, and widening conversions. (fold, case LE_EXPR): Rework changing unsigned to signed comparisons to look at size of mode, not precision of type; also add missing cases. (optimize_bit_field_compare, decode_field_reference): Don't try to optimize COMPONENT_REF of a PLACEHOLDER_EXPR. * dwarf2out.c (ctype.h): Include. (dwarf2out_set_demangle_name_func): New function. (size_of_line_info): Deleted. (output_line_info): Compute size of line info table from difference of labels. (base_type_die, add_name_attribute): Call demangle function, if any. (field_byte_offset): Use bits per word for variable length fields. (gen_array_type_die): Add array name. (gen_subprogram_die): Ignore DECL_INLINE if -fno-inline. (dwarf2out_add_library_unit_info): New function. * explow.c (set_stack_check_libfunc): New function. (stack_check_libfunc): New static variable. (probe_stack_range): Allow front-end to set up a libfunc to call. * combine.c (simplify_comparison): When making comparison in wider mode, check for having commuted an AND and a SUBREG. (contains_muldiv): New function. (try_combine): Call it when dividing a PARALLEL. (simplify_rtx, case TRUNCATE): Don't remove for umulsi3_highpart. (simplify_comparison, case ASHIFTRT): Recognize sign-extension of a PLUS. (record_value_for_reg): If TEM is a binary operation with two CLOBBERs, use one of the CLOBBERs instead. (if_then_else_cond): If comparing against zero, just return thing being compared. * optabs.c (expand_abs): If machine has MAX, ABS (x) is MAX (x, -x). Don't generate shifts and subtract if have conditional arithmetic. * rtl.h (delete_barrier): New declaration. * jump.c (jump_optimize): Set up to handle conditional call. In conditional arithmetic case, handle CALL_INSN followed by a BARRIER. (delete_barrier): New function. * rtl.c (read_rtx): Call fatal if bad RTL code; check for bad mode. * recog.c (nonmemory_operand): Accept ADDRESSOF. * tree.c (build_type_attribute_variant): Push to obstack of ttype around type_hash_canon call. * expr.c (placeholder_list): Move decl to file scope. (expand_expr): Don't force access to volatile just because its address is taken. If ignoring reference operations, just expand the operands. (expand_expr, case COMPONENT_REF): Propagate EXPAND_CONST_ADDRESS to recursive call when expanding inner. Refine test for using bitfield operations vs pointer punning. (expand_expr, case CONVERT_EXPR): If converting to BLKmode UNION_TYPE from BLKmode, just return inner object. Use proper mode in store_field call. Properly set sizes of object to store and total size in store_field call for convert to union. (expand_expr, case ARRAY_REF): If OP0 is in a register, put it in memory (like for ADDR_EXPR). Also, don't put constant in register if we'll want it in memory. (readonly_fields_p): New function. (expand_expr, case INDIRECT_REF): Call it if LHS. (expand_assignment): Handle a RESULT_DECL where DECL_RTL is a PARALLEL. (do_jump, case WITH_RECORD_EXPR): New case. (get_inner_reference): Always go inside a CONVERT_EXPR and NOP_EXPR if both modes are the same. (store_field): Use bitfield operations if size of bitsize is not same as size of RHS's type. Check for bitpos not a multiple of alignment in BLKmode case. Do block move in largest possible alignment. (store_constructor): Set BITSIZE to -1 for variable size and properly in case of array of BLKmode. (expand_expr_unaligned): New function. (do_compare_and_jump): Call it. * mips/iris5.h (SWITCHES_NEED_SPACES): New macro. * collect2.c (main): Only allow -ofoo if SWITCHES_NEED_SPACES does not include 'o'. * function.c (instantiate_virtual_regs_1, case SET): Handle case where both SET_DEST and SET_SRC reference a virtual register. (gen_mem_addressof): Copy RTX_UNCHANGING_P from new REG to old REG. * integrate.c (expand_inline_function): Handle case of setting virtual stack vars register (from built in setjmp); when parameter lives in memory, expand virtual_{stack_vars,incoming_args}_rtx early. (subst_constant): Add new parm, MEMONLY. (expand_inline_function, integrate_parm_decls): Pass new parm. (integrate_decl_tree): Likewise. (copy_rtx_and_substitute, case MEM): Do copy RTX_UNCHANGING_P. (try_constants): Call subst_constants twice, with MEMONLY 0 and 1. (copy_rtx_and_substitute, case SET): Add explicit calls to copy_rtx_and_substitute for both sides. * stmt.c (expand_asm_operands): Don't use TREE_STRING_LENGTH for constraints. (pushcase{,_range}): Convert to NOMINAL_TYPE after checking for within INDEX_TYPE, instead of before. (fixup_gotos): Use f->target_rtl, not the next insn, since latter may be from a later fixup. (expand_value_return): Correctly convert VAL when promoting function return; support RETURN_REG being a PARALLEL. (expand_return): When checking for result in regs and having cleanup, consider PARALLEL in DECL_RTL as being in regs. From-SVN: r30299
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c308
1 files changed, 270 insertions, 38 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 49f61b8..b93f49e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -92,6 +92,7 @@ static int merge_ranges PROTO((int *, tree *, tree *, int, tree, tree,
static tree fold_range_test PROTO((tree));
static tree unextend PROTO((tree, int, int, tree));
static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
+static tree optimize_minmax_comparison PROTO((tree));
static tree strip_compound_expr PROTO((tree, tree));
static int multiple_of_p PROTO((tree, tree, tree));
static tree constant_boolean_node PROTO((int, tree));
@@ -2585,6 +2586,11 @@ invert_truthvalue (arg)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0),
invert_truthvalue (TREE_OPERAND (arg, 1)));
+ case WITH_RECORD_EXPR:
+ return build (WITH_RECORD_EXPR, type,
+ invert_truthvalue (TREE_OPERAND (arg, 0)),
+ TREE_OPERAND (arg, 1));
+
case NON_LVALUE_EXPR:
return invert_truthvalue (TREE_OPERAND (arg, 0));
@@ -2728,11 +2734,13 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
/* Get all the information about the extractions being done. If the bit size
if the same as the size of the underlying object, we aren't doing an
- extraction at all and so can do nothing. */
+ extraction at all and so can do nothing. We also don't want to
+ do anything if the inner expression is a PLACEHOLDER_EXPR since we
+ then will no longer be able to replace it. */
linner = get_inner_reference (lhs, &lbitsize, &lbitpos, &offset, &lmode,
&lunsignedp, &lvolatilep, &alignment);
if (linner == lhs || lbitsize == GET_MODE_BITSIZE (lmode) || lbitsize < 0
- || offset != 0)
+ || offset != 0 || TREE_CODE (linner) == PLACEHOLDER_EXPR)
return 0;
if (!const_p)
@@ -2743,7 +2751,8 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs)
&runsignedp, &rvolatilep, &alignment);
if (rinner == rhs || lbitpos != rbitpos || lbitsize != rbitsize
- || lunsignedp != runsignedp || offset != 0)
+ || lunsignedp != runsignedp || offset != 0
+ || TREE_CODE (rinner) == PLACEHOLDER_EXPR)
return 0;
}
@@ -2936,7 +2945,8 @@ decode_field_reference (exp, pbitsize, pbitpos, pmode, punsignedp,
inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode,
punsignedp, pvolatilep, &alignment);
if ((inner == exp && and_mask == 0)
- || *pbitsize < 0 || offset != 0)
+ || *pbitsize < 0 || offset != 0
+ || TREE_CODE (inner) == PLACEHOLDER_EXPR)
return 0;
/* Compute the mask to access the bitfield. */
@@ -3305,15 +3315,11 @@ make_range (exp, pin_p, plow, phigh)
/* A range without an upper bound is, naturally, unbounded.
Since convert would have cropped a very large value, use
- the max value for the destination type. */
+ the max value for the destination type. */
+ high_positive
+ = TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
+ : TYPE_MAX_VALUE (type);
- high_positive = TYPE_MAX_VALUE (equiv_type);
- if (!high_positive)
- {
- high_positive = TYPE_MAX_VALUE (type);
- if (!high_positive)
- abort();
- }
high_positive = fold (build (RSHIFT_EXPR, type,
convert (type, high_positive),
convert (type, integer_one_node)));
@@ -3517,7 +3523,7 @@ merge_ranges (pin_p, plow, phigh, in0_p, low0, high0, in1_p, low1, high1)
end of the second. */
if (no_overlap)
in_p = 1, low = low1, high = high1;
- else if (subset)
+ else if (subset || highequal)
in_p = 0, low = high = 0;
else
{
@@ -4051,6 +4057,103 @@ fold_truthop (code, truth_type, lhs, rhs)
const_binop (BIT_IOR_EXPR, l_const, r_const, 0));
}
+/* Optimize T, which is a comparison of a MIN_EXPR or MAX_EXPR with a
+ constant. */
+
+static tree
+optimize_minmax_comparison (t)
+ tree t;
+{
+ tree type = TREE_TYPE (t);
+ tree arg0 = TREE_OPERAND (t, 0);
+ enum tree_code op_code;
+ tree comp_const = TREE_OPERAND (t, 1);
+ tree minmax_const;
+ int consts_equal, consts_lt;
+ tree inner;
+
+ STRIP_SIGN_NOPS (arg0);
+
+ op_code = TREE_CODE (arg0);
+ minmax_const = TREE_OPERAND (arg0, 1);
+ consts_equal = tree_int_cst_equal (minmax_const, comp_const);
+ consts_lt = tree_int_cst_lt (minmax_const, comp_const);
+ inner = TREE_OPERAND (arg0, 0);
+
+ /* If something does not permit us to optimize, return the original tree. */
+ if ((op_code != MIN_EXPR && op_code != MAX_EXPR)
+ || TREE_CODE (comp_const) != INTEGER_CST
+ || TREE_CONSTANT_OVERFLOW (comp_const)
+ || TREE_CODE (minmax_const) != INTEGER_CST
+ || TREE_CONSTANT_OVERFLOW (minmax_const))
+ return t;
+
+ /* Now handle all the various comparison codes. We only handle EQ_EXPR
+ and GT_EXPR, doing the rest with recursive calls using logical
+ simplifications. */
+ switch (TREE_CODE (t))
+ {
+ case NE_EXPR: case LT_EXPR: case LE_EXPR:
+ return
+ invert_truthvalue (optimize_minmax_comparison (invert_truthvalue (t)));
+
+ case GE_EXPR:
+ return
+ fold (build (TRUTH_ORIF_EXPR, type,
+ optimize_minmax_comparison
+ (build (EQ_EXPR, type, arg0, comp_const)),
+ optimize_minmax_comparison
+ (build (GT_EXPR, type, arg0, comp_const))));
+
+ case EQ_EXPR:
+ if (op_code == MAX_EXPR && consts_equal)
+ /* MAX (X, 0) == 0 -> X <= 0 */
+ return fold (build (LE_EXPR, type, inner, comp_const));
+
+ else if (op_code == MAX_EXPR && consts_lt)
+ /* MAX (X, 0) == 5 -> X == 5 */
+ return fold (build (EQ_EXPR, type, inner, comp_const));
+
+ else if (op_code == MAX_EXPR)
+ /* MAX (X, 0) == -1 -> false */
+ return omit_one_operand (type, integer_zero_node, inner);
+
+ else if (consts_equal)
+ /* MIN (X, 0) == 0 -> X >= 0 */
+ return fold (build (GE_EXPR, type, inner, comp_const));
+
+ else if (consts_lt)
+ /* MIN (X, 0) == 5 -> false */
+ return omit_one_operand (type, integer_zero_node, inner);
+
+ else
+ /* MIN (X, 0) == -1 -> X == -1 */
+ return fold (build (EQ_EXPR, type, inner, comp_const));
+
+ case GT_EXPR:
+ if (op_code == MAX_EXPR && (consts_equal || consts_lt))
+ /* MAX (X, 0) > 0 -> X > 0
+ MAX (X, 0) > 5 -> X > 5 */
+ return fold (build (GT_EXPR, type, inner, comp_const));
+
+ else if (op_code == MAX_EXPR)
+ /* MAX (X, 0) > -1 -> true */
+ return omit_one_operand (type, integer_one_node, inner);
+
+ else if (op_code == MIN_EXPR && (consts_equal || consts_lt))
+ /* MIN (X, 0) > 0 -> false
+ MIN (X, 0) > 5 -> false */
+ return omit_one_operand (type, integer_zero_node, inner);
+
+ else
+ /* MIN (X, 0) > -1 -> X > -1 */
+ return fold (build (GT_EXPR, type, inner, comp_const));
+
+ default:
+ return t;
+ }
+}
+
/* If T contains a COMPOUND_EXPR which was inserted merely to evaluate
S, a SAVE_EXPR, return the expression actually being evaluated. Note
that we may sometimes modify the tree. */
@@ -4182,7 +4285,7 @@ fold (expr)
/* Don't use STRIP_NOPS, because signedness of argument type matters. */
if (arg0 != 0)
- STRIP_TYPE_NOPS (arg0);
+ STRIP_SIGN_NOPS (arg0);
if (arg0 != 0 && TREE_CODE (arg0) == COMPLEX_CST)
subop = TREE_REALPART (arg0);
@@ -4216,7 +4319,7 @@ fold (expr)
{
/* Signedness matters here. Perhaps we can refine this
later. */
- STRIP_TYPE_NOPS (op);
+ STRIP_SIGN_NOPS (op);
}
else
{
@@ -5925,6 +6028,76 @@ fold (expr)
}
}
+ /* If this is an EQ or NE comparison of a constant with a PLUS_EXPR or
+ a MINUS_EXPR of a constant, we can convert it into a comparison with
+ a revised constant as long as no overflow occurs. */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && TREE_CODE (arg1) == INTEGER_CST
+ && (TREE_CODE (arg0) == PLUS_EXPR
+ || TREE_CODE (arg0) == MINUS_EXPR)
+ && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
+ && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
+ ? MINUS_EXPR : PLUS_EXPR,
+ arg1, TREE_OPERAND (arg0, 1), 0))
+ && ! TREE_CONSTANT_OVERFLOW (tem))
+ return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
+
+ /* Similarly for a NEGATE_EXPR. */
+ else if ((code == EQ_EXPR || code == NE_EXPR)
+ && TREE_CODE (arg0) == NEGATE_EXPR
+ && TREE_CODE (arg1) == INTEGER_CST
+ && 0 != (tem = fold (build1 (NEGATE_EXPR, TREE_TYPE (arg1),
+ arg1)))
+ && TREE_CODE (tem) == INTEGER_CST
+ && ! TREE_CONSTANT_OVERFLOW (tem))
+ return fold (build (code, type, TREE_OPERAND (arg0, 0), tem));
+
+ /* If we have X - Y == 0, we can convert that to X == Y and similarly
+ for !=. Don't do this for ordered comparisons due to overflow. */
+ else if ((code == NE_EXPR || code == EQ_EXPR)
+ && integer_zerop (arg1) && TREE_CODE (arg0) == MINUS_EXPR)
+ return fold (build (code, type,
+ TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1)));
+
+ /* If we are widening one operand of an integer comparison,
+ see if the other operand is similarly being widened. Perhaps we
+ can do the comparison in the narrower type. */
+ else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
+ && TREE_CODE (arg0) == NOP_EXPR
+ && (tem = get_unwidened (arg0, NULL_TREE)) != arg0
+ && (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
+ && (TREE_TYPE (t1) == TREE_TYPE (tem)
+ || (TREE_CODE (t1) == INTEGER_CST
+ && int_fits_type_p (t1, TREE_TYPE (tem)))))
+ return fold (build (code, type, tem, convert (TREE_TYPE (tem), t1)));
+
+ /* If this is comparing a constant with a MIN_EXPR or a MAX_EXPR of a
+ constant, we can simplify it. */
+ else if (TREE_CODE (arg1) == INTEGER_CST
+ && (TREE_CODE (arg0) == MIN_EXPR
+ || TREE_CODE (arg0) == MAX_EXPR)
+ && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
+ return optimize_minmax_comparison (t);
+
+ /* If we are comparing an ABS_EXPR with a constant, we can
+ convert all the cases into explicit comparisons, but they may
+ well not be faster than doing the ABS and one comparison.
+ But ABS (X) <= C is a range comparison, which becomes a subtraction
+ and a comparison, and is probably faster. */
+ else if (code == LE_EXPR && TREE_CODE (arg1) == INTEGER_CST
+ && TREE_CODE (arg0) == ABS_EXPR
+ && ! TREE_SIDE_EFFECTS (arg0))
+ {
+ tree inner = TREE_OPERAND (arg0, 0);
+
+ tem = fold (build1 (NEGATE_EXPR, TREE_TYPE (arg1), arg1));
+ if (TREE_CODE (tem) == INTEGER_CST
+ && ! TREE_CONSTANT_OVERFLOW (tem))
+ return fold (build (TRUTH_ANDIF_EXPR, type,
+ build (GE_EXPR, type, inner, tem),
+ build (LE_EXPR, type, inner, arg1)));
+ }
+
/* If this is an EQ or NE comparison with zero and ARG0 is
(1 << foo) & bar, convert it to (bar >> foo) & 1. Both require
two operations, but the latter can be done in one less insn
@@ -6076,35 +6249,93 @@ fold (expr)
}
}
- /* An unsigned <= 0x7fffffff can be simplified. */
+ /* Comparisons with the highest or lowest possible integer of
+ the specified size will have known values and an unsigned
+ <= 0x7fffffff can be simplified. */
{
- int width = TYPE_PRECISION (TREE_TYPE (arg1));
+ int width = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg1)));
+
if (TREE_CODE (arg1) == INTEGER_CST
&& ! TREE_CONSTANT_OVERFLOW (arg1)
&& width <= HOST_BITS_PER_WIDE_INT
- && TREE_INT_CST_LOW (arg1) == ((HOST_WIDE_INT) 1 << (width - 1)) - 1
- && TREE_INT_CST_HIGH (arg1) == 0
&& (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
- || POINTER_TYPE_P (TREE_TYPE (arg1)))
- && TREE_UNSIGNED (TREE_TYPE (arg1)))
+ || POINTER_TYPE_P (TREE_TYPE (arg1))))
{
- switch (TREE_CODE (t))
- {
- case LE_EXPR:
- return fold (build (GE_EXPR, type,
- convert (signed_type (TREE_TYPE (arg0)),
- arg0),
- convert (signed_type (TREE_TYPE (arg1)),
- integer_zero_node)));
- case GT_EXPR:
- return fold (build (LT_EXPR, type,
- convert (signed_type (TREE_TYPE (arg0)),
- arg0),
- convert (signed_type (TREE_TYPE (arg1)),
- integer_zero_node)));
- default:
- break;
- }
+ if (TREE_INT_CST_HIGH (arg1) == 0
+ && (TREE_INT_CST_LOW (arg1)
+ == ((HOST_WIDE_INT) 1 << (width - 1)) - 1)
+ && ! TREE_UNSIGNED (TREE_TYPE (arg1)))
+ switch (TREE_CODE (t))
+ {
+ case GT_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_zero_node),
+ arg0);
+ case GE_EXPR:
+ TREE_SET_CODE (t, EQ_EXPR);
+ break;
+
+ case LE_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_one_node),
+ arg0);
+ case LT_EXPR:
+ TREE_SET_CODE (t, NE_EXPR);
+ break;
+
+ default:
+ break;
+ }
+
+ else if (TREE_INT_CST_HIGH (arg1) == -1
+ && (- TREE_INT_CST_LOW (arg1)
+ == ((HOST_WIDE_INT) 1 << (width - 1)))
+ && ! TREE_UNSIGNED (TREE_TYPE (arg1)))
+ switch (TREE_CODE (t))
+ {
+ case LT_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_zero_node),
+ arg0);
+ case LE_EXPR:
+ TREE_SET_CODE (t, EQ_EXPR);
+ break;
+
+ case GE_EXPR:
+ return omit_one_operand (type,
+ convert (type, integer_one_node),
+ arg0);
+ case GT_EXPR:
+ TREE_SET_CODE (t, NE_EXPR);
+ break;
+
+ default:
+ break;
+ }
+
+ else if (TREE_INT_CST_HIGH (arg1) == 0
+ && (TREE_INT_CST_LOW (arg1)
+ == ((HOST_WIDE_INT) 1 << (width - 1)) - 1)
+ && TREE_UNSIGNED (TREE_TYPE (arg1)))
+
+ switch (TREE_CODE (t))
+ {
+ case LE_EXPR:
+ return fold (build (GE_EXPR, type,
+ convert (signed_type (TREE_TYPE (arg0)),
+ arg0),
+ convert (signed_type (TREE_TYPE (arg1)),
+ integer_zero_node)));
+ case GT_EXPR:
+ return fold (build (LT_EXPR, type,
+ convert (signed_type (TREE_TYPE (arg0)),
+ arg0),
+ convert (signed_type (TREE_TYPE (arg1)),
+ integer_zero_node)));
+
+ default:
+ break;
+ }
}
}
@@ -6268,6 +6499,7 @@ fold (expr)
/* Note that it is safe to invert for real values here because we
will check below in the one case that it matters. */
+ t1 = NULL_TREE;
invert = 0;
if (code == NE_EXPR || code == GE_EXPR)
{