https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110852
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jan Hubicka from comment #9) > By removing the logic we lose ability to optimize things like > a = b * c; > where b is predicted to value 0 and c has no useful prediction on it. No, that is what my unposted WIP patch did, but predict-18.c test catched that. > > @@ -2631,6 +2623,9 @@ expr_expected_value_1 (tree type, tree o > > > > if (predictor2 < *predictor) > > *predictor = predictor2; > > + if (*predictor != PRED_BUILTIN_EXPECT > > + && *predictor != PRED_BUILTIN_EXPECT_WITH_PROBABILITY) > > + *probability = -1; > > This still can "upgrade" prediction to a predictor of lower enm value > but higher probability that is not conservative thing to do. > > > > return res; > > } > I ended up with the folloing patch that also takes care of various cases > of phi merging and downgrading the predictor to new > PRED_COMBINED_VALUE_PREDICTION which can, like PRED_BUILTIN_EXPECT hold > custom probability but it is not trued as FIRST_MATCH. > What do you think? > + int p1 = get_predictor_value (*predictor, *probability); > + int p2 = get_predictor_value (predictor2, probability2); > + /* If both predictors agrees, it does not matter from which s/agrees/agree/ > + Consequently failing to fold both means that we will not suceed > determinging s/suceed/succeed/;s/determinging/determining/ Otherwise yes, but I think the code could be still simplified the way I had in my patch (i.e. drop parts of the r14-2219 changes, and simply assume that failed recursion for one operand is PRED_UNCONDITIONAL instead of returning early, and not requiring the operands are INTEGER_CSTs, just that the result of the binop folds to INTEGER_CST.