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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The compile time evaluation of a loop to determine final values when scev can't
do it is also mentioned in PR87465.

Perhaps we can have some valueization where we keep current values of SSA_NAMEs
(dunno if it should use SCCVN stuff or just a SSA_NAME -> invariant mapping),
and then just start from loop preheader edge, valueize non-virtual PHIs, then
for each non-debug statement gimple_fold_stmt_to_constant and store that to the
valueization data structure if it succeeds, otherwise punt.  Have some param
for upper limit on how many statements we want to evaluate at most, probably
need some special code to deal with GIMPLE_CONDs, GIMPLE_SWITCH etc.
Maybe extend it at some point so that it can handle also some non-invariants
(like say having the result be some base SSA_NAME + invariant or some similar
exceptions).  Guess it could help also with some vectorized loops we don't
completely unroll, I think we have some PRs where vectorization disabled final
value computation, if we'd without unrolling managed to constant evaluate the
outcome of the loop, they'd be fixed too.

Reply via email to