return whether ``lhs -> rhs`` can be proved
| 13 | |
| 14 | //! return whether ``lhs -> rhs`` can be proved |
| 15 | bool can_prove_imply(cg::ExecutionMask* lhs, cg::ExecutionMask* rhs) { |
| 16 | // this function is neither sound nor complete (and it can never be due |
| 17 | // to the NP-completeness of SAT); here we only handle the most common |
| 18 | // cases |
| 19 | |
| 20 | if (rhs == lhs->parent()) { |
| 21 | // nested cond exec oprs |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | using Mode = CondExecPredLogical::Mode; |
| 26 | auto is_pred_logical = [](cg::OperatorNodeBase* opr, Mode mode) { |
| 27 | auto as_p = opr->try_cast_final<CondExecPredLogical>(); |
| 28 | return as_p && as_p->param().mode == mode; |
| 29 | }; |
| 30 | |
| 31 | auto opr = rhs->owner()->owner_opr(); |
| 32 | |
| 33 | if (is_pred_logical(opr, Mode::AND) && opr->input().size() == 1) { |
| 34 | // cross-cn copy of predicate |
| 35 | opr = opr->input(0)->owner_opr(); |
| 36 | } |
| 37 | |
| 38 | if (is_pred_logical(opr, Mode::OR)) { |
| 39 | // in the grad of SUM_COND_OUT CondExecMerge |
| 40 | auto lvar = lhs->owner(); |
| 41 | for (auto i : opr->input()) { |
| 42 | if (lvar == i) { |
| 43 | return true; |
| 44 | } |
| 45 | } |
| 46 | return false; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | VarNode* proxy_var_from_mask(cg::ExecutionMask* mask) { |
| 52 | auto var = mask->owner(); |