aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-predicate-analysis.h
AgeCommit message (Collapse)AuthorFilesLines
2023-01-02Update copyright years.Jakub Jelinek1-1/+1
2022-12-01tree-optimization/107937 - uninit predicate simplification fixupRichard Biener1-3/+20
The following changes the predicate representation to record the value of a predicate with an empty set of AND predicates. That's necessary to properly represent the conservative fallback for the def vs use predicates. Since simplification now can result in such an empty set this distinction becomes important and we need to check for this as we otherwise ICE. PR tree-optimization/107937 * gimple-predicate-analysis.h (predicate::is_true): New. (predicate::is_false): Likewise. (predicate::empty_val): Likewise. (uninit_analysis::uninit_analysis): Properly initialize def_preds. * gimple-predicate-analysis.cc (simplify_1b): Indicate whether the chain became empty. (predicate::simplify): Release emptied chain before removing it. (predicate::normalize): Replace temporary object with assertion. (uninit_analysis::is_use_guarded): Deal with predicates that simplify to true/false. * gcc.dg/pr107937.c: New testcase.
2022-09-05debug () for predicatesRichard Biener1-1/+3
The following adds a debug () member to the predicate class. * gimple-predicate-analysis.h (predicate::debug): New. (predicate::dump): Add FILE * argument, add base overload. * gimple-predicate-analysis.cc (debug): New. (dump_pred_info): Add FILE * argument. (dump_pred_chain): Likewise. (predicate::dump): Split out preamble into overload. Add FILE * argument. (predicate::debug): New. (predicate::simplify): Adjust. (predicate::normalize): Likewise. (predicate::init_from_control_deps): Likewise.
2022-08-31tree-optimization/65244 - include asserts in predicates for uninitRichard Biener1-1/+1
When uninit computes the actual predicates from the control dependence edges it currently skips those that are assert-like (where one edge leads to a block which ends in a noreturn call). That leads to bogus uninit diagnostics when applied on the USE side. PR tree-optimization/65244 * gimple-predicate-analysis.h (predicate::init_from_control_deps): Add argument to specify whether the predicate is for the USE. * gimple-predicate-analysis.cc (predicate::init_from_control_deps): Also include predicates effective fallthru control edges when the predicate is for the USE. * gcc.dg/uninit-pr65244-2.c: New testcase.
2022-08-30Make uninit PHI processing more consistentRichard Biener1-2/+0
Currently the main working of the maybe-uninit pass is to scan over all PHIs with possibly undefined arguments, diagnosing whether there's a direct not guarded use. For not guarded uses in PHIs those are queued for later processing and to make the uninit analysis PHI def handling work, mark the PHI def as possibly uninitialized. But this happens only for those PHI uses that happen to be seen before a direct not guarded use and whether all arguments of a PHI node which are defined by a PHI are properly marked as maybe uninitialized depends on the processing order. The following changes the uninit pass to perform an RPO walk over the function, ensuring that PHI argument defs are visited before the PHI node (besides backedge uses which we ignore already), getting rid of the worklist. It also makes sure to process all PHI uses, but recording those that are properly guarded so they are not treated as maybe undefined when processing the PHI use later. Overall this should make behavior more consistent, avoid some false negative because of the previous early out and order issue, and avoid some false positive because of the missed recording of guarded PHI uses. The patch correctly diagnoses an uninitalized use of 'regnum' in store_bit_field_1 and also diagnoses an uninitialized use of best_match::m_best_candidate_len in c-decl.cc which I've chosen to silence by initializing m_best_candidate_len. The warning is a false positive but GCC cannot see that m_best_candidate_len is initialized when m_best_candidate is not NULL so from this perspective this was a false negative. I've added g++.dg/uninit-pred-5.C with a reduced testcase that nicely shows how the previous behavior missed the diagnostic because the worklist ended up visiting the PHI with the dependend uninit value before visiting the PHIs producing it. * gimple-predicate-analysis.h (uninit_analysis::operator()): Remove. * gimple-predicate-analysis.cc (uninit_analysis::collect_phi_def_edges): Use phi_arg_set, simplify a bit. * tree-ssa-uninit.cc (defined_args): New global. (compute_uninit_opnds_pos): Mask with the recorded set of guarded maybe-uninitialized uses. (uninit_undef_val_t::operator()): Remove. (find_uninit_use): Process all PHI uses, recording the guarded ones and marking the PHI result as uninitialized consistently. (warn_uninitialized_phi): Adjust. (execute_late_warn_uninitialized): Get rid of the PHI worklist and instead walk the function in RPO order. * spellcheck.h (best_match::m_best_candidate_len): Initialize. * g++.dg/uninit-pred-5.C: New testcase.
2022-08-26Remove uninit_analysis::use_cannot_happenRichard Biener1-1/+0
As written earlier uninit_analysis::use_cannot_happen is duplicate functionality implemented in a complement way, not adhering to the idea of disproving a may-uninit use and eventually (I have not yet found a testcase it helps to avoid false positives) avoiding false positives because of this or different ways it imposes limits on the predicate computations. This patch removes it. * gimple-predicate-analysis.h (uninit_analysis::use_cannot_happen): Remove. * gimple-predicate-analysis.cc (can_be_invalidated_p): Remove. (uninit_analysis::use_cannot_happen): Likewise. (uninit_analysis::is_use_guarded): Do not call use_cannot_happen. (dump_predicates): Remove. (simple_control_dep_chain): Remove edge overload.
2022-08-24Split uninit analysis from predicate analysisRichard Biener1-42/+59
This splits the API collected in gimple-predicate-analysis.h into what I'd call a predicate and assorted functionality plus utility used by the uninit pass that happens to use that. I've tried to be minimalistic with refactoring, there's still recursive instantiation of uninit_analysis, the new class encapsulating a series of uninit analysis queries from the uninit pass. But it at least should make the predicate part actually reusable and what predicate is dealt with is a little bit more clear in the uninit_analysis part. I will followup with moving the predicate implementation bits together in the gimple-predicate-analysis.cc file. * gimple-predicate-analysis.h (predicate): Split out non-predicate related functionality into .. (uninit_analysis): .. this new class. * gimple-predicate-analysis.cc: Refactor into two classes. * tree-ssa-uninit.cc (find_uninit_use): Use uninit_analysis.
2022-08-23tree-optimization/106722 - uninit analysis with long def -> use pathRichard Biener1-4/+0
The following applies similar measures as r13-2133-ge66cf626c72d58 to the computation of the use predicate when the path from PHI def to use is too long and we run into compute_control_dep_chain limits. It also moves the preprocessor define limits internal. This resolves the reduced testcase but not the original one. PR tree-optimization/106722 * gimple-predicate-analysis.h (MAX_NUM_CHAINS, MAX_CHAIN_LEN, MAX_POSTDOM_CHECK, MAX_SWITCH_CASES): Move ... * gimple-predicate-analysis.cc: ... here and document. (simple_control_dep_chain): New function, factored from predicate::use_cannot_happen. (predicate::use_cannot_happen): Adjust. (predicate::predicate): Use simple_control_dep_chain as fallback. * g++.dg/uninit-pr106722-1.C: New testcase.
2022-08-22Remove dead predicate analysis GENERIC expr building codeRichard Biener1-14/+2
The following removes the unused def_expr, use_expr and expr APIs from the predicate class including the unconditional build of the GENERIC use_expr on each uninit analysis run. * gimple-predicate-analysis.h (predicate::m_use_expr): Remove. (predicate::def_expr): Likewise. (predicate::use_expr): Likewise. (predicate::expr): Likewise. * gimple-predicate-analysis.cc (predicate::def_expr): Remove. (predicate::use_expr): Likewise. (predicate::expr): Likewise. (predicate::is_use_guarded): Do not build m_use_expr.
2022-01-03Update copyright years.Jakub Jelinek1-1/+1
2021-09-17Factor predidacte analysis out of tree-ssa-uninit.c into its own module.Martin Sebor1-0/+158
gcc/ChangeLog: * Makefile.in (OBJS): Add gimple-predicate-analysis.o. * tree-ssa-uninit.c (max_phi_args): Move to gimple-predicate-analysis. (MASK_SET_BIT, MASK_TEST_BIT, MASK_EMPTY): Same. (check_defs): Add comment. (can_skip_redundant_opnd): Update comment. (compute_uninit_opnds_pos): Adjust to namespace change. (find_pdom): Move to gimple-predicate-analysis.cc. (find_dom): Same. (struct uninit_undef_val_t): New. (is_non_loop_exit_postdominating): Move to gimple-predicate-analysis.cc. (find_control_equiv_block): Same. (MAX_NUM_CHAINS, MAX_CHAIN_LEN, MAX_POSTDOM_CHECK): Same. (MAX_SWITCH_CASES): Same. (compute_control_dep_chain): Same. (find_uninit_use): Use predicate analyzer. (struct pred_info): Move to gimple-predicate-analysis. (convert_control_dep_chain_into_preds): Same. (find_predicates): Same. (collect_phi_def_edges): Same. (warn_uninitialized_phi): Use predicate analyzer. (find_def_preds): Move to gimple-predicate-analysis. (dump_pred_info): Same. (dump_pred_chain): Same. (dump_predicates): Same. (destroy_predicate_vecs): Remove. (execute_late_warn_uninitialized): New. (get_cmp_code): Move to gimple-predicate-analysis. (is_value_included_in): Same. (value_sat_pred_p): Same. (find_matching_predicate_in_rest_chains): Same. (is_use_properly_guarded): Same. (prune_uninit_phi_opnds): Same. (find_var_cmp_const): Same. (use_pred_not_overlap_with_undef_path_pred): Same. (pred_equal_p): Same. (is_neq_relop_p): Same. (is_neq_zero_form_p): Same. (pred_expr_equal_p): Same. (is_pred_expr_subset_of): Same. (is_pred_chain_subset_of): Same. (is_included_in): Same. (is_superset_of): Same. (pred_neg_p): Same. (simplify_pred): Same. (simplify_preds_2): Same. (simplify_preds_3): Same. (simplify_preds_4): Same. (simplify_preds): Same. (push_pred): Same. (push_to_worklist): Same. (get_pred_info_from_cmp): Same. (is_degenerated_phi): Same. (normalize_one_pred_1): Same. (normalize_one_pred): Same. (normalize_one_pred_chain): Same. (normalize_preds): Same. (can_one_predicate_be_invalidated_p): Same. (can_chain_union_be_invalidated_p): Same. (uninit_uses_cannot_happen): Same. (pass_late_warn_uninitialized::execute): Define. * gimple-predicate-analysis.cc: New file. * gimple-predicate-analysis.h: New file.