+2019-05-21 Vladislav Ivanishin <vlad@ispras.ru>
+
+ * 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 <mliska@suse.cz>
* config/rs6000/driver-rs6000.c (elf_platform): Do not use
+2019-05-21 Vladislav Ivanishin <vlad@ispras.ru>
+
+ * 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 <mliska@suse.cz>
* gcc.dg/pr90263.c: Add -O2.
--- /dev/null
+/* { 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;
+}
--- /dev/null
+/* { 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;
+}
--- /dev/null
+/* { 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;
+}
--- /dev/null
+/* { 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;
+}
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. */
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;
}