Commit 74e3c262 by Richard Biener Committed by Richard Biener

gimple-fold.c (gimple_fold_builtin_memory_op): Use gimple_build and get rid of…

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
parent aa00059c
2015-10-16 Richard Biener <rguenther@suse.de> 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.
2015-10-16 Richard Biener <rguenther@suse.de>
* tree-nested.h (build_addr): Adjust prototype. * tree-nested.h (build_addr): Adjust prototype.
* tree-nested.c (build_addr): Remove context argument and use * tree-nested.c (build_addr): Remove context argument and use
mark_addressable. mark_addressable.
...@@ -1045,16 +1045,20 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, ...@@ -1045,16 +1045,20 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
} }
done: done:
gimple_seq stmts = NULL;
if (endp == 0 || endp == 3) if (endp == 0 || endp == 3)
len = NULL_TREE; len = NULL_TREE;
else if (endp == 2) else if (endp == 2)
len = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (len), len, len = gimple_build (&stmts, loc, MINUS_EXPR, TREE_TYPE (len), len,
ssize_int (1)); ssize_int (1));
if (endp == 2 || endp == 1) if (endp == 2 || endp == 1)
dest = fold_build_pointer_plus_loc (loc, dest, len); {
len = gimple_convert_to_ptrofftype (&stmts, loc, len);
dest = gimple_build (&stmts, loc, POINTER_PLUS_EXPR,
TREE_TYPE (dest), dest, len);
}
dest = force_gimple_operand_gsi (gsi, dest, false, NULL_TREE, true, gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
GSI_SAME_STMT);
gimple *repl = gimple_build_assign (lhs, dest); gimple *repl = gimple_build_assign (lhs, dest);
gsi_replace (gsi, repl, false); gsi_replace (gsi, repl, false);
return true; return true;
...@@ -1708,10 +1712,10 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator *gsi, ...@@ -1708,10 +1712,10 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator *gsi,
} }
else else
{ {
tree temp = fold_build_pointer_plus_loc (loc, dest, len); gimple_seq stmts = NULL;
temp = force_gimple_operand_gsi (gsi, temp, len = gimple_convert_to_ptrofftype (&stmts, loc, len);
false, NULL_TREE, true, tree temp = gimple_build (&stmts, loc, POINTER_PLUS_EXPR, dest, len);
GSI_SAME_STMT); gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
replace_call_with_value (gsi, temp); replace_call_with_value (gsi, temp);
return true; return true;
} }
...@@ -1844,11 +1848,11 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi, ...@@ -1844,11 +1848,11 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi,
if (!fn) if (!fn)
return false; return false;
len = fold_convert_loc (loc, size_type_node, len); gimple_seq stmts = NULL;
len = size_binop_loc (loc, PLUS_EXPR, len, len = gimple_convert (&stmts, loc, size_type_node, len);
build_int_cst (size_type_node, 1)); len = gimple_build (&stmts, loc, PLUS_EXPR, size_type_node, len,
len = force_gimple_operand_gsi (gsi, len, true, NULL_TREE, build_int_cst (size_type_node, 1));
true, GSI_SAME_STMT); gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT);
gimple *repl = gimple_build_call (fn, 4, dest, src, len, size); gimple *repl = gimple_build_call (fn, 4, dest, src, len, size);
replace_call_with_call_and_fold (gsi, repl); replace_call_with_call_and_fold (gsi, repl);
return true; return true;
...@@ -5940,12 +5944,9 @@ rewrite_to_defined_overflow (gimple *stmt) ...@@ -5940,12 +5944,9 @@ rewrite_to_defined_overflow (gimple *stmt)
gimple_seq stmts = NULL; gimple_seq stmts = NULL;
for (unsigned i = 1; i < gimple_num_ops (stmt); ++i) for (unsigned i = 1; i < gimple_num_ops (stmt); ++i)
{ {
gimple_seq stmts2 = NULL; tree op = gimple_op (stmt, i);
gimple_set_op (stmt, i, op = gimple_convert (&stmts, type, op);
force_gimple_operand (fold_convert (type, gimple_set_op (stmt, i, op);
gimple_op (stmt, i)),
&stmts2, true, NULL_TREE));
gimple_seq_add_seq (&stmts, stmts2);
} }
gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt)); gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt));
if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR) if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR)
...@@ -6154,6 +6155,20 @@ gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op) ...@@ -6154,6 +6155,20 @@ gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
return gimple_build (seq, loc, NOP_EXPR, type, op); return gimple_build (seq, loc, NOP_EXPR, type, op);
} }
/* Build the conversion (ptrofftype) OP with a result of a type
compatible with ptrofftype with location LOC if such conversion
is neccesary in GIMPLE, simplifying it first.
Returns the built expression value and appends
statements possibly defining it to SEQ. */
tree
gimple_convert_to_ptrofftype (gimple_seq *seq, location_t loc, tree op)
{
if (ptrofftype_p (TREE_TYPE (op)))
return op;
return gimple_convert (seq, loc, sizetype, op);
}
/* Return true if the result of assignment STMT is known to be non-negative. /* Return true if the result of assignment STMT is known to be non-negative.
If the return value is based on the assumption that signed overflow is If the return value is based on the assumption that signed overflow is
undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't change
......
...@@ -112,6 +112,13 @@ gimple_convert (gimple_seq *seq, tree type, tree op) ...@@ -112,6 +112,13 @@ gimple_convert (gimple_seq *seq, tree type, tree op)
return gimple_convert (seq, UNKNOWN_LOCATION, type, op); return gimple_convert (seq, UNKNOWN_LOCATION, type, op);
} }
extern tree gimple_convert_to_ptrofftype (gimple_seq *, location_t, tree);
inline tree
gimple_convert_to_ptrofftype (gimple_seq *seq, tree op)
{
return gimple_convert_to_ptrofftype (seq, UNKNOWN_LOCATION, op);
}
extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0); extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
/* In gimple-match.c. */ /* In gimple-match.c. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment