Commit Graph

30 Commits

Author SHA1 Message Date
Martin Sebor 3f3430400b PR tree-optimization/79352 - -fprintf-return-value doesn't handle flexible-like array members properly
gcc/ChangeLog:

	PR tree-optimization/79352
	* gimple-fold.c (get_range_strlen): Add argument.
	(get_range_strlen): Change return type to bool.
	(get_maxval_strlen): Pass in a dummy argument.
	* gimple-fold.h (get_range_strlen): Change return type to bool.
	* gimple-ssa-sprintf.c (get_string_length): Set unlikely counter.
	* tree.h (array_at_struct_end_p): Add argument.
	* tree.c (array_at_struct_end_p): Handle it.

gcc/testsuite/ChangeLog:

	PR tree-optimization/79352
	* gcc.dg/tree-ssa/pr79352.c: New test.

From-SVN: r245156
2017-02-03 09:38:15 -07:00
Jakub Jelinek cbe34bb5ed Update copyright years.
From-SVN: r243994
2017-01-01 13:07:43 +01:00
Martin Sebor 88d0c3f0a1 PR middle-end/49905 - Better sanity checking on sprintf src & dest to
gcc/ChangeLog:

	PR middle-end/49905
	* Makefile.in (OBJS): Add gimple-ssa-sprintf.o.
	* config/linux.h (TARGET_PRINTF_POINTER_FORMAT): Redefine.
	* config/linux.c (gnu_libc_printf_pointer_format): New function.
	* config/sol2.h (TARGET_PRINTF_POINTER_FORMAT): Same.
	* config/sol2.c (solaris_printf_pointer_format): New function.
	* doc/invoke.texi (-Wformat-length, -fprintf-return-value): New
	options.
	* doc/tm.texi.in (TARGET_PRINTF_POINTER_FORMAT): Document.
	* doc/tm.texi: Regenerate.
	* gimple-fold.h (get_range_strlen): New function.
	(get_maxval_strlen): Declare existing function.
	* gimple-fold.c (get_range_strlen): Add arguments and compute both
	maximum and minimum.
	 (get_range_strlen): Define overload.
	(get_maxval_strlen): Adjust.
	* gimple-ssa-sprintf.c: New file and pass.
	* passes.def (pass_sprintf_length): Add new pass.
	* targhooks.h (default_printf_pointer_format): Declare new function.
	(gnu_libc_printf_pointer_format): Same.
	(solaris_libc_printf_pointer_format): Same.
	* targhooks.c (default_printf_pointer_format): Define new function.
	* tree-pass.h (make_pass_sprintf_length): Declare new function.
	* print-tree.c: Increase buffer size.

gcc/c-family/ChangeLog:

	PR middle-end/49905
	* c.opt: Add -Wformat-length and -fprintf-return-value.

gcc/testsuite/ChangeLog:

	PR middle-end/49905
	* gcc.dg/builtin-stringop-chk-1.c: Adjust.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: New test.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-2.c: New test.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-3.c: New test.
	* gcc.dg/tree-ssa/builtin-sprintf-warn-4.c: New test.
	* gcc.dg/tree-ssa/builtin-sprintf.c: New test.
	* gcc.dg/tree-ssa/builtin-sprintf-2.c: New test.

From-SVN: r240298
2016-09-20 19:39:27 -06:00
Jakub Jelinek 849a76a5a2 re PR middle-end/66867 (Suboptimal code generation for atomic_compare_exchange)
PR middle-end/66867
	* builtins.c (expand_ifn_atomic_compare_exchange_into_call,
	expand_ifn_atomic_compare_exchange): New functions.
	* internal-fn.c (expand_ATOMIC_COMPARE_EXCHANGE): New function.
	* tree.h (build_call_expr_internal_loc): Rename to ...
	(build_call_expr_internal_loc_array): ... this.  Fix up type of
	last argument.
	* internal-fn.def (ATOMIC_COMPARE_EXCHANGE): New internal fn.
	* predict.c (expr_expected_value_1): Handle IMAGPART_EXPR of
	ATOMIC_COMPARE_EXCHANGE result.
	* builtins.h (expand_ifn_atomic_compare_exchange): New prototype.
	* gimple-fold.h (optimize_atomic_compare_exchange_p,
	fold_builtin_atomic_compare_exchange): New prototypes.
	* gimple-fold.c (optimize_atomic_compare_exchange_p,
	fold_builtin_atomic_compare_exchange): New functions..
	* tree-ssa.c (execute_update_addresses_taken): If
	optimize_atomic_compare_exchange_p, ignore &var in 2nd argument
	of call when finding addressable vars, and if such var becomes
	non-addressable, call fold_builtin_atomic_compare_exchange.

From-SVN: r237814
2016-06-28 10:27:18 +02:00
Jakub Jelinek 818ab71a41 Update copyright years.
From-SVN: r232055
2016-01-04 15:30:50 +01:00
Richard Sandiford 67dbe5829e Move fold_trunc_transparent_mathfn to match.pd
This moves the fold rules for trunc, floor, ceil, round, nearbyint and
rint in one go, since they're tested as a group.  Most of the code is
supporting the f(x)->x fold when x is known to be integer-valued.
Like with the non-negative test, this is probably more elegantly handled
by tracking range information for reals, but until that happens, I think
we should handle it analogously to tree_expr_nonnegative_p.

I've incorporated the fix for PR68031 in the new version of
integer_valued_real_p.  However, it seemed confusing to test for an
SSA name at the head of the function rather than the case statement,
and not fall through to tree_simple_nonnegative_warnv_p (which
conceptually shouldn't care whether an update is in progress).
But tree_simple_nonnegative_warnv_p is a no-op for SSA names,
so I simply changed it to:

          return (!name_registered_for_update_p (t)
	      && depth < PARAM_VALUE (PARAM_MAX_SSA_NAME_QUERY_DEPTH)
	      && gimple_stmt_nonnegative_warnv_p (SSA_NAME_DEF_STMT (t),
						  strict_overflow_p, depth));

and used that in the new code too.

Doing these folds later meant that IPA would start to use information
about the aborting sinf and floor in 20030125-1.c before the folds
kicked in.  I changed them from noinline to weak to stop that.

Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/
	* builtins.c (integer_valued_real_p): Move to fold-const.c.
	(fold_trunc_transparent_mathfn, fold_builtin_trunc, fold_builtin_floor)
	(fold_builtin_ceil, fold_builtin_round): Delete.
	(fold_builtin_1): Handle constant trunc, floor, ceil and round
	arguments here.
	* convert.c (convert_to_real): Remove narrowing of rounding
	functions.
	* fold-const.h (integer_valued_real_unary_p)
	(integer_valued_real_binary_p, integer_valued_real_call_p)
	(integer_valued_real_single_p, integer_valued_real_p): Declare.
	* fold-const.c (tree_single_nonnegative_warnv_p): Move
	name_registered_for_update_p check to SSA_NAME case statement.
	Don't call tree_simple_nonnegative_warnv_p for SSA names.
	(integer_valued_real_unary_p, integer_valued_real_binary_p)
	(integer_valued_real_call_p, integer_valued_real_single_p)
	(integer_valued_real_invalid_p): New functions.
	(integer_valued_real_p): Move from fold-const.c and rework
	to call the functions above.  Handle SSA names.
	* gimple-fold.h (gimple_stmt_integer_valued_real_p): Declare.
	* gimple-fold.c (gimple_assign_integer_valued_real_p)
	(gimple_call_integer_valued_real_p, gimple_phi_integer_valued_real_p)
	(gimple_stmt_integer_valued_real_p): New functions.
	* match.pd: Fold f(f(x))->f(x) for fp->fp rounding functions f.
	Fold f(x)->x for the same f if x is known to be integer-valued.
	Fold f(extend(x))->extend(f'(x)) if doing so doesn't affect
	the result.  Canonicalize floor(x) as trunc(x) if x is
	nonnegative.

gcc/testsuite/
	* gcc.c-torture/execute/20030125-1.c (floor, floorf, sin, sinf):
	Make weak rather than noinline.
	* gcc.dg/builtins-57.c: Compile with -O.
	* gcc.dg/torture/builtin-integral-1.c: Skip for -O0.

From-SVN: r229221
2015-10-23 10:01:47 +00:00
Richard Biener 74e3c26262 gimple-fold.c (gimple_fold_builtin_memory_op): Use gimple_build and get rid of force_gimple_operand_gsi.
2015-10-16  Richard Biener  <rguenther@suse.de>

	* gimple-fold.c (gimple_fold_builtin_memory_op): Use gimple_build
	and get rid of force_gimple_operand_gsi.
	(gimple_fold_builtin_memory_chk): Likewise.
	(gimple_fold_builtin_stxcpy_chk): Likewise.
	(rewrite_to_defined_overflow): Likewise.
	(gimple_convert_to_ptrofftype): New function.
	* gimple-fold.h (gimple_convert_to_ptrofftype): New overload,
	declare.

From-SVN: r228863
2015-10-16 07:52:32 +00:00
Richard Sandiford 68e57f040c Make tree_expr_nonnegative_warnv_p recurse into SSA names
The upcoming patch to move sqrt and cbrt simplifications to match.pd
caused a regression because the (abs @0)->@0 simplification didn't
trigger for:

        (abs (convert (abs X)))

The simplification is based on tree_expr_nonnegative_p, which at
the moment just gives up if it sees an SSA_NAME.

This patch makes tree_expr_nonnegative_p recurse into SSA name
definitions, but limits the depth of recursion to a small number
for the reason mentioned in the comment (adapted from an existing
comment in gimple_val_nonnegative_real_p).  The patch reuses code
in tree-vrp.c, moving it to gimple-fold.c.  It also replaces calls
to gimple_val_nonnegative_real_p with calls to tree_expr_nonnegative_p.

A knock-on effect is that we can now prove _i_589 < 0 is false in
sequences like:

      i_1917 = ASSERT_EXPR <i_1075, i_1075 == 0>;
      _i_589 = (const int) i_1917;
      _i_1507 = ASSERT_EXPR <_i_589, _i_589 < 0>;

This defeats an assert in tree-vrp.c that ASSERT_EXPR conditions
are never known to be false.  Previously the assert only ever used
local knowledge and so would be limited to cases like x != x for
integer x.  Now that we use global knowledge it's possible to prove
the assertion condition is false in blocks that are in practice
unreachable.  The patch therefore removes the assert.

Bootstrapped & regression-tested on x86_64-linux-gnu.  I didn't write
a specific test because this is already covered by the testsuite if
the follow-on patch is also applied.

gcc/
	* params.def (PARAM_MAX_SSA_NAME_QUERY_DEPTH): New param.
	* doc/invoke.texi (--param max-ssa-name-query-depth): Document.
	* fold-const.h (tree_unary_nonnegative_warnv_p)
	(tree_single_nonnegative_warnv_p, tree_call_nonnegative_warnv_p)
	(tree_expr_nonnegative_warnv_p): Add depth parameters.
	* fold-const.c: Include gimple-fold.h and params.h.
	(tree_ssa_name_nonnegative_warnv_p): New function.
	(tree_unary_nonnegative_warnv_p, tree_binary_nonnegative_warnv_p)
	(tree_single_nonnegative_warnv_p, tree_call_nonnegative_warnv_p)
	(tree_invalid_nonnegative_warnv_p, tree_expr_nonnegative_warnv_p):
	Add a depth parameter and increment it for recursive calls to
	tree_expr_nonnegative_warnv_p.  Use tree_ssa_name_nonnegative_warnv_p
	to handle SSA names.
	* gimple-fold.h (gimple_val_nonnegative_real_p): Delete.
	(gimple_stmt_nonnegative_warnv_p): Declare.
	* tree-vrp.c (remove_range_assertions): Remove assert that condition
	cannot be proven false.
	(gimple_assign_nonnegative_warnv_p, gimple_call_nonnegative_warnv_p)
	(gimple_stmt_nonnegative_warnv_p): Move to...
	* gimple-fold.c: ...here.  Add depth parameters and pass them
	down to the tree routines.  Accept statements that aren't
	assignments or calls but just return false for them.
	(gimple_val_nonnegative_real_p): Delete.
	* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Use
	tree_expr_nonnegative_p instead of gimple_val_nonnegative_real_p.
	Check HONOR_NANs first.

From-SVN: r228614
2015-10-08 16:49:24 +00:00
Trevor Saunders 355fe0884b switch from gimple to gimple*
This renames the gimple_statement_base struct to gimple removes the
typedef of gimple_statement_base * to gimple, and then adjusts all of
the places that use the type.

gcc/ChangeLog:

2015-09-19  Trevor Saunders  <tbsaunde@tbsaunde.org>

	* coretypes.h (gimple): Change typedef to be a forward
	declaration.
	* gimple.h (gimple_statement_base): rename to gimple.
	* (all functions and types using gimple): Adjust.
	* *.[ch]: Likewise.

gcc/cp/ChangeLog:

2015-09-19  Trevor Saunders  <tbsaunde@tbsaunde.org>

	* cp-gimplify.c (gimplify_must_not_throw_expr): Adjust.

From-SVN: r227941
2015-09-20 00:52:59 +00:00
Richard Biener c26de36ddc gimple-fold.h (gimple_build): Remove optional valueize arguments.
2015-04-20  Richard Biener  <rguenther@suse.de>

	* gimple-fold.h (gimple_build): Remove optional valueize arguments.
	* gimple-fold.c (gimple_build_valueize): New function.
	(gimple_build): Always use gimple_build_valueize as valueize hook.

From-SVN: r222231
2015-04-20 13:23:59 +00:00
Jakub Jelinek 5624e564d2 Update copyright years.
From-SVN: r219188
2015-01-05 13:33:28 +01:00
Richard Biener 8403c2cf5f re PR target/63679 ([AArch64] Failure to constant fold.)
2014-11-24  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/63679
	* tree-ssa-sccvn.c: Include ipa-ref.h, plugin-api.h and cgraph.h.
	(copy_reference_ops_from_ref): Fix non-constant ADDR_EXPR case
	to properly leave off at -1.
	(fully_constant_vn_reference_p): Generalize folding from
	constant initializers.
	(vn_reference_lookup_3): When looking through aggregate copies
	handle offsetted reads and try simplifying the result to
	a constant.
	* gimple-fold.h (fold_ctor_reference): Export.
	* gimple-fold.c (fold_ctor_reference): Likewise.

	* gcc.dg/tree-ssa/ssa-fre-42.c: New testcase.
	* gcc.dg/tree-ssa/20030807-5.c: Avoid folding read from global to zero.
	* gcc.target/i386/ssetype-1.c: Likewise.
	* gcc.target/i386/ssetype-3.c: Likewise.
	* gcc.target/i386/ssetype-5.c: Likewise.

From-SVN: r218019
2014-11-24 14:07:18 +00:00
Richard Biener d2a858011c gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd valueization hook defaulted to no_follow_ssa_edges.
2014-11-14  Richard Biener  <rguenther@suse.de>

	* gimple-fold.h (gimple_fold_stmt_to_constant_1): Add 2nd
	valueization hook defaulted to no_follow_ssa_edges.
	* gimple-fold.c (gimple_fold_stmt_to_constant_1): Pass
	2nd valueization hook to gimple_simplify.
	* tree-ssa-ccp.c (valueize_op_1): New function to be
	used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
	(ccp_fold): Adjust.
	* tree-vrp.c (vrp_valueize_1): New function to be
	used for gimple_simplify called via gimple_fold_stmt_to_constant_1.
	(vrp_visit_assignment_or_call): Adjust.

From-SVN: r217560
2014-11-14 13:32:56 +00:00
Jakub Jelinek 1304953e4f re PR c/59708 (clang-compatible checked arithmetic builtins)
PR c/59708
	* builtin-attrs.def (ATTR_NOTHROW_TYPEGENERIC_LEAF): New attribute.
	* builtins.c (fold_builtin_arith_overflow): New function.
	(fold_builtin_3): Use it.
	* builtins.def (BUILT_IN_ADD_OVERFLOW, BUILT_IN_SUB_OVERFLOW,
	BUILT_IN_MUL_OVERFLOW, BUILT_IN_SADD_OVERFLOW, BUILT_IN_SADDL_OVERFLOW,
	BUILT_IN_SADDLL_OVERFLOW, BUILT_IN_SSUB_OVERFLOW,
	BUILT_IN_SSUBL_OVERFLOW, BUILT_IN_SSUBLL_OVERFLOW,
	BUILT_IN_SMUL_OVERFLOW, BUILT_IN_SMULL_OVERFLOW,
	BUILT_IN_SMULLL_OVERFLOW, BUILT_IN_UADDL_OVERFLOW,
	BUILT_IN_UADDLL_OVERFLOW, BUILT_IN_USUB_OVERFLOW,
	BUILT_IN_USUBL_OVERFLOW, BUILT_IN_USUBLL_OVERFLOW,
	BUILT_IN_UMUL_OVERFLOW, BUILT_IN_UMULL_OVERFLOW,
	BUILT_IN_UMULLL_OVERFLOW): New built-in functions.
	* builtin-types.def (BT_PTR_UINT, BT_PTR_ULONG, BT_PTR_LONGLONG,
	BT_FN_BOOL_INT_INT_INTPTR, BT_FN_BOOL_LONG_LONG_LONGPTR,
	BT_FN_BOOL_LONGLONG_LONGLONG_LONGLONGPTR, BT_FN_BOOL_UINT_UINT_UINTPTR,
	BT_FN_BOOL_ULONG_ULONG_ULONGPTR,
	BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, BT_FN_BOOL_VAR): New.
	* expr.c (write_complex_part): Remove prototype, no longer static.
	* expr.h (write_complex_part): New prototype.
	* function.c (aggregate_value_p): For internal functions return 0.
	* gimple-fold.c (arith_overflowed_p): New functions.
	(gimple_fold_call): Fold {ADD,SUB,MUL}_OVERFLOW internal calls.
	* gimple-fold.h (arith_overflowed_p): New prototype.
	* tree-ssa-dce.c: Include tree-ssa-propagate.h and gimple-fold.h.
	(find_non_realpart_uses, maybe_optimize_arith_overflow): New
	functions.
	(eliminate_unnecessary_stmts): Transform {ADD,SUB,MUL}_OVERFLOW
	into COMPLEX_CST/COMPLEX_EXPR if IMAGPART_EXPR of the result is
	never used.
	* gimplify.c (gimplify_call_expr): Handle gimplification of
	internal calls with lhs.
	* internal-fn.c (get_range_pos_neg, get_min_precision,
	expand_arith_overflow_result_store): New functions.
	(ubsan_expand_si_overflow_addsub_check): Renamed to ...
	(expand_addsub_overflow): ... this.  Add LOC, LHS, ARG0, ARG1,
	UNSR_P, UNS0_P, UNS1_P, IS_UBSAN arguments, remove STMT argument.
	Handle ADD_OVERFLOW and SUB_OVERFLOW expansion.
	(ubsan_expand_si_overflow_neg_check): Renamed to ...
	(expand_neg_overflow): ... this.  Add LOC, LHS, ARG1, IS_UBSAN
	arguments, remove STMT argument.  Handle SUB_OVERFLOW with
	0 as first argument expansion.
	(ubsan_expand_si_overflow_mul_check): Renamed to ...
	(expand_mul_overflow): ... this.  Add LOC, LHS, ARG0, ARG1,
	UNSR_P, UNS0_P, UNS1_P, IS_UBSAN arguments, remove STMT argument.
	Handle MUL_OVERFLOW expansion.
	(expand_UBSAN_CHECK_ADD): Use expand_addsub_overflow, prepare
	arguments for it.
	(expand_UBSAN_CHECK_SUB): Use expand_addsub_overflow or
	expand_neg_overflow, prepare arguments for it.
	(expand_UBSAN_CHECK_MUL): Use expand_mul_overflow, prepare arguments
	for it.
	(expand_arith_overflow, expand_ADD_OVERFLOW, expand_SUB_OVERFLOW,
	expand_MUL_OVERFLOW): New functions.
	* internal-fn.def (ADD_OVERFLOW, SUB_OVERFLOW, MUL_OVERFLOW): New
	internal functions.
	* tree-vrp.c (check_for_binary_op_overflow): New function.
	(extract_range_basic): Handle {REAL,IMAG}PART_EXPR if the operand
	is SSA_NAME set by {ADD,SUB,MUL}_OVERFLOW internal functions.
	(simplify_internal_call_using_ranges): Handle {ADD,SUB,MUL}_OVERFLOW
	internal functions.
	* optabs.def (umulv4_optab): New optab.
	* config/i386/i386.md (umulv<mode>4, <u>mulvqi4): New define_expands.
	(*umulv<mode>4, *<u>mulvqi4): New define_insns.
	* doc/extend.texi (Integer Overflow Builtins): Document
	__builtin_*_overflow.
c-family/
	* c-common.c (check_builtin_function_arguments): Handle
	BUILT_IN_{ADD,SUB,MUL}_OVERFLOW.
testsuite/
	* c-c++-common/builtin-arith-overflow-1.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-10.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-11.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-12.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-12.h: New file.
	* c-c++-common/torture/builtin-arith-overflow-13.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-14.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-15.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-16.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-17.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-18.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-1.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-1.h: New file.
	* c-c++-common/torture/builtin-arith-overflow-2.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-3.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-4.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-5.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-6.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-7.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-8.c: New test.
	* c-c++-common/torture/builtin-arith-overflow-9.c: New test.
	* c-c++-common/torture/builtin-arith-overflow.h: New file.
	* gcc.dg/builtin-arith-overflow-1.c: New test.
	* gcc.dg/builtin-arith-overflow-2.c: New test.

From-SVN: r217415
2014-11-12 13:28:06 +01:00
Richard Biener 45cc9f96c2 gimple-fold.h (follow_single_use_edges): Declare.
2014-10-28  Richard Biener  <rguenther@suse.de>

	* gimple-fold.h (follow_single_use_edges): Declare.
	* gimple-fold.c (follow_single_use_edges): New function.
	(gimple_fold_stmt_to_constant_1): Dispatch to gimple_simplify.
	* tree-ssa-propagate.c
	(substitute_and_fold_dom_walker::before_dom_children): Allow
	following single-use edges when folding stmts we propagated into.

From-SVN: r216799
2014-10-28 14:23:27 +00:00
Richard Biener e0ee10ed5a genmatch.c (expr::gen_transform): Use fold_buildN_loc and build_call_expr_loc.
2014-10-24  Richard Biener  <rguenther@suse.de>

	* genmatch.c (expr::gen_transform): Use fold_buildN_loc
	and build_call_expr_loc.
	(dt_simplify::gen): Drop non_lvalue for GIMPLE, use
	non_lvalue_loc to build it for GENERIC.
	(decision_tree::gen_generic): Add location argument to
	generic_simplify prototype.
	(capture_info): New class.
	(capture_info::capture_info): New constructor.
	(capture_info::walk_match): New method.
	(capture_info::walk_result): New method.
	(capture_info::walk_c_expr): New method.
	(dt_simplify::gen): Handle preserving side-effects for
	GENERIC code generation.
	(decision_tree::gen_generic): Do not reject operands
	with TREE_SIDE_EFFECTS.
	* generic-match.h: New file.
	* generic-match-head.c: Include generic-match.h, not gimple-match.h.
	* match.pd: Add some constant folding patterns from fold-const.c.
	* fold-const.c: Include generic-match.h.
	(fold_unary_loc): Dispatch to generic_simplify.
	(fold_ternary_loc): Likewise.
	(fold_binary_loc): Likewise.  Remove patterns now implemented
	by generic_simplify.
	* gimple-fold.c (replace_stmt_with_simplification): New function.
	(fold_stmt_1): Add valueize parameter, dispatch to gimple_simplify.
	(no_follow_ssa_edges): New function.
	(fold_stmt): New overload with valueization hook.  Use
	no_follow_ssa_edges for the overload without hook.
	(fold_stmt_inplace): Likewise.
	* gimple-fold.h (no_follow_ssa_edges): Declare.

From-SVN: r216631
2014-10-24 11:00:08 +00:00
Richard Biener 3d2cf79f81 Makefile.in (OBJS): Add gimple-match.o and generic-match.o.
2014-10-22  Richard Biener  <rguenther@suse.de>
	Prathamesh Kulkarni  <bilbotheelffriend@gmail.com>

	* Makefile.in (OBJS): Add gimple-match.o and generic-match.o.
	(MOSTLYCLEANFILES): Add gimple-match.c and generic-match.c.
	(gimple-match.c): Generate by triggering s-match.
	(generic-match.c): Likewise.
	(s-match): Rule to build gimple-match.c and generic-match.c
	by running the genmatch generator program.
	(build/hash-table.o): Dependencies to build hash-table.c for the host.
	(build/genmatch.o): Dependencies to build genmatch.
	(genprog): Add match.
	(build/genmatch): Likewise.
	(TEXI_GCCINT_FILES): Add match-and-simplify.texi.
	* generic-match-head.c: New file.
	* gimple-match-head.c: Likewise.
	* gimple-match.h: Likewise.
	* genmatch.c: Likewise.
	* match.pd: Likewise.
	* builtins.h (fold_builtin_n): Export.
	* builtins.c (fold_builtin_n): Likewise.
	* gimple-fold.h (gimple_build): Declare various overloads.
	(gimple_simplify): Likewise.
	(gimple_convert): Re-implement in terms of gimple_build.
	* gimple-fold.c (gimple_convert): Remove.
	(gimple_build): New functions.

	* doc/match-and-simplify.texi: New file.
	* doc/gccint.texi: Add menu item Match and Simplify and include
	match-and-simplify.texi.

Co-Authored-By: Prathamesh Kulkarni <bilbotheelffriend@gmail.com>

From-SVN: r216542
2014-10-22 08:42:37 +00:00
Richard Biener d4f5cd5e82 re PR c++/63419 (verify_gimple failed: "vector CONSTRUCTOR element is not a GIMPLE value")
2014-10-13  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/63419
	* gimple-fold.h (gimple_convert): New function.
	* gimple-fold.c (gimple_convert): Likewise.
	* tree-ssa-pre.c (create_expression_by_pieces): Use gimple_convert
	to split out required conversions early.

	* g++.dg/torture/pr63419.C: New testcase.

From-SVN: r216138
2014-10-13 07:58:05 +00:00
Richard Biener 3daa26d0e9 gimple-fold.h (gimple_fold_builtin): Remove.
2014-08-04  Richard Biener  <rguenther@suse.de>

	* gimple-fold.h (gimple_fold_builtin): Remove.
	* gimple-fold.c (gimple_fold_builtin): Make static.
	* tree-ssa-ccp.c (pass_fold_builtins::execute): Use
	fold_stmt, not gimple_fold_builtin.

From-SVN: r213585
2014-08-04 13:08:34 +00:00
Jan Hubicka ec77d61fe3 re PR lto/59468 (ICE on invalid C++ code with LTO in gimple_get_virt_method_for_binfo, at gimple-fold.c:3224)
PR lto/59468
	* ipa-utils.h (possible_polymorphic_call_targets): Update prototype
	and wrapper.
	* ipa-devirt.c: Include demangle.h
	(odr_violation_reported): New static variable.
	(add_type_duplicate): Update odr_violations.
	(maybe_record_node): Add completep parameter; update it.
	(record_target_from_binfo): Add COMPLETEP parameter;
	update it as needed.
	(possible_polymorphic_call_targets_1): Likewise.
	(struct polymorphic_call_target_d): Add nonconstruction_targets;
	rename FINAL to COMPLETE.
	(record_targets_from_bases): Sanity check we found the binfo;
	fix COMPLETEP updating.
	(possible_polymorphic_call_targets): Add NONCONSTRUTION_TARGETSP
	parameter, fix computing of COMPLETEP.
	(dump_possible_polymorphic_call_targets): Imrove readability of dump; at
	LTO time do demangling.
	(ipa_devirt): Use nonconstruction_targets; Improve dumps.
	* gimple-fold.c (gimple_get_virt_method_for_vtable): Add can_refer
	parameter.
	(gimple_get_virt_method_for_binfo): Likewise.
	* gimple-fold.h (gimple_get_virt_method_for_binfo,
	gimple_get_virt_method_for_vtable): Update prototypes.

	PR lto/59468
	* g++.dg/ipa/devirt-27.C: New testcase.
	* g++.dg/ipa/devirt-26.C: New testcase.

From-SVN: r207702
2014-02-11 22:54:21 +00:00
Jan Hubicka 6f746413d4 gimple-fold.c (gimple_extract_devirt_binfo_from_cst): Remove.
* gimple-fold.c (gimple_extract_devirt_binfo_from_cst): Remove.
	* gimple-fold.h (gimple_extract_devirt_binfo_from_cst): Remove.

From-SVN: r207450
2014-02-04 06:04:32 +00:00
Jan Hubicka 85942f45e9 re PR ipa/59831 (ice in cgraph_speculative_call_info with -O3)
PR ipa/59831
	* g++.dg/ipa/devirt-24.C: New testcase.

	* ipa-cp.c (ipa_get_indirect_edge_target_1): Give up on -fno-devirtualize;
	Try to devirtualize by the knowledge of virtual table pointer given by
	aggregate propagation.
	* ipa-prop.c (try_make_edge_direct_virtual_call): Likewise.
	ipa_print_node_jump_functions): Dump also offset that
	is relevant for polymorphic calls.
	(determine_known_aggregate_parts): Add arg_type parameter; use it
	instead of determining the type from pointer type.
	(ipa_compute_jump_functions_for_edge): Update call of
	determine_known_aggregate_parts.
	* gimple-fold.c (gimple_get_virt_method_for_vtable): Break out from ...
	(gimple_get_virt_method_for_binfo): ... here; simplify using
	vtable_pointer_value_to_vtable.
	* gimple-fold.h (gimple_get_virt_method_for_vtable): Declare.
	* ipa-devirt.c (subbinfo_with_vtable_at_offset): Turn OFFSET parameter
	to unsigned HOST_WIDE_INT; Use vtable_pointer_value_to_vtable.
	(vtable_pointer_value_to_vtable): Break out from ...; handle also
	POINTER_PLUS_EXPR.
	(vtable_pointer_value_to_binfo): ... here.
	* ipa-utils.h (vtable_pointer_value_to_vtable): Declare.

From-SVN: r207439
2014-02-03 20:41:30 +00:00
Jakub Jelinek 19e51b409e re PR tree-optimization/59387 (wrong code (hangs) at -Os on x86_64-linux-gnu)
PR tree-optimization/59387
	* tree-scalar-evolution.c: Include gimple-fold.h and gimplify-me.h.
	(scev_const_prop): If folded_casts and type has undefined overflow,
	use force_gimple_operand instead of force_gimple_operand_gsi and
	for each added stmt if it is assign with
	arith_code_with_undefined_signed_overflow, call
	rewrite_to_defined_overflow.
	* tree-ssa-loop-im.c: Don't include gimplify-me.h, include
	gimple-fold.h instead.
	(arith_code_with_undefined_signed_overflow,
	rewrite_to_defined_overflow): Moved to ...
	* gimple-fold.c (arith_code_with_undefined_signed_overflow,
	rewrite_to_defined_overflow): ... here.  No longer static.
	Include gimplify-me.h.
	* gimple-fold.h (arith_code_with_undefined_signed_overflow,
	rewrite_to_defined_overflow): New prototypes.

	* gcc.c-torture/execute/pr59387.c: New test.

From-SVN: r206583
2014-01-13 20:14:03 +01:00
Richard Sandiford 23a5b65a92 Update copyright years in gcc/
From-SVN: r206289
2014-01-02 22:23:26 +00:00
Andrew MacLeod b184c8f138 tree-flow.h: Move some prototypes to gimple.h.
2013-10-10  Andrew MacLeod  <amacleod@redhat.com>

	* tree-flow.h: Move some prototypes to gimple.h.
	(gimple_fold_indirect_ref): Move prototype to gimple-fold.h.
	* gimple.h: Relocate some prototypes from tree-flow.h
	* builtins.c (std_gimplify_va_arg_expr, build_va_arg_indirect_ref):
	Move to gimplify.c.
	* gimplify.c (gimple_fold_indirect_ref): Move to gimple-fold.c.
	(build_va_arg_indirect_ref): Relocate and make static.
	(std_gimplify_va_arg_expr): Relocate here.
	* gimple-fold.c (gimple_fold_indirect_ref): Relocate here.
	* gimple-fold.h (gimple_fold_indirect_ref): Add prototype.

From-SVN: r203357
2013-10-10 12:16:24 +00:00
Andrew MacLeod 744730a48e tree-flow.h: Remove some prototypes.
2013-10-02  Andrew MacLeod  <amacleod@redhat.com>

	* tree-flow.h: Remove some prototypes.
	* gimple-fold.h: Add prototypes from gimple.h and tree-flow.h.
	* tree-ssa-propagate.h: Relocate prototypes from tree-flow.h.
	* tree-ssa-copy.c (may_propagate*, propagate_value, replace_exp,
	propagate_tree_value*): Move from here to...
	* tree-ssa-propagate.c (may_propagate*, propagate_value, replace_exp,
	propagate_tree_value*): Relocate here.
	* tree-ssa-propagate.h: Relocate prototypes from tree-flow.h.
	* gimple.h: Include gimple-fold.h, move prototypes into gimple-fold.h.
	* gimple-fold.c: Remove gimple-fold.h from include list.
	* tree-vrp.c: Remove gimple-fold.h from include list.
	* tree-ssa-sccvn.c: Remove gimple-fold.h from include list.
	* tree-ssa-ccp.c: Remove gimple-fold.h from include list.
	* tree-scalar-evolution.c: Add tree-ssa-propagate.h to include list.
	* tree-ssa-pre.c: Add tree-ssa-propagate.h to include list.
	* sese.c: Add tree-ssa-propagate.h to include list.

From-SVN: r203118
2013-10-02 15:29:35 +00:00
Richard Sandiford d1e082c2c2 Update copyright years in gcc/
From-SVN: r195098
2013-01-10 20:38:27 +00:00
Jakub Jelinek 90d04a445c Update Copyright years for files modified in 2011 and/or 2012.
From-SVN: r194903
2013-01-04 13:49:55 +01:00
Steven Bosscher 79bdca32d4 alias.h: Do not include coretypes.h in header files.
gcc/
	* alias.h: Do not include coretypes.h in header files.
	* cppbuiltin.h: Likewise.
	* double-int.h: Likewise.
	* gimple-fold.h: Likewise.
	* flags.h: Likewise.
	* tree-ssa-alias.h: Likewise.
	* gengtype.h (obstack_chunk_alloc, obstack_chunk_free,
	OBSTACK_CHUNK_SIZE): Define here to avoid dependency on coretypes.h.
	* Makefile.in (RTL_BASE_H): Depend on coretypes.h.
	(TREE_H): Likewise.
	(ALIAS_H): Do not depend on coretypes.h.
	(FLAGS_H): Likewise.
	(realmpfr.o): Depend on coretypes.h.

java/
	* verify.h: Do not include system.h and coretypes.h here.
	* verify-impl.c: Include them here instead.

From-SVN: r189358
2012-07-08 09:57:36 +00:00
Richard Guenther cfef45c809 re PR tree-optimization/46562 (CCP currently needs iteration for &a[i])
2011-03-24  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46562
	* tree.c (build_invariant_address): New function.
	* tree.h (build_invariant_address): Declare.
	* tree-dfa.c (get_addr_base_and_unit_offset): Wrap around
	a renamed function moved ...
	* tree-flow-inline.h (get_addr_base_and_unit_offset_1): ... here.
	Take valueization callback parameter.
	* tree-flow.h (gimple_fold_stmt_to_constant): Declare.
	* gimple-fold.h: New file.
	* tree-ssa-ccp.c (ccp_fold): Use gimple_fold_stmt_to_constant_1.
	(ccp_fold, fold_const_aggregate_ref,
	fold_ctor_reference, fold_nonarray_ctor_reference,
	fold_array_ctor_reference, fold_string_cst_ctor_reference,
	get_base_constructor): Move ...
	* gimple-fold.c: ... here.
	(gimple_fold_stmt_to_constant_1): New function
	split out from ccp_fold.  Take a valueization callback parameter.
	Valueize all operands.
	(gimple_fold_stmt_to_constant): New wrapper function.
	(fold_const_aggregate_ref_1): New function split out from
	fold_const_aggregate_ref.  Take a valueization callback parameter.
	(fold_const_aggregate_ref): Wrap fold_const_aggregate_ref_1.
	* tree-ssa-sccvn.c (simplify_binary_expression): Simplify
	invariant POINTER_PLUS_EXPRs to invariant form.
	(vn_valueize): New function.
	(try_to_simplify): Simplify by using gimple_fold_stmt_to_constant.
	* tree-vrp.c (vrp_valueize): New function.
	(vrp_visit_assignment_or_call): Use gimple_fold_stmt_to_constant
	to fold statements to constants.
	* tree-ssa-pre.c (eliminate): Properly guard propagation of
	function declarations.
	* Makefile.in (tree-ssa-sccvn.o, tree-vrp.o, gimple-fold.o,
	tree-ssa-ccp.o): Add gimple-fold.h dependencies.

	* c-c++-common/pr46562-2.c: New testcase.
	* c-c++-common/pr46562.c: Likewise.

From-SVN: r171386
2011-03-24 11:23:29 +00:00