Skip to content

[LV] missed optimization with pragma assume_safety #99734

@vfdff

Description

@vfdff
  • I defined 2 function Map_Center_Of_Mass_CPU and foo_noalias, we can see the only different is that the function foo_noalias has extra restrict for the argument int * crd. According Control-auto-vectorization-with-pragmas, the #pragma clang loop vectorize(assume_safety) can assume there is no data dependencies for the following loop, so I expected they have similar output assemble , and now only the function foo_noalias can vectorize succcessfully.

The preceding pragma indicates to the compiler that the following loop contains no data dependencies between loop iterations that would prevent vectorization. The compiler might be able to use this information to vectorize a loop, where it would not typically be possible

void Map_Center_Of_Mass_CPU(int residue_i, int *start,  int *end, int * crd)
{
    #pragma clang loop vectorize(assume_safety)
    for (int atom_i = start[residue_i]; atom_i < end[residue_i]; atom_i++)
    {
        crd[atom_i] = crd[atom_i] + 8;
    }
}


void foo_noalias (int residue_i, int *start,  int *end, int * __restrict__ crd)
{
    #pragma clang loop vectorize(assume_safety)
    for (int atom_i = start[residue_i]; atom_i < end[residue_i]; atom_i++)
    {
        crd[atom_i] = crd[atom_i] + 8;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions