Moving pass_lower_switch after the late jump threading changed the
control flow seen by the uninitialized warning pass, exposing two
false positives (PR107919 and PR44547). Both stem from the same
defect in uninit_analysis::is_use_guarded.
is_use_guarded treats an empty use predicate (the PHI is defined and
used in the same block) as an unguarded use because init_use_preds
returns false when the predicate is empty. That is wrong: whether
such a use is guarded depends solely on the definition predicate, so
fall through and compute it.
An empty (TRUE) use predicate is then matched by m_phi_def_preds being
TRUE, i.e. the value is defined on every path. Two spots made this
mismatch on a TRUE use predicate:
- predicate::simplify_2 folded a tautological disjunction to TRUE by
clearing m_preds but forgot to set m_cval, so a definition
predicate that simplified to TRUE was misread as FALSE ("never
defined"). Set m_cval as well.
- the fallback path only recognized an implied guard when the
relaxed definition predicate was a superset of the use predicate,
which is vacuous for a TRUE use predicate; simplify and normalize
the relaxed predicate and check relaxed.is_true () instead.
gcc/ChangeLog:
* gimple-predicate-analysis.cc (predicate::simplify_2): Set
m_cval when a disjunction simplifies to true.
(uninit_analysis::is_use_guarded): Do not return early for an
empty use predicate; skip the overlap pruning and use an
is_true-based superset test for an unconditional use; simplify
and normalize the relaxed definition predicate in the fallback
and test it with is_true for an unconditional use.
---
gcc/gimple-predicate-analysis.cc | 36 ++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index 6ecb1bc0387..37ced7e2663 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -1402,6 +1402,8 @@ predicate::simplify_2 ()
for (unsigned k = 0; k < m_preds.length (); ++k)
m_preds[k].release ();
m_preds.truncate (0);
+ /* The whole disjunction has simplified to true. */
+ m_cval = true;
}
break;
}
@@ -2257,18 +2259,22 @@ uninit_analysis::is_use_guarded (gimple *use_stmt,
basic_block use_bb,
into its use. This will be empty if the PHI is defined and used
in the same bb. */
predicate use_preds (true);
- if (!init_use_preds (use_preds, def_bb, use_bb))
- return false;
+ init_use_preds (use_preds, def_bb, use_bb);
+ /* init_use_preds() returns false for an empty (unconditional) use
+ predicate. That does not make the use unguarded: whether it is
+ guarded then depends solely on the definition predicate, which is
+ computed below. */
use_preds.simplify (use_stmt, /*is_use=*/true);
use_preds.normalize (use_stmt, /*is_use=*/true);
if (use_preds.is_false ())
return true;
- if (use_preds.is_true ())
- return false;
- /* Try to prune the dead incoming phi edges. */
- if (!overlap (phi, opnds, visited, use_preds))
+ /* Try to prune the dead incoming phi edges. This requires a non-trivial
+ use predicate; an unconditional use (USE_PREDS is TRUE) has nothing to
+ check against. */
+ if (!use_preds.is_true ()
+ && !overlap (phi, opnds, visited, use_preds))
{
if (DEBUG_PREDICATE_ANALYZER && dump_file)
fputs ("found predicate overlap\n", dump_file);
@@ -2292,8 +2298,11 @@ uninit_analysis::is_use_guarded (gimple *use_stmt,
basic_block use_bb,
/* Return true if the predicate guarding the valid definition (i.e.,
*THIS) is a superset of the predicate guarding the use (i.e.,
- USE_PREDS). */
- if (m_phi_def_preds.superset_of (use_preds))
+ USE_PREDS). An unconditional use (USE_PREDS is TRUE) is guarded only
+ if the value is defined on every path, i.e. the definition predicate
+ is TRUE; superset_of() is vacuous for a TRUE use predicate. */
+ if (use_preds.is_true () ? m_phi_def_preds.is_true ()
+ : m_phi_def_preds.superset_of (use_preds))
return true;
/* The superset test fails when a guard that distinguishes the defined from
@@ -2329,9 +2338,14 @@ uninit_analysis::is_use_guarded (gimple *use_stmt,
basic_block use_bb,
if (!edge_conds.is_empty ())
{
predicate relaxed (m_phi_def_preds);
- if (relaxed.drop_conjuncts_implied_by (edge_conds)
- && relaxed.superset_of (use_preds))
- return true;
+ if (relaxed.drop_conjuncts_implied_by (edge_conds))
+ {
+ relaxed.simplify (phi);
+ relaxed.normalize (phi);
+ if (use_preds.is_true () ? relaxed.is_true ()
+ : relaxed.superset_of (use_preds))
+ return true;
+ }
}
return false;
--
2.34.1