Commit 3824a0a2 by Jakub Jelinek Committed by Jakub Jelinek

re PR tree-optimization/69802 (gcc ICE at -O1 and above on valid code on…

re PR tree-optimization/69802 (gcc ICE at -O1 and above  on valid code on x86_64-linux-gnu with “seg fault”)

	PR tree-optimization/69802
	* tree-ssa-reassoc.c (update_range_test): If op is
	SSA_NAME_IS_DEFAULT_DEF, give up unless tem is a positive
	op == 1 test of precision 1 integral op, otherwise handle
	that case as op itself.  Fix up formatting.
	(optimize_range_tests_to_bit_test, optimize_range_tests): Fix
	up formatting.

	* gcc.dg/pr69802.c: New test.

From-SVN: r233446
parent 4cb5f5a3
2016-02-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/69802
* tree-ssa-reassoc.c (update_range_test): If op is
SSA_NAME_IS_DEFAULT_DEF, give up unless tem is a positive
op == 1 test of precision 1 integral op, otherwise handle
that case as op itself. Fix up formatting.
(optimize_range_tests_to_bit_test, optimize_range_tests): Fix
up formatting.
2016-02-16 Richard Biener <rguenther@suse.de> 2016-02-16 Richard Biener <rguenther@suse.de>
PR tree-optimization/69586 PR tree-optimization/69586
......
2016-02-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/69802
* gcc.dg/pr69802.c: New test.
2016-02-16 Richard Biener <rguenther@suse.de> 2016-02-16 Richard Biener <rguenther@suse.de>
PR middle-end/69801 PR middle-end/69801
......
/* PR tree-optimization/69802 */
/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */
struct S { unsigned f : 1; };
int a, d;
int
foo (void)
{
unsigned b = 0;
struct S c;
d = ((1 && b) < c.f) & c.f; /* { dg-warning "is used uninitialized" } */
return a;
}
int
bar (_Bool c)
{
unsigned b = 0;
d = ((1 && b) < c) & c;
return a;
}
...@@ -2046,19 +2046,41 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange, ...@@ -2046,19 +2046,41 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
{ {
operand_entry *oe = (*ops)[range->idx]; operand_entry *oe = (*ops)[range->idx];
tree op = oe->op; tree op = oe->op;
gimple *stmt = op ? SSA_NAME_DEF_STMT (op) : gimple *stmt = op ? SSA_NAME_DEF_STMT (op)
last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)); : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
location_t loc = gimple_location (stmt); location_t loc = gimple_location (stmt);
tree optype = op ? TREE_TYPE (op) : boolean_type_node; tree optype = op ? TREE_TYPE (op) : boolean_type_node;
tree tem = build_range_check (loc, optype, unshare_expr (exp), tree tem = build_range_check (loc, optype, unshare_expr (exp),
in_p, low, high); in_p, low, high);
enum warn_strict_overflow_code wc = WARN_STRICT_OVERFLOW_COMPARISON; enum warn_strict_overflow_code wc = WARN_STRICT_OVERFLOW_COMPARISON;
gimple_stmt_iterator gsi; gimple_stmt_iterator gsi;
unsigned int i; unsigned int i, uid;
if (tem == NULL_TREE) if (tem == NULL_TREE)
return false; return false;
/* If op is default def SSA_NAME, there is no place to insert the
new comparison. Give up, unless we can use OP itself as the
range test. */
if (op && SSA_NAME_IS_DEFAULT_DEF (op))
{
if (op == range->exp
&& ((TYPE_PRECISION (optype) == 1 && TYPE_UNSIGNED (optype))
|| TREE_CODE (optype) == BOOLEAN_TYPE)
&& (op == tem
|| (TREE_CODE (tem) == EQ_EXPR
&& TREE_OPERAND (tem, 0) == op
&& integer_onep (TREE_OPERAND (tem, 1))))
&& opcode != BIT_IOR_EXPR
&& (opcode != ERROR_MARK || oe->rank != BIT_IOR_EXPR))
{
stmt = NULL;
tem = op;
}
else
return false;
}
if (strict_overflow_p && issue_strict_overflow_warning (wc)) if (strict_overflow_p && issue_strict_overflow_warning (wc))
warning_at (loc, OPT_Wstrict_overflow, warning_at (loc, OPT_Wstrict_overflow,
"assuming signed overflow does not occur " "assuming signed overflow does not occur "
...@@ -2096,12 +2118,22 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange, ...@@ -2096,12 +2118,22 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
tem = invert_truthvalue_loc (loc, tem); tem = invert_truthvalue_loc (loc, tem);
tem = fold_convert_loc (loc, optype, tem); tem = fold_convert_loc (loc, optype, tem);
gsi = gsi_for_stmt (stmt); if (stmt)
unsigned int uid = gimple_uid (stmt); {
gsi = gsi_for_stmt (stmt);
uid = gimple_uid (stmt);
}
else
{
gsi = gsi_none ();
uid = 0;
}
if (stmt == NULL)
gcc_checking_assert (tem == op);
/* In rare cases range->exp can be equal to lhs of stmt. /* In rare cases range->exp can be equal to lhs of stmt.
In that case we have to insert after the stmt rather then before In that case we have to insert after the stmt rather then before
it. If stmt is a PHI, insert it at the start of the basic block. */ it. If stmt is a PHI, insert it at the start of the basic block. */
if (op != range->exp) else if (op != range->exp)
{ {
gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT);
tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, true, tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, true,
...@@ -2489,7 +2521,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length, ...@@ -2489,7 +2521,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
operand_entry *oe = (*ops)[ranges[i].idx]; operand_entry *oe = (*ops)[ranges[i].idx];
tree op = oe->op; tree op = oe->op;
gimple *stmt = op ? SSA_NAME_DEF_STMT (op) gimple *stmt = op ? SSA_NAME_DEF_STMT (op)
: last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)); : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
location_t loc = gimple_location (stmt); location_t loc = gimple_location (stmt);
tree optype = op ? TREE_TYPE (op) : boolean_type_node; tree optype = op ? TREE_TYPE (op) : boolean_type_node;
...@@ -2553,7 +2585,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length, ...@@ -2553,7 +2585,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
gcc_assert (TREE_CODE (exp) == SSA_NAME); gcc_assert (TREE_CODE (exp) == SSA_NAME);
gimple_set_visited (SSA_NAME_DEF_STMT (exp), true); gimple_set_visited (SSA_NAME_DEF_STMT (exp), true);
gimple *g = gimple_build_assign (make_ssa_name (optype), gimple *g = gimple_build_assign (make_ssa_name (optype),
BIT_IOR_EXPR, tem, exp); BIT_IOR_EXPR, tem, exp);
gimple_set_location (g, loc); gimple_set_location (g, loc);
gimple_seq_add_stmt_without_update (&seq, g); gimple_seq_add_stmt_without_update (&seq, g);
exp = gimple_assign_lhs (g); exp = gimple_assign_lhs (g);
...@@ -2599,8 +2631,9 @@ optimize_range_tests (enum tree_code opcode, ...@@ -2599,8 +2631,9 @@ optimize_range_tests (enum tree_code opcode,
oe = (*ops)[i]; oe = (*ops)[i];
ranges[i].idx = i; ranges[i].idx = i;
init_range_entry (ranges + i, oe->op, init_range_entry (ranges + i, oe->op,
oe->op ? NULL : oe->op
last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id))); ? NULL
: last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)));
/* For | invert it now, we will invert it again before emitting /* For | invert it now, we will invert it again before emitting
the optimized expression. */ the optimized expression. */
if (opcode == BIT_IOR_EXPR if (opcode == BIT_IOR_EXPR
......
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