tree-ssa-uninit.c (is_pred_expr_subset_of): Correctly handle cases where cond2 is NE_EXPR.

* tree-ssa-uninit.c (is_pred_expr_subset_of): Correctly handle cases
	where cond2 is NE_EXPR.
	(is_value_included_in): Update comment.

        * gcc.dg/uninit-25-gimple.c: New test.
        * gcc.dg/uninit-25.c: New test.
        * gcc.dg/uninit-26.c: New test.
        * gcc.dg/uninit-27-gimple.c: New test.

From-SVN: r270660
This commit is contained in:
Vladislav Ivanishin 2019-04-29 19:47:17 +00:00 committed by Jeff Law
parent 95c33590c8
commit 5c1b3334a2
7 changed files with 149 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2019-04-29 Vladislav Ivanishin <vlad@ispras.ru>
* tree-ssa-uninit.c (is_pred_expr_subset_of): Correctly handle cases
where cond2 is NE_EXPR.
(is_value_included_in): Update comment.
2019-04-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/90278

View File

@ -1,3 +1,10 @@
2019-04-29 Vladislav Ivanishin <vlad@ispras.ru>
* gcc.dg/uninit-25-gimple.c: New test.
* gcc.dg/uninit-25.c: New test.
* gcc.dg/uninit-26.c: New test.
* gcc.dg/uninit-27-gimple.c: New test.
2019-04-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/90278

View File

@ -0,0 +1,41 @@
/* { dg-do compile } */
/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */
unsigned int __GIMPLE (ssa,startwith("uninit1"))
foo (unsigned int v)
{
unsigned int undef; /* { dg-warning "may be used uninitialized" } */
unsigned int _2;
unsigned int _9;
unsigned int _10;
__BB(2):
if (v_4(D) != 1u)
goto __BB3;
else
goto __BB4;
__BB(3):
undef_8 = 8u; // 'undef' is defined conditionally (under 'v != 1' predicate)
goto __BB4;
__BB(4):
// An undef value flows into a phi.
undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8);
if (v_4(D) != 2u) // This condition is neither a superset nor a subset of 'v != 1'.
goto __BB5;
else
goto __BB6;
__BB(5):
_9 = undef_1; // The phi value is used here (under 'v != 2' predicate).
goto __BB7;
__BB(6):
_10 = v_4(D);
goto __BB7;
__BB(7):
_2 = __PHI (__BB5: _9, __BB6: _10);
return _2;
}

View File

@ -0,0 +1,23 @@
/* { dg-do compile } */
/* { dg-options "-O -Wmaybe-uninitialized" } */
extern unsigned bar (void);
extern void quux (void);
unsigned foo (unsigned v)
{
unsigned u;
if (v != 1)
u = bar ();
// Prevent the "dom" pass from changing the CFG layout based on the inference
// 'if (v != 1) is false then (v != 2) is true'. (Now it would have to
// duplicate the loop in order to do so, which is deemed expensive.)
for (int i = 0; i < 10; i++)
quux ();
if (v != 2)
return u; /* { dg-warning "may be used uninitialized" } */
return 0;
}

View File

@ -0,0 +1,23 @@
/* { dg-do compile } */
/* { dg-options "-O -Wmaybe-uninitialized" } */
extern unsigned bar (void);
extern void quux (void);
unsigned foo (unsigned v)
{
unsigned u;
if (v != 100)
u = bar ();
// Prevent the "dom" pass from changing the CFG layout based on the inference
// 'if (v != 100) is false then (v < 105) is true'. (Now it would have to
// duplicate the loop in order to do so, which is deemed expensive.)
for (int i = 0; i < 10; i++)
quux ();
if (v < 105) /* v == 100 falls into this range. */
return u; /* { dg-warning "may be used uninitialized" } */
return 0;
}

View File

@ -0,0 +1,41 @@
/* { dg-do compile } */
/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */
unsigned int __GIMPLE (ssa,startwith("uninit1"))
foo (unsigned int v)
{
unsigned int undef; /* { dg-bogus "may be used uninitialized" } */
unsigned int _2;
unsigned int _9;
unsigned int _10;
__BB(2):
if (v_4(D) != 100u)
goto __BB3;
else
goto __BB4;
__BB(3):
undef_8 = 8u; // 'undef' is defined conditionally (under 'v != 100' predicate)
goto __BB4;
__BB(4):
// An undef value flows into a phi.
undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8);
if (v_4(D) < 100u)
goto __BB5;
else
goto __BB6;
__BB(5):
_9 = undef_1; // The phi value is used here (under 'v < 100' predicate).
goto __BB7;
__BB(6):
_10 = v_4(D);
goto __BB7;
__BB(7):
_2 = __PHI (__BB5: _9, __BB6: _10);
return _2;
}

View File

@ -1011,8 +1011,7 @@ get_cmp_code (enum tree_code orig_cmp_code, bool swap_cond, bool invert)
return tc;
}
/* Returns true if VAL falls in the range defined by BOUNDARY and CMPC, i.e.
all values in the range satisfies (x CMPC BOUNDARY) == true. */
/* Returns whether VAL CMPC BOUNDARY is true. */
static bool
is_value_included_in (tree val, tree boundary, enum tree_code cmpc)
@ -1488,11 +1487,17 @@ is_pred_expr_subset_of (pred_info expr1, pred_info expr2)
if (expr2.invert)
code2 = invert_tree_comparison (code2, false);
if (code2 == NE_EXPR && code1 == NE_EXPR)
return false;
if (code2 == NE_EXPR)
return !is_value_included_in (expr2.pred_rhs, expr1.pred_rhs, code1);
if ((code1 == EQ_EXPR || code1 == BIT_AND_EXPR) && code2 == BIT_AND_EXPR)
return (wi::to_wide (expr1.pred_rhs)
== (wi::to_wide (expr1.pred_rhs) & wi::to_wide (expr2.pred_rhs)));
if (code1 != code2 && code2 != NE_EXPR)
if (code1 != code2)
return false;
if (is_value_included_in (expr1.pred_rhs, expr2.pred_rhs, code2))