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

--- Comment #10 from Feng Xue <fxue at os dot amperecomputing.com> ---
(In reply to Martin Jambor from comment #8)
> I am about to thest the following patch.  In longer-run, it would be better
> to never generate lattice values outside of the value_range but there is an
> ordering problem, we need the complete VR info before we can use it.  I plan
> to rearrange IPA-CP into making multiple passes over the lattice dependency
> graph and this should quite naturally be solved by doing this kind of
> resursive-value-generation only in second and later passes. 
> 
> 
> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> index 453e9c93cc3..cbbb8bbc80a 100644
> --- a/gcc/ipa-cp.cc
> +++ b/gcc/ipa-cp.cc
> @@ -6154,8 +6154,16 @@ decide_whether_version_node (struct cgraph_node *node)
>         {
>           ipcp_value<tree> *val;
>           for (val = lat->values; val; val = val->next)
> -           ret |= decide_about_value (node, i, -1, val, &avals,
> -                                      &self_gen_clones);
> +           {
> +             if (!plats->m_value_range.bottom_p ()
> +                 && !plats->m_value_range.m_vr.contains_p (val->value))
> +               {
> +                 gcc_checking_assert (val->self_recursion_generated_p ());
> +                 continue;
> +               }
> +             ret |= decide_about_value (node, i, -1, val, &avals,
> +                                        &self_gen_clones);
> +           }
>         }
>  
>        if (!plats->aggs_bottom)

Here is a complication that value range for recursion index might not be not
easily computed, and could not prevent IPA-CP generating useless copy.
Constraint of recursion index comes from "block2[level][x]", not its value
range deduced from condition predicate (level > 0). Change the case to cover up
value range of "level", and we will get same warning. So in the circumstances,
one way for us is to disable warning for these copies?

extern int block2[7][256];

extern unsigned G_START;
extern unsigned G_SCALE;

static int encode_block(int block2[7][256], unsigned level)
{
    int best_score = 0;

    for (unsigned x = G_START; x < G_SCALE * level; x++) {
        int v = block2[1][x];
        block2[level][x] = 0;
        best_score      += v * v;
    }

    if (G_SCALE * level > G_START && best_score > 64) {
        int score = 0;

        score += encode_block(block2, level - 1);
        score += encode_block(block2, level - 1);

        if (score < best_score) {
            best_score = score;
        }
    }

    return best_score;
}

Reply via email to