From: Vladislav Ivanishin Date: Mon, 29 Apr 2019 19:47:17 +0000 (+0000) Subject: tree-ssa-uninit.c (is_pred_expr_subset_of): Correctly handle cases where cond2 is... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5c1b3334a2f59492f57e32c2ddab06d22941a3f3;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d6adeda090d..8bb8dcfee1e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-04-29 Vladislav Ivanishin + + * 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 PR tree-optimization/90278 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4089febb09c..d64281548b4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-04-29 Vladislav Ivanishin + + * 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 PR tree-optimization/90278 diff --git a/gcc/testsuite/gcc.dg/uninit-25-gimple.c b/gcc/testsuite/gcc.dg/uninit-25-gimple.c new file mode 100644 index 00000000000..0c0acd6b83e --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-25-gimple.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/uninit-25.c b/gcc/testsuite/gcc.dg/uninit-25.c new file mode 100644 index 00000000000..ffffce3f91c --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-25.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/uninit-26.c b/gcc/testsuite/gcc.dg/uninit-26.c new file mode 100644 index 00000000000..60ac48cdc50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-26.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/uninit-27-gimple.c b/gcc/testsuite/gcc.dg/uninit-27-gimple.c new file mode 100644 index 00000000000..f75469d8ef8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-27-gimple.c @@ -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; +} diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 55a55a05c96..831587854c6 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -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))