https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47661

--- Comment #4 from Drea Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Drea Pinski from comment #3)
> I have an idea on fixing this.
> 
> tree_predict_by_opcode:
> ```
>   op0 = gimple_cond_lhs (stmt);
>   op1 = gimple_cond_rhs (stmt);
>   cmp = gimple_cond_code (stmt);
>   type = TREE_TYPE (op0);
>   val = expr_expected_value_1 (boolean_type_node, op0, cmp, op1,
>                                &predictor, &probability);
>   if (val && TREE_CODE (val) == INTEGER_CST)
>     {
>       HOST_WIDE_INT prob = get_predictor_value (predictor, probability);
>       if (integer_zerop (val))
>         prob = REG_BR_PROB_BASE - prob;
>       predict_edge (then_edge, predictor, prob);
>     }
> ...
> 
>         /* Comparisons with 0 are often used for booleans and there is
>            nothing useful to predict about them.  */
>         else if (integer_zerop (op0) || integer_zerop (op1))
>           ;
> 
> 
> ```
> 
> Does not look back for boolean types.
> For single use booleans, it makes sense to look back to its definition I
> think.

So looking into older patches I Noticed this one:
https://inbox.sourceware.org/gcc-patches/[email protected]/

This had gimple_pred_extract_comparison which didn't exactly do the same but
forced a similar idea here. Note COND_EXPR part of that patch no longer applies
due to r13-707-g68e0063397ba82 but the GIMPLE_COND part kinda of applies when
it comes to `-ftrapping-math -fnon-call-exceptions`. That is because with
non-call exceptions some fp comparisons won't be part of GIMPLE_COND.
Especially when it comes to throwing externally.

Reply via email to