From: Vladislav Ivanishin Date: Tue, 21 May 2019 10:39:05 +0000 (+0000) Subject: tree-ssa-uninit: suppress more spurious warnings X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0f8e84c609c67456965b20e1274e7dca3db9ab05;p=gcc.git tree-ssa-uninit: suppress more spurious warnings * tree-ssa-uninit.c (value_sat_pred_p): This new function is a wrapper around is_value_included_in that knows how to handle BIT_AND_EXPR. (is_pred_expr_subset_of): Use the new function. Handle more cases where code1 == EQ_EXPR and where code1 == BIT_AND_EXPR and thus fix some false positives. testsuite/ * gcc.dg/uninit-28-gimple.c: New test. * gcc.dg/uninit-29-gimple.c: New test. * gcc.dg/uninit-30-gimple.c: New test. * gcc.dg/uninit-31-gimple.c: New test. From-SVN: r271460 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 17b4b10aa82..d341a64440c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-05-21 Vladislav Ivanishin + + * tree-ssa-uninit.c (value_sat_pred_p): This new function is a wrapper + around is_value_included_in that knows how to handle BIT_AND_EXPR. + (is_pred_expr_subset_of): Use the new function. Handle more cases where + code1 == EQ_EXPR and where code1 == BIT_AND_EXPR and thus fix some false + positives. + 2019-05-21 Martin Liska * config/rs6000/driver-rs6000.c (elf_platform): Do not use diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f65b6f427b6..f2bff8a0b42 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-05-21 Vladislav Ivanishin + + * gcc.dg/uninit-28-gimple.c: New test. + * gcc.dg/uninit-29-gimple.c: New test. + * gcc.dg/uninit-30-gimple.c: New test. + * gcc.dg/uninit-31-gimple.c: New test. + 2019-05-21 Martin Liska * gcc.dg/pr90263.c: Add -O2. diff --git a/gcc/testsuite/gcc.dg/uninit-28-gimple.c b/gcc/testsuite/gcc.dg/uninit-28-gimple.c new file mode 100644 index 00000000000..0648b8a4aa7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-28-gimple.c @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + /* Uninit warning here would be bogus, because (16 & 3) == 0 and therefore + if v == 16, the uninit value is not used (the use is properly guarded). */ + unsigned int undef; /* { dg-bogus "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned pred; + + __BB(2): + if (v_4(D) != 16u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v != 16' predicate) */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + pred = v_4(D) & 3u; + if (pred != 0u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v & 3' predicate). */ + __BB(5): + _9 = undef_1; + 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-29-gimple.c b/gcc/testsuite/gcc.dg/uninit-29-gimple.c new file mode 100644 index 00000000000..cb5bc97164e --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-29-gimple.c @@ -0,0 +1,45 @@ +/* { 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; + unsigned pred; + + __BB(2): + pred = v_4(D) & 3u; + if (pred != 0u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v & 3' predicate) */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + if (v_4(D) != 16u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v != 16' predicate). */ + __BB(5): + _9 = undef_1; + 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-30-gimple.c b/gcc/testsuite/gcc.dg/uninit-30-gimple.c new file mode 100644 index 00000000000..8c91f79d509 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-30-gimple.c @@ -0,0 +1,43 @@ +/* { 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; + + /* 'undef' is defined conditionally (under 'v < 100' predicate). */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + if (v_4(D) == 42u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v == 42' predicate). */ + __BB(5): + _9 = undef_1; + 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-31-gimple.c b/gcc/testsuite/gcc.dg/uninit-31-gimple.c new file mode 100644 index 00000000000..01118ef9823 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-31-gimple.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + /* If v == 2, then undef is used w/o being initialized. */ + unsigned int undef; /* { dg-warning "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned int pred2; + unsigned int pred1; + + __BB(2): + pred2 = v_4(D) & 5u; + if (pred2 != 0u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v & 5' predicate). */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + pred1 = v_4(D) & 3u; + if (pred1 != 0u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v & 3' predicate). */ + __BB(5): + _9 = undef_1; + 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 b89da4017e8..bc07afe32c8 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -1045,6 +1045,26 @@ is_value_included_in (tree val, tree boundary, enum tree_code cmpc) return result; } +/* Returns whether VAL satisfies (x CMPC BOUNDARY) predicate. CMPC can be + either one of the range comparison codes ({GE,LT,EQ,NE}_EXPR and the like), + or BIT_AND_EXPR. EXACT_P is only meaningful for the latter. It modifies the + question from whether VAL & BOUNDARY != 0 to whether VAL & BOUNDARY == VAL. + For other values of CMPC, EXACT_P is ignored. */ + +static bool +value_sat_pred_p (tree val, tree boundary, enum tree_code cmpc, + bool exact_p = false) +{ + if (cmpc != BIT_AND_EXPR) + return is_value_included_in (val, boundary, cmpc); + + wi::tree_to_wide_ref andw = wi::to_wide (val) & wi::to_wide (boundary); + if (exact_p) + return andw == wi::to_wide (val); + else + return andw.to_uhwi (); +} + /* Returns true if PRED is common among all the predicate chains (PREDS) (and therefore can be factored out). NUM_PRED_CHAIN is the size of array PREDS. */ @@ -1471,18 +1491,15 @@ is_pred_expr_subset_of (pred_info expr1, pred_info expr2) if (code2 == NE_EXPR && code1 == NE_EXPR) return false; - if (code2 == NE_EXPR && code1 != BIT_AND_EXPR) - return !is_value_included_in (expr2.pred_rhs, expr1.pred_rhs, code1); + if (code2 == NE_EXPR) + return !value_sat_pred_p (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 == EQ_EXPR) + return value_sat_pred_p (expr1.pred_rhs, expr2.pred_rhs, code2); - if (code1 != code2) - return false; - - if (is_value_included_in (expr1.pred_rhs, expr2.pred_rhs, code2)) - return true; + if (code1 == code2) + return value_sat_pred_p (expr1.pred_rhs, expr2.pred_rhs, code2, + code1 == BIT_AND_EXPR); return false; }